diff --git a/analyzer/codechecker_analyzer/buildlog/log_parser.py b/analyzer/codechecker_analyzer/buildlog/log_parser.py index 63a96255a2..53a7c0e09a 100644 --- a/analyzer/codechecker_analyzer/buildlog/log_parser.py +++ b/analyzer/codechecker_analyzer/buildlog/log_parser.py @@ -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\+\+', @@ -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, diff --git a/analyzer/tests/unit/test_option_parser.py b/analyzer/tests/unit/test_option_parser.py index 19af77e469..8fb417da03 100644 --- a/analyzer/tests/unit/test_option_parser.py +++ b/analyzer/tests/unit/test_option_parser.py @@ -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)), @@ -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', @@ -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): """