Skip to content

Commit

Permalink
Merge pull request #3417 from bruntib/no_clangsa_from_tidy
Browse files Browse the repository at this point in the history
[analyzer] Don't run ClangSA checkers from clang-tidy
  • Loading branch information
bruntib authored Sep 2, 2021
2 parents 5aec531 + a7cab42 commit e0c741f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
19 changes: 14 additions & 5 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,29 @@ 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 = []

# -checks=-clang-analyzer-* option is added to the analyzer command by
# default except when all analyzer config options come from .clang-tidy
# file. The content of this file overrides every other custom config.
if config.analyzer_config.get('take-config-from-directory') == 'true':
return checkers, compiler_warnings

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 +175,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.config_handler.analyzer_config = \
{'take-config-from-directory': 'true'}

for arg in analyzer.construct_analyzer_cmd(result_handler):
self.assertFalse(arg.startswith('-checks'))

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 e0c741f

Please sign in to comment.