Skip to content

Commit

Permalink
[analyzer] Fix crash when an assembler command is analyzed
Browse files Browse the repository at this point in the history
If an assember command is analyzed then the recognized language remains
None which can't be provided after -x flag in a subprocess.Popen call.
So -x is added to the command if the recognized language is not None.

Fixes Ericsson#3670
Fixes Ericsson#3730
  • Loading branch information
bruntib committed May 19, 2023
1 parent 6362ae6 commit 322268a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions analyzer/codechecker_analyzer/buildlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,11 @@ def parse_options(compilation_db_entry,
gcc_toolchain.toolchain_in_args(details['analyzer_options'])

# Store the compiler built in include paths and defines.
# If clang compiler is used for compilation and analysis,
# do not collect the implicit include paths.
if (not toolchain and not using_same_clang_to_compile_and_analyze) or \
(compiler_info_file and os.path.exists(compiler_info_file)):
# If clang compiler is used for compilation and analysis, or language is
# not recognized, do not collect the implicit include paths.
if ((not toolchain and not using_same_clang_to_compile_and_analyze) or
(compiler_info_file and os.path.exists(compiler_info_file))) and \
details['lang']:
ImplicitCompilerInfo.set(details, compiler_info_file)

if not keep_gcc_include_fixed:
Expand Down
15 changes: 15 additions & 0 deletions analyzer/tests/unit/test_option_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ def test_compile_onefile(self):
self.assertTrue('main.cpp' == res.source)
self.assertEqual(BuildAction.COMPILE, res.action_type)

def test_nasm_action(self):
"""
Test if an assembler is logged and analyzed.
"""
action = {
'file': 'main.asm',
'command': "nasm -f elf64 main.asm",
'directory': ''}

res = log_parser.parse_options(action)
print(res)
self.assertIsNone(res.lang)
self.assertEqual(res.source, 'main.asm')
self.assertEqual(res.analyzer_type, -1)

def test_preprocess_onefile(self):
"""
Test the preprocess command of one file.
Expand Down

0 comments on commit 322268a

Please sign in to comment.