Skip to content

Commit

Permalink
[analyzer] Don't run ClangSA checkers from clang-tidy
Browse files Browse the repository at this point in the history
`clang-tidy` can invoke some ClangSA checkers. We are disabling this
behavior by default, because ClangSA checkers should run through ClangSA
itself. We missed this disable if analyzer config options were given to
clang-tidy. If ClangSA has some bug then it would effect clang-tidy
analysis too. That's the real reason why we force disabling.
  • Loading branch information
bruntib committed Sep 2, 2021
1 parent 0a57b98 commit 245658f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
16 changes: 11 additions & 5 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def get_checker_list(self, config) -> Tuple[List[str], List[str]]:
If the file specified by the '--tidy-config' option contains a 'Checks'
key or the 'Checks' option is specified through the '--analyzer-config'
the return value will be a tuple of empty lists which means do not turn
checkers explicitly.
checkers explicitly. "clang-analyzer-*" is an exception, because we
want to disable these even if analyzer config is given. If we wouldn't
disable this group then some ClangSA checkers would be invoked by
clang-tidy and in some cases that would cause analysis error due to
some ClangSA bug.
"""
checkers = []
compiler_warnings = []
Expand All @@ -147,6 +151,11 @@ def get_checker_list(self, config) -> Tuple[List[str], List[str]]:
has_checker_config = \
config.checker_config and config.checker_config != '{}'

# Do not disable any clang-tidy checks explicitly, but don't run
# ClangSA checkers. ClangSA checkers are driven by an other
# analyzer in CodeChecker.
checkers.append('-clang-analyzer-*')

if has_checker_config:
try:
# Is is possible that the value of config.checker_config
Expand All @@ -163,13 +172,10 @@ def get_checker_list(self, config) -> Tuple[List[str], List[str]]:
LOG.debug("Invalid checker configuration: %s. Error: %s",
config.checker_config, ex)

# Do not disable any clang-tidy checks explicitly, but don't run
# ClangSA checkers. ClangSA checkers are driven by an other
# analyzer in CodeChecker.
# For clang compiler warnings a correspoding
# clang-diagnostic error is generated by Clang tidy.
# They can be disabled by this glob -clang-diagnostic-*
checkers = ['-clang-analyzer-*', 'clang-diagnostic-*']
checkers.append('clang-diagnostic-*')

# Config handler stores which checkers are enabled or disabled.
for checker_name, value in config.checks().items():
Expand Down
25 changes: 25 additions & 0 deletions analyzer/tests/unit/test_checker_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,31 @@ def setUpClass(cls):
cls.checks_list = checks.split(',')
print('Checks list: %s' % cls.checks_list)

def test_disable_clangsa_checkers(self):
"""
Test that checker config still disables clang-analyzer-*.
"""
analyzer = create_analyzer_tidy()
result_handler = create_result_handler(analyzer)

for arg in analyzer.construct_analyzer_cmd(result_handler):
if arg.startswith('-checks='):
self.assertIn('-clang-analyzer-*', arg)

analyzer.config_handler.checker_config = \
'{"Checks": "hicpp-use-nullptr"}'

for arg in analyzer.construct_analyzer_cmd(result_handler):
if arg.startswith('-checks='):
self.assertIn('-clang-analyzer-*', arg)

analyzer.config_handler.checker_config = '{}'
analyzer.analyzer_config = {'take-config-from-directory': 'true'}

for arg in analyzer.construct_analyzer_cmd(result_handler):
if arg.startswith('-checks='):
self.assertIn('-clang-analyzer-*', arg)

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 245658f

Please sign in to comment.