Skip to content

Commit 2534527

Browse files
committed
feat(analyzer): make analyze-headers configurable
1 parent efa4f61 commit 2534527

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,13 @@ def construct_analyzer_cmd(self, result_handler):
507507

508508
analyzer_mode = 'plist-multi-file'
509509
analyzer_cmd.extend(['-Xclang',
510-
'-analyzer-opt-analyze-headers',
511-
'-Xclang',
512510
'-analyzer-output=' + analyzer_mode,
513511
'-o', analyzer_output_file])
514512

513+
if config.analyze_headers:
514+
analyzer_cmd.extend(['-Xclang',
515+
'-analyzer-opt-analyze-headers'])
516+
515517
# Expand macros in plist output on the bug path.
516518
analyzer_cmd.extend(['-Xclang',
517519
'-analyzer-config',
@@ -755,6 +757,9 @@ def construct_config_handler(cls, args):
755757
'add_gcc_include_dirs_with_isystem' in args and \
756758
args.add_gcc_include_dirs_with_isystem
757759

760+
handler.analyze_headers = 'analyze_headers' in args and \
761+
args.analyze_headers
762+
758763
if 'ctu_phases' in args:
759764
handler.ctu_dir = os.path.join(args.output_path,
760765
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,23 @@ def test_isystem_idirafter(self):
6363
result_handler = create_result_handler(analyzer)
6464
cmd = analyzer.construct_analyzer_cmd(result_handler)
6565
self.assertIn('-idirafter', cmd)
66+
67+
def test_no_analyze_headers(self):
68+
"""
69+
Test that the -analyzer-opt-analyze-headers flag is NOT present in the
70+
analyzer command by default.
71+
"""
72+
analyzer = create_analyzer_sa()
73+
result_handler = create_result_handler(analyzer)
74+
cmd = analyzer.construct_analyzer_cmd(result_handler)
75+
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)