Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] Don't run ClangSA checkers from clang-tidy #3417

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
bruntib marked this conversation as resolved.
Show resolved Hide resolved
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