[cfe-dev] DIRS missing scan-build in build/tools/clang/tools/Makefile?

Anna Zaks ganna at apple.com
Mon Nov 26 15:11:14 PST 2012

CCing the list as other people might add suggestions.

scan-build works by interposing on a build (by setting CC and CCC to a fake compiler, called ccc-analyzer.). If everything works correctly, the build system then uses ccc-analyzer for compiling C and C++ files.  When ccc-analyzer gets invoked, it first invokes the real compiler and then invokes clang for static analysis. scan-build currently only works with make and xcodebuild. (See: http://clang-analyzer.llvm.org/scan-build.html)

On Nov 26, 2012, at 2:19 PM, Peeter Joot <peeter.joot at gmail.com> wrote:

> Hi Anna,
> In our case, regardless of whether you ever support more than one translation unit, there's effectively no practical way that our project (~7500 source files in a reduced build configuration) would ever be compiled in any other way than our own build system (which is very complex, and non-trivial to modify).  So we are stuck with invoking any analyzer at a file by file basis.

You should be able to analyze your project by calling clang --analyze on each translation unit. Just keep in mind that this might change in the future (ex: with whole project analyzes).

It might also possible that you could come up with a simple patch to scan-build which would make it suitable for your build system.

> If I try scan-build manually on just one file:
> $HOME/tmp/clang/llvm/tools/clang/tools/scan-build/scan-build -o $HOME/tmp/an/ --use-analyzer $HOME/local/bin/clang $HOME/local/bin/clang++ -c [SNIP MANY OPTIONS]  sqle_ca_cmd.C
> I end up with no output?  If I debug into ccc-analyzer, I see that it does invoke the compiler, but without adding any options.
>  In particular, it doesn't add: --analyze.  Do I need to both add that to my compilation options and also call scan-build?

You can look at the Analyze() routine in ccc-analyzer. It does not call "clang --analyze" directly, but calls a lower level "clang -cc1 -analyze -analyzer-checker=.." the command built by scan-build. Unless you specify extra options to scan-build they will be equivalent (scan-build calls clang --analyzer -### to get the equivalent cc1 command).

> -- 
> Peeter

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

More information about the cfe-dev mailing list