Skip to content

Commit efec112

Browse files
committed
feat(analyzer): make analyze-headers configurable
1 parent 6797a01 commit efec112

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ def construct_analyzer_cmd(self, result_handler):
510510
'-analyzer-output=' + analyzer_mode,
511511
'-o', analyzer_output_file])
512512

513+
if config.analyze_headers:
514+
analyzer_cmd.extend(['-Xclang',
515+
'-analyzer-opt-analyze-headers'])
516+
513517
# Expand macros in plist output on the bug path.
514518
analyzer_cmd.extend(['-Xclang',
515519
'-analyzer-config',
@@ -753,6 +757,9 @@ def construct_config_handler(cls, args):
753757
'add_gcc_include_dirs_with_isystem' in args and \
754758
args.add_gcc_include_dirs_with_isystem
755759

760+
handler.analyze_headers = 'analyze_headers' in args and \
761+
args.analyze_headers
762+
756763
if 'ctu_phases' in args:
757764
handler.ctu_dir = os.path.join(args.output_path,
758765
args.ctu_dir)

analyzer/codechecker_analyzer/analyzers/config_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self):
5454
self.analyzer_config = None
5555
self.report_hash = None
5656
self.enable_all = None
57+
self.analyze_headers = None
5758

5859
# The key is the checker name, the value is a tuple of CheckerState and
5960
# checker description.

analyzer/codechecker_analyzer/cli/analyze.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ def add_arguments_to_parser(parser):
436436
"cppcheck:cc-verbatim-args-file="
437437
"<filepath>")
438438

439+
analyzer_opts.add_argument('--analyze-headers',
440+
dest="analyze_headers",
441+
required=False,
442+
action='store_true',
443+
default=False,
444+
help="Enable the analysis in the header files "
445+
"in Clang SA.")
446+
439447
analyzer_opts.add_argument('--saargs',
440448
dest="clangsa_args_cfg_file",
441449
required=False,

analyzer/tests/unit/test_analyzer_command.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,19 @@ def test_isystem_idirafter(self):
6767
def test_no_analyze_headers(self):
6868
"""
6969
Test that the -analyzer-opt-analyze-headers flag is NOT present in the
70-
analyzer command.
70+
analyzer command by default.
7171
"""
7272
analyzer = create_analyzer_sa()
7373
result_handler = create_result_handler(analyzer)
7474
cmd = analyzer.construct_analyzer_cmd(result_handler)
7575
self.assertNotIn('-analyzer-opt-analyze-headers', cmd)
76+
77+
def test_analyze_headers_on(self):
78+
"""
79+
Test that the -analyzer-opt-analyze-headers flag IS present in the
80+
analyzer command when requested.
81+
"""
82+
analyzer = create_analyzer_sa(['--analyze-headers'])
83+
result_handler = create_result_handler(analyzer)
84+
cmd = analyzer.construct_analyzer_cmd(result_handler)
85+
self.assertIn('-analyzer-opt-analyze-headers', cmd)

0 commit comments

Comments
 (0)