[cfe-dev] -emit-ast doesn't work with static analyzer

Devin Coughlin via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 28 09:38:27 PST 2015

Hi Jack,

> On Dec 20, 2015, at 8:31 PM, via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> Recently I need to generate AST files while using clang static analyzer. I found that the option "-emit-ast" could not work with static analyzer. I used the command like this: clang -emit-ast --analyze -Xanalyzer -analyzer-checker=core.DivideZero a.c. Then I got a warning: argument unused during compilation: '-emit-ast'. I can only compile the source code once for some reason, so I have to generate ast file and use static analyzer at the same time. How can I manage that?
I don’t believe there is a good way to do this. The driver will only perform a single job action for the ‘compile' phase and in this case --analyze takes precedence over -emit-ast.

If you really can only call ‘clang’ once with your build process, one hacky possibility (depending on your build system) is to replace the environmental variables $CC and $CPP with a script that that calls the real clang twice, once with --analyze and once with -emit-ast, forwarding all other arguments. We do this with ‘scan-build’, which interposes with this trick to run the static analyzer while also compiling the program. You can see how this is done in tools/scan-build.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151228/bf02d906/attachment.html>

More information about the cfe-dev mailing list