Skip to content

Commit

Permalink
Merge pull request Ericsson#2062 from bruntib/clang_skip
Browse files Browse the repository at this point in the history
The skipped flags are skipped in case of Clang too
  • Loading branch information
gyorb authored Apr 11, 2019
2 parents 95075bb + b91d688 commit 197579e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
9 changes: 9 additions & 0 deletions analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@
re.compile('-filelist'): 1
}

# These flag groups are ignored together.
# TODO: This list is not used yet, but will be applied in the next release.
IGNORED_FLAG_LISTS = [
['-Xclang', '-mllvm'],
['-Xclang', '-emit-llvm'],
['-Xclang', '-instcombine-lower-dbg-declare=0']
]

COMPILE_OPTIONS = [
'-nostdinc',
r'-nostdinc\+\+',
Expand Down Expand Up @@ -765,6 +773,7 @@ def parse_options(compilation_db_entry, compiler_info_file=None):

if 'clang' in details['compiler']:
flag_transformers = [
__skip,
__determine_action_type,
__get_language,
__get_output,
Expand Down
32 changes: 23 additions & 9 deletions analyzer/tests/unit/test_option_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ def test_ignore_flags_gcc(self):
"""
ignore = ["-Werror", "-fsyntax-only",
"-mfloat-gprs=double", "-mfloat-gprs=yes",
"-mabi=spe", "-mabi=eabi",
'-Xclang', '-mllvm',
'-Xclang', '-instcombine-lower-dbg-declare=0']
"-mabi=spe", "-mabi=eabi"]
action = {
'file': 'main.cpp',
'command': "g++ {} main.cpp".format(' '.join(ignore)),
Expand All @@ -260,10 +258,9 @@ def test_ignore_flags_gcc(self):

def test_ignore_flags_clang(self):
"""
Test if Clang compiler preserves the compiler flags except for the
preprocessor related flags.
Clang has some further flags which should be omitted.
"""
ignore = ["-Werror", "-E", "-M", "-fsyntax-only",
ignore = ["-Werror", "-fsyntax-only",
"-mfloat-gprs=double", "-mfloat-gprs=yes",
"-mabi=spe", "-mabi=eabi",
'-Xclang', '-mllvm',
Expand All @@ -273,9 +270,26 @@ def test_ignore_flags_clang(self):
'command': "clang++ {} main.cpp".format(' '.join(ignore)),
'directory': ''}
res = log_parser.parse_options(action)
ignore.remove("-E")
ignore.remove("-M")
self.assertEqual(res.analyzer_options, ignore)
self.assertEqual(res.analyzer_options, ["-fsyntax-only"])

@unittest.skip("This will be enabled when we distinguish -Xclang params.")
def test_ignore_xclang_groups(self):
"""
In case a flag has a parameter, we'd like to skip only the ones with a
specific parameter. Currently Clang compiler has such parameters after
-Xclang flag.
"""
ignore = ["-Werror", "-fsyntax-only",
'-Xclang', '-mllvm',
'-Xclang', '-instcombine-lower-dbg-declare=0',
'-Xclang', '-something']
action = {
'file': 'main.cpp',
'command': "clang++ {} main.cpp".format(' '.join(ignore)),
'directory': ''}
res = log_parser.parse_options(action)
self.assertEqual(res.analyzer_options,
["-fsyntax-only", "-Xclang", "-something"])

def test_preserve_flags(self):
"""
Expand Down

0 comments on commit 197579e

Please sign in to comment.