Ericsson / clang

Cross Translation Unit analysis capability for Clang Static Analyzer. (Fork of official clang at http://llvm.org/git/clang)
http://clang.llvm.org/
Other
15 stars 10 forks source link

Add On-the-fly analysis support #694

Open gamesh411 opened 5 years ago

gamesh411 commented 5 years ago

Add an option to enable on-the-fly parsing of needed ASTs during CTU analysis. The option CTUCompilationDatabase should be a path to a compilation database, which has all the necessary information to generate the ASTs. In case an empty string is given, on-the-fly parsing is disabled.

gamesh411 commented 5 years ago

Could you plase check the new test files 'ctu-on-the-fly.c' and 'ctu-on-the-fly.cpp'. I have managed to get almost working, however there are 2 issues still reamining.

First issue: During the analysis of sometimes the file part is entirely left off from the diagnostic. The interesting part is that Line number is OK, just the file part gets lost. This could be fixed by making the check more lenient in case of on-demand analysis (eg. not requiring that the diagnostic contains the file information).

Second issue: Inline assembly importing fails if -std=c89 is given inside compile_commands.json for the c test (see the test RUN: lines for the contents of the compile_commands.json). If however no -std=c89 is given, then unsupported AST node error is given during the analysis (I assume that it must be the clang tool which parses the file).

What are your thoughts?

Thanks

gamesh411 commented 4 years ago

I have a working solution updated. The parsing logic of external TUs should be refactored to increase maintainability. However, this change is complex enough as is, and I would recommend refactoring in a separate change.

There is another ongoing issue with passing configuration options to CTUContext during the CallEvent handling of the analyzer engine. This promotes parameter-style passing of information, however, the Context object would be better off with constructor parameter injection or getters and setters (which is still a bit inferior to constructor injection because the values are set every time an external TU definition is requested from the context).

gamesh411 commented 4 years ago

Fixed a remaining typo.

gamesh411 commented 4 years ago

I have refactored and rebased the solution. There is an extra diagnostic as requested, and I have asserted some invariants in the code.

martong commented 4 years ago

CI still fails...

martong commented 4 years ago

run tests (this message is intended for the build bot, if you answer to this message then you owe me a bottle of whiskey)

martong commented 4 years ago

run tests

gamesh411 commented 4 years ago

run tests