I'd like to teach clang how to preprocess sources so static analyzer would behave in the same way as if run on raw input sources.
clang help ... --analyze Run the static analyzer ... -E Only run the preprocessor
Driver currently ignores --analyze option in presence of -E but I am not sure if that's based on conscious decision or if it's just an implementation detail (getFinalPhase sets the last compilation phase as Preprocess in presence of -E). @dergachev.a could you please confirm?
clang --analyze -E ~/tmp/trivial.cpp clang: warning: argument unused during compilation: '--analyze' [-Wunused-command-line-argument]
The only relevant effect of running analyzer that I found is that in Frontend __clang_analyzer__ macro is set (see BOOKMARK below).
@dergachev.a Do you know about any other things I should take care of?
I generally see two possible solutions:
- We generate superset of options for both actions in Driver (probably by calling RenderAnalyzerOptions in Clang::ConstructJob) and deal with that in Frontend.
- We generate such options in Driver that setup Frontend as necessary. (This seemed way easier implementation-wise so I explored it first.)
@arphaman @dergachev.a WDYT?
It's the first time in my life i hear about --analyze-auto. We should probably remove it completely.