Skip to content

Commit

Permalink
[fix] Bugfix at --enable-all and disable warning
Browse files Browse the repository at this point in the history
There was a bug in CodeChecker:

CodeChecker analyze --enable-all --disable clang-diagnostic-unused-variable

This command didn't disable that warning. The problem is that we
represent --enable-all with -Weverything in the clang-tidy analyzer
command, but -Wno-unused-variable has to be appended too. It was a
false assumption that
"clang-tidy -checks='-clang-diagnostic-unused-variable' main.c -- -Weverything"
does the job.
  • Loading branch information
bruntib committed Nov 14, 2023
1 parent 482804c commit 472822c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def get_checker_list(self, config) -> Tuple[List[str], List[str]]:
if state == CheckerState.enabled:
compiler_warnings.add('-W' + warning_name)
enabled_checkers.add(checker_name)
else:
compiler_warnings.add('-Wno-' + warning_name)

continue

Expand Down Expand Up @@ -490,6 +492,8 @@ def construct_analyzer_cmd(self, result_handler):

if config.enable_all:
analyzer_cmd.append("-Weverything")
analyzer_cmd.extend(
filter(lambda x: x.startswith('-Wno-'), compiler_warnings))
else:
analyzer_cmd.extend(compiler_warnings)

Expand Down
27 changes: 27 additions & 0 deletions analyzer/tests/unit/test_checker_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,33 @@ def test_disable_clangsa_checkers(self):
analyzer.config_handler.checks()['Wreserved-id-macro'][0],
CheckerState.enabled)

def test_enable_all_disable_warning(self):
"""
If --enable-all is used and a warning is disabled, then the proper
parameterization of clang-tidy is using both -Weverything and
-Wno-<warning> in this order.
Side note: we use -Weverything instead of listing all enabled warnings
to represent --enable-all.
"""
args = Namespace()
args.ordered_checkers = [('clang-diagnostic-unused-variable', False)]
args.enable_all = True

analyzer = create_analyzer_tidy(args)
result_handler = create_result_handler(analyzer)

analyzer_cmd = analyzer.construct_analyzer_cmd(result_handler)

try:
pos_everything = analyzer_cmd.index('-Weverything')
pos_disable = analyzer_cmd.index('-Wno-unused-variable')
self.assertLess(pos_everything, pos_disable)
except ValueError:
self.assertTrue(
False,
"-Weverything and -Wno-unused-variable should be in the "
"analysis command.")

def test_default_checkers_are_not_disabled(self):
"""
Test that the default checks are not disabled in Clang Tidy.
Expand Down

0 comments on commit 472822c

Please sign in to comment.