Skip to content

feat: add strict/permissive compiler warning profiles#527

Draft
AAmbuj wants to merge 1 commit into
eclipse-score:mainfrom
AAmbuj:amsh_feat_compiler_warning_features
Draft

feat: add strict/permissive compiler warning profiles#527
AAmbuj wants to merge 1 commit into
eclipse-score:mainfrom
AAmbuj:amsh_feat_compiler_warning_features

Conversation

@AAmbuj

@AAmbuj AAmbuj commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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

@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch 5 times, most recently from e879777 to e05eb47 Compare June 12, 2026 06:41
Comment thread score/mw/common_features.bzl
Comment thread score/message_passing/BUILD
Comment thread .bazelrc Outdated
Comment thread MODULE.bazel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add the features to the S-CORE gcc toolchain

Comment thread quality/compiler_warnings/clang/BUILD Outdated
Comment thread quality/compiler_warnings/clang/BUILD Outdated
Comment thread quality/compiler_warnings/test/BUILD Outdated
Comment thread quality/compiler_warnings/test/BUILD
Comment thread MODULE.bazel
@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch from e05eb47 to ce81645 Compare June 13, 2026 10:09
@AAmbuj

AAmbuj commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

This much warring turn into error when we implement the warring as a error feature in current code base: #539

@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch 2 times, most recently from 93129c1 to cb0811e Compare June 15, 2026 09:20
@AAmbuj AAmbuj self-assigned this Jun 16, 2026
Comment thread score/mw/common_features.bzl
Comment thread MODULE.bazel Outdated
"//quality/compiler_warnings/clang:strict_warnings",
"//quality/compiler_warnings/clang:third_party_warnings",
],
extra_link_libs = {"": [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These link flags should probably also go into a cc_feature that you reference in the extra_enabled_features here.

Comment thread quality/compiler_warnings/clang/BUILD
Comment thread quality/compiler_warnings/clang/BUILD
Comment thread quality/compiler_warnings/clang/BUILD Outdated
Comment on lines +47 to +52
# 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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do not use these annotations in our code.

Suggested change
# 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",

Comment thread quality/compiler_warnings/clang/BUILD Outdated
Comment on lines +109 to +113
# -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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @limdor. We decided to enable -Wshadow-all.

Suggested change
# -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",

Comment on lines +54 to +55
(void)context;
(void)reserved;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use the C++ way of doing this, since we also suggest that in proper production code.

Suggested change
(void)context;
(void)reserved;
std::ignore = context;
std::ignore = reserved;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

{
void process(double x)
{
(void)x;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Comment on lines +51 to +63
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 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we have one function per flag. That way we can make sure that actually every flag triggers as expected.

Comment on lines +42 to +44
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading in this docu.

Suggested change
# 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

@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch 4 times, most recently from 6b98546 to 9ffba9d Compare June 17, 2026 12:44
Comment on lines +17 to +20
# 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.

@LittleHuba LittleHuba Jun 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this restriction is awful. Let me think about a better way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done using suggested method https://github.com/yuyawk/rules_build_error

Comment thread score/mw/common_features.bzl Outdated
Comment on lines +14 to +17
# 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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after score_communication_strict_warnings_no_error enable this much changes only required to merge our PR. #558

Comment thread MODULE.bazel
Comment on lines +118 to +119
extra_compile_flags = SCORE_GCC_MINIMAL_WARNING_COMPILE_FLAGS,
extra_cxx_compile_flags = SCORE_GCC_MINIMAL_WARNING_CXX_FLAGS,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no support for cc_features?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch 2 times, most recently from 6576505 to ff9eef0 Compare June 18, 2026 05:44
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
@AAmbuj AAmbuj force-pushed the amsh_feat_compiler_warning_features branch from ff9eef0 to af7062c Compare June 18, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants