Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with -pedantic, fix problems #3892

Merged
merged 9 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ add_cxx_compiler_option ("-Wextra")
add_cxx_compiler_option ("-Wno-overloaded-virtual")
add_cxx_compiler_option ("-Wno-deprecated")
add_cxx_compiler_option ("-Wno-deprecated-declarations")
# Make compiler follow the standard and not be too lenient. The increases
# likelyhood that compilation will not break with other compilers (mainly clang)
# or in future versions of GCC.
add_cxx_compiler_option ("-pedantic")

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# The ##__VA_ARGS__ GNU extension is needed for IR. But clang compains about it.
# FIXME: with C++20 we would be able to use standard __VA_OPT__
add_cxx_compiler_option ("-Wno-gnu-zero-variadic-macro-arguments")
endif()

if (ENABLE_SANITIZERS)
append("-fsanitize=undefined,address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ class BMV2Options : public CompilerOptions {

using BMV2Context = P4CContextWithOptions<BMV2Options>;

}; // namespace BMV2
} // namespace BMV2

#endif /* BACKENDS_BMV2_COMMON_OPTIONS_H_ */
2 changes: 1 addition & 1 deletion backends/bmv2/psa_switch/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class PsaSwitchOptions : public BMV2Options {

using PsaSwitchContext = P4CContextWithOptions<PsaSwitchOptions>;

}; // namespace BMV2
} // namespace BMV2

#endif /* BACKENDS_BMV2_PSA_SWITCH_OPTIONS_H_ */
2 changes: 1 addition & 1 deletion backends/bmv2/simple_switch/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class SimpleSwitchOptions : public BMV2Options {

using SimpleSwitchContext = P4CContextWithOptions<SimpleSwitchOptions>;

}; // namespace BMV2
} // namespace BMV2

#endif /* BACKENDS_BMV2_SIMPLE_SWITCH_OPTIONS_H_ */
2 changes: 1 addition & 1 deletion backends/dpdk/dpdkArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1420,5 +1420,5 @@ struct DpdkHandleIPSec : public PassManager {
}
};

}; // namespace DPDK
} // namespace DPDK
#endif /* BACKENDS_DPDK_DPDKARCH_H_ */
2 changes: 1 addition & 1 deletion backends/dpdk/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ const char *DpdkOptions::getIncludePath() {
return path.c_str();
}

}; // namespace DPDK
} // namespace DPDK
7 changes: 3 additions & 4 deletions backends/ebpf/psa/ebpfPsaTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,9 @@ EBPFTablePSA::EntriesGroupedByMask_t EBPFTablePSA::getConstEntriesGroupedByMask(
unsigned priority = entries->entries.size() + 1;
for (auto entry : entries->entries) {
cstring mask = maskGenerator.getMaskStr(entry);
ConstTernaryEntryDesc desc = {
.entry = entry,
.priority = priority--,
};
ConstTernaryEntryDesc desc;
desc.entry = entry;
desc.priority = priority--;
entriesGroupedByMask[mask].emplace_back(desc);
}

Expand Down
2 changes: 1 addition & 1 deletion backends/p4tools/common/compiler/reachability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void ReachabilityEngineState::setState(std::list<const DCGVertexType *> ls) { st

const DCGVertexType *ReachabilityEngineState::getPrevNode() { return prevNode; }

void ReachabilityEngineState::setPrevNode(const DCGVertexType *n) { prevNode = n; };
void ReachabilityEngineState::setPrevNode(const DCGVertexType *n) { prevNode = n; }

bool ReachabilityEngineState::isEmpty() { return state.empty(); }

Expand Down
11 changes: 3 additions & 8 deletions control-plane/typeSpecConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ bool hasTranslationAnnotation(const IR::Type *type, TranslationAnnotation *paylo
// See p4rtControllerType in p4parser.ypp for an explanation of how the
// second argument is encoded.
if (second_arg->to<IR::StringLiteral>() != nullptr) {
payload->controller_type = ControllerType{
.type = ControllerType::kString,
.width = 0,
};
payload->controller_type = ControllerType{ControllerType::kString, 0};
return true;
} else if (second_arg->to<IR::Constant>() != nullptr) {
payload->controller_type = ControllerType{
.type = ControllerType::kBit,
.width = second_arg->to<IR::Constant>()->asInt(),
};
payload->controller_type =
ControllerType{ControllerType::kBit, second_arg->to<IR::Constant>()->asInt()};
return true;
}
BUG("%1%: expected second argument to @p4runtime_translation to parse as an"
Expand Down
1 change: 1 addition & 0 deletions frontends/parsers/p4/p4lexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using Parser = P4::P4Parser;
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wtautological-undefined-compare"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wnull-conversion"
#pragma clang diagnostic ignored "-Wregister"
Expand Down
1 change: 1 addition & 0 deletions frontends/parsers/v1/v1lexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using Parser = V1::V1Parser;
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wtautological-undefined-compare"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wnull-conversion"
#pragma clang diagnostic ignored "-Wregister"
Expand Down
7 changes: 4 additions & 3 deletions lib/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ limitations under the License.
namespace Util {

// colors to pretty print messages
constexpr char ANSI_RED[] = "\e[31m";
constexpr char ANSI_BLUE[] = "\e[34m";
constexpr char ANSI_CLR[] = "\e[0m";
// \e is non-standard escape sequence, use codepoint \33 instead
constexpr char ANSI_RED[] = "\33[31m";
constexpr char ANSI_BLUE[] = "\33[34m";
constexpr char ANSI_CLR[] = "\33[0m";

/// Checks if stderr is redirected to a file
/// Check is done only once and then saved to a static variable
Expand Down