feat: add strict/permissive compiler warning profiles#527
Conversation
e879777 to
e05eb47
Compare
There was a problem hiding this comment.
You should also add the features to the S-CORE gcc toolchain
e05eb47 to
ce81645
Compare
|
This much warring turn into error when we implement the warring as a error feature in current code base: #539 |
93129c1 to
cb0811e
Compare
| "//quality/compiler_warnings/clang:strict_warnings", | ||
| "//quality/compiler_warnings/clang:third_party_warnings", | ||
| ], | ||
| extra_link_libs = {"": [ |
There was a problem hiding this comment.
These link flags should probably also go into a cc_feature that you reference in the extra_enabled_features here.
| # Clang Thread Safety Analysis. Detects potential data races through | ||
| # annotations (GUARDED_BY, REQUIRES, etc.). Essential for concurrent code. | ||
| # Ref: CERT C++ CON43-CPP — do not allow data races. | ||
| # Clang-specific: not available in GCC. | ||
| # Ref: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html | ||
| "-Wthread-safety", |
There was a problem hiding this comment.
We currently do not use these annotations in our code.
| # Clang Thread Safety Analysis. Detects potential data races through | |
| # annotations (GUARDED_BY, REQUIRES, etc.). Essential for concurrent code. | |
| # Ref: CERT C++ CON43-CPP — do not allow data races. | |
| # Clang-specific: not available in GCC. | |
| # Ref: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html | |
| "-Wthread-safety", |
| # -Wshadow-all sub-categories are NOT subcategories of -Wshadow for | ||
| # -Wno-error purposes. Downgrade these individually so that the global | ||
| # -Werror does not reject them during migration. | ||
| "-Wno-error=shadow-uncaptured-local", | ||
| "-Wno-error=shadow-field", |
There was a problem hiding this comment.
Discussed with @limdor. We decided to enable -Wshadow-all.
| # -Wshadow-all sub-categories are NOT subcategories of -Wshadow for | |
| # -Wno-error purposes. Downgrade these individually so that the global | |
| # -Werror does not reject them during migration. | |
| "-Wno-error=shadow-uncaptured-local", | |
| "-Wno-error=shadow-field", |
| (void)context; | ||
| (void)reserved; |
There was a problem hiding this comment.
Better use the C++ way of doing this, since we also suggest that in proper production code.
| (void)context; | |
| (void)reserved; | |
| std::ignore = context; | |
| std::ignore = reserved; |
There was a problem hiding this comment.
You must split this to one bazel target per flag you test. Otherwise you only test the first flag that causes an error.
| { | ||
| virtual void process(std::int32_t x) | ||
| { | ||
| (void)x; |
| { | ||
| void process(double x) | ||
| { | ||
| (void)x; |
| 9 functions, each triggering exactly one warning category: | ||
|
|
||
| | Function | Warning flag | Feature | MISRA / CWE | | ||
| |----------|-------------|---------|-------------| | ||
| | `implicit_narrowing` | `-Wfloat-conversion` | `score_communication_strict_warnings` | MISRA Rule 7.0.5, CWE-681 | | ||
| | `variable_shadowing` | `-Wshadow` | `score_communication_strict_warnings` | MISRA Rule 6.4.1, CWE-398 | | ||
| | `signed_unsigned_compare` | `-Wsign-compare` | `score_communication_strict_warnings` | CWE-195, CWE-697 | | ||
| | `unused_parameter` | `-Wunused-parameter` | `score_communication_strict_warnings` | MISRA Rule 0.1.1, CWE-561 | | ||
| | `delete_polymorphic` | `-Wdelete-non-virtual-dtor` | `score_communication_strict_warnings` (C++) | MISRA Rule 15.7.1 | | ||
| | `VDerived::process` | `-Woverloaded-virtual` | `score_communication_strict_warnings` (C++) | MISRA Rule 10.2.0 | | ||
| | `cast_away_const` | `-Wcast-qual` | `score_communication_additional_warnings` | MISRA Rule 8.2.3 | | ||
| | `format_nonliteral` | `-Wformat-nonliteral` | `score_communication_additional_warnings` | CWE-134 | | ||
| | `#if UNDEFINED_MACRO` | `-Wundef` | `score_communication_additional_warnings` | MISRA Dir 4.4 | |
There was a problem hiding this comment.
Ideally we have one function per flag. That way we can make sure that actually every flag triggers as expected.
| # Sanitizer configs activate LLVM automatically | ||
| bazel test --config=asan_ubsan_lsan //quality/compiler_warnings/test:fp_build_test | ||
| bazel test --config=tsan //quality/compiler_warnings/test:fp_build_test |
There was a problem hiding this comment.
Misleading in this docu.
| # Sanitizer configs activate LLVM automatically | |
| bazel test --config=asan_ubsan_lsan //quality/compiler_warnings/test:fp_build_test | |
| bazel test --config=tsan //quality/compiler_warnings/test:fp_build_test |
6b98546 to
9ffba9d
Compare
| # Self-contained copies of the warning features under test. The real features | ||
| # live in //quality/compiler_warnings/{clang,gcc}:BUILD; they are duplicated | ||
| # here (Clang flag set) because a nested workspace cannot reference the parent | ||
| # module's targets. |
There was a problem hiding this comment.
Hmm this restriction is awful. Let me think about a better way.
There was a problem hiding this comment.
Done using suggested method https://github.com/yuyawk/rules_build_error
| # Temporarily disabled for sanitizer test runs (ASAN/TSAN). | ||
| # Re-enable after shadow/deprecation warnings are fixed in dependencies. | ||
| # "score_communication_treat_warnings_as_errors", | ||
| # "score_communication_strict_warnings", |
There was a problem hiding this comment.
Better would be to introduce a score_communication_strict_warnings_no_error and degrade the flags that cause errors to warnings. That way we can enable this and slowly work towards improving the situation.
There was a problem hiding this comment.
after score_communication_strict_warnings_no_error enable this much changes only required to merge our PR. #558
| extra_compile_flags = SCORE_GCC_MINIMAL_WARNING_COMPILE_FLAGS, | ||
| extra_cxx_compile_flags = SCORE_GCC_MINIMAL_WARNING_CXX_FLAGS, |
There was a problem hiding this comment.
Is there no support for cc_features?
There was a problem hiding this comment.
Currently not on this path. cc_features are wired for LLVM, but GCC/QCC still require compile flag injection, so these two lines are a temporary compatibility step until upstream feature support is available.
6576505 to
ff9eef0
Compare
Introduce configurable warning features for GCC and Clang toolchains
with two build modes controlled via --config=strict and --config=permissive.
- Add quality/compiler_warnings/{BUILD,clang/BUILD,gcc/BUILD} with
cc_feature definitions for minimal, strict, and additional warnings
- Configure LLVM toolchain with extra_known_features (toolchains_llvm 1.7.0)
- Configure GCC toolchain with extra_cxxflags baseline matching minimal_warnings
- Add selective -Wno-error overrides in .bazelrc for permissive mode
- Refactor score/message_passing BUILD files to use COMPILER_WARNING_FEATURES
- Add FP/TP test targets with build_test verification
- Document usage in quality/quality.md
MISRA C++:2023 Dir 1.1, Rules 6.4.1, 7.0.5, 8.2.3, 0.1.1
CWE-134, CWE-195, CWE-398, CWE-561, CWE-681
ff9eef0 to
af7062c
Compare
Introduce configurable warning features for GCC and Clang toolchains with two build modes controlled via --config=strict and --config=permissive.
MISRA C++:2023 Dir 1.1, Rules 6.4.1, 7.0.5, 8.2.3, 0.1.1 CWE-134, CWE-195, CWE-398, CWE-561, CWE-681