Skip to content

Commit

Permalink
Merge pull request #2569 from gyorb/release-v6.11.1-intrin-filter
Browse files Browse the repository at this point in the history
filter out include directories containing *intrin.h header files
  • Loading branch information
bruntib authored Feb 12, 2020
2 parents beb7a0e + a29e26b commit 9bb0047
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
41 changes: 41 additions & 0 deletions analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@
'-iwithprefixbefore'
]

INCLUDE_OPTIONS_MERGED = [
'-iquote',
'-[IF]',
'-isystem',
'-iprefix',
'-iwithprefix',
'-iwithprefixbefore'
]

XCLANG_FLAGS_TO_SKIP = ['-module-file-info',
'-S',
'-emit-llvm',
Expand All @@ -229,6 +238,10 @@
COMPILE_OPTIONS_MERGED = \
re.compile('(' + '|'.join(COMPILE_OPTIONS_MERGED) + ')')

INCLUDE_OPTIONS_MERGED = \
re.compile('(' + '|'.join(INCLUDE_OPTIONS_MERGED) + ')')


PRECOMPILATION_OPTION = re.compile('-(E|M[G|T|Q|F|J|P|V|M]*)$')

# Match for all of the compiler flags.
Expand Down Expand Up @@ -1048,6 +1061,34 @@ def parse_options(compilation_db_entry,
details['compiler_includes'][lang] = \
filter(__contains_no_intrinsic_headers, includes)

# filter out intrin directories
aop_without_intrin = []
analyzer_options = iter(details['analyzer_options'])

for aopt in analyzer_options:
m = INCLUDE_OPTIONS_MERGED.match(aopt)
if m:
flag = m.group(0)
together = len(flag) != len(aopt)

if together:
value = aopt[len(flag):]
else:
flag = aopt
value = analyzer_options.next()
if os.path.isdir(value) and __contains_no_intrinsic_headers(
value) or not os.path.isdir(value):
if together:
aop_without_intrin.append(aopt)
else:
aop_without_intrin.append(flag)
aop_without_intrin.append(value)
else:
# no match
aop_without_intrin.append(aopt)

details['analyzer_options'] = aop_without_intrin

return BuildAction(**details)


Expand Down
25 changes: 25 additions & 0 deletions analyzer/tests/unit/test_option_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,31 @@ def test_compiler_gcc_implicit_includes(self):
self.assertTrue(any(map(lambda x: x.endswith('include-fixed'),
res.compiler_includes['c++'])))

def test_compiler_intrin_headers(self):
""" Include directories with *intrin.h files should be skipped."""

action = {
'file': 'main.cpp',
'directory': '',
'command': 'g++ main.cpp'
}
with tempfile.NamedTemporaryFile(suffix="test-intrin.h") as tmpintrin:
intrin_dir = os.path.dirname(tmpintrin.name)
include_dirs = ["-I", intrin_dir, "-I" + intrin_dir,
"-isystem", intrin_dir, "-isystem" + intrin_dir,
"-I/usr/include"]
action['command'] = "g++ " + ' '.join(include_dirs)

print(action)

res = log_parser.parse_options(action, keep_gcc_intrin=False)

self.assertEquals(len(res.analyzer_options), 1)
self.assertIn("-I/usr/include", res.analyzer_options)

res = log_parser.parse_options(action, keep_gcc_intrin=True)
self.assertEquals(include_dirs, res.analyzer_options)

@unittest.skipIf(platform.system() == 'Darwin',
"If gcc or g++ is a symlink to clang this test should be "
"skipped. Option filtering is different for the two "
Expand Down

0 comments on commit 9bb0047

Please sign in to comment.