Skip to content

Commit

Permalink
[feat] Hide disabled ClangSA checkers in post-processing
Browse files Browse the repository at this point in the history
Sometimes ClangSA checkers rely on each other. Core checkers are
building the underlying model which other checkers are using too. For
this reason disabled checker are never actually disabled in ClangSA, but
are hidden in a post-processing step.
  • Loading branch information
bruntib committed Jul 10, 2023
1 parent bb271ff commit a132699
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

import os
import plistlib
import re
import shlex
import subprocess
Expand Down Expand Up @@ -106,6 +107,7 @@ def __init__(self, cfg_handler, buildaction):
super(ClangSA, self).__init__(cfg_handler, buildaction)
self.__disable_ctu = False
self.__checker_configs = []
self.__disabled_checkers = []

@classmethod
def analyzer_binary(cls):
Expand Down Expand Up @@ -288,6 +290,25 @@ def get_analyzer_config(cls) -> List[str]:

return parse_clang_help_page(command, 'OPTIONS:')

def post_analyze(self, result_handler):
"""
Disabled checkers are not actually disabled during analysis, because
they rely on each other under the hood. The disabled checkers' reports
are removed in this post-processing step.
"""
if not os.path.isfile(result_handler.analyzer_result_file):
return

with open(result_handler.analyzer_result_file, 'rb') as f:
plist = plistlib.load(f)

plist['diagnostics'] = list(filter(
lambda diag: diag['check_name'] not in self.__disabled_checkers,
plist.get('diagnostics', [])))

with open(result_handler.analyzer_result_file, 'wb') as f:
plistlib.dump(plist, f)

def construct_analyzer_cmd(self, result_handler):
"""
Called by the analyzer method.
Expand Down Expand Up @@ -339,23 +360,19 @@ def construct_analyzer_cmd(self, result_handler):
['-Xclang', '-analyzer-config', '-Xclang', cfg])

# Config handler stores which checkers are enabled or disabled.
disabled_checkers = []
self.__disabled_checkers = []
enabled_checkers = []
for checker_name, value in config.checks().items():
state, _ = value
if state == CheckerState.enabled:
enabled_checkers.append(checker_name)
elif state == CheckerState.disabled:
disabled_checkers.append(checker_name)
self.__disabled_checkers.append(checker_name)

if enabled_checkers:
analyzer_cmd.extend(['-Xclang',
'-analyzer-checker=' +
','.join(enabled_checkers)])
if disabled_checkers:
analyzer_cmd.extend(['-Xclang',
'-analyzer-disable-checker=' +
','.join(disabled_checkers)])
# Enable aggressive-binary-operation-simplification option.
version_info = ClangSA.version_info()
if version_info and version_info.major_version >= 8:
Expand Down

0 comments on commit a132699

Please sign in to comment.