Clang Static Analyzer without scan-build

I would like to use the Clang Static Analyzer in our projects but I’m having some difficulties in figuring out how to integrate it in our build systems.

We currently use SCons to build our projects. We develop firmware for embedded systems, so a single project usually builds executables for different targets using different toolchains. In addition, the SCons script will build the unit tests using the host system compiler in order to run them on the host.

At the moment we are using PC-Lint to perform static analysis. This tool can be used like a typical compiler. You can compile a single source file to a (sort of) object file, the object files can be grouped in libraries, object files and libraries can be linked to a (sort of) final executable. During the compilation the tool analyzes the single source file in isolation, during the link it does some inter-module analysis. This approach fits very well with our build system, because we can use the lint tool like any other toolchain.

I understand that Clang Static Analyzer is driven by the scan-build script. This script substitutes calls to the compiler with calls to the static analyzer by acting on the typical build variables like CC. This approach does not work with our build system, because we do not use any external build variable but instead the build script will explicitly select different toolchains while building programs for different targets.

Is there a (documented) way to use Clang Static Analyzer directly without the scan-build script?

Michele Galante
Direzione Tecnica
Laboratorio delle Idee

I would like to use the Clang Static Analyzer in our projects but I'm
having some difficulties in figuring out how to integrate it in our build
systems.

We currently use SCons to build our projects. We develop firmware for
embedded systems, so a single project usually builds executables for
different targets using different toolchains. In addition, the SCons script
will build the unit tests using the host system compiler in order to run
them on the host.

At the moment we are using PC-Lint to perform static analysis. This tool
can be used like a typical compiler. You can compile a single source file
to a (sort of) object file, the object files can be grouped in libraries,
object files and libraries can be linked to a (sort of) final executable.
During the compilation the tool analyzes the single source file in
isolation, during the link it does some inter-module analysis. This
approach fits very well with our build system, because we can use the lint
tool like any other toolchain.

I understand that Clang Static Analyzer is driven by the scan-build
script. This script substitutes calls to the compiler with calls to the
static analyzer by acting on the typical build variables like CC. This
approach does not work with our build system, because we do not use any
external build variable but instead the build script will explicitly select
different toolchains while building programs for different targets.

Is there a (documented) way to use Clang Static Analyzer directly without
the scan-build script?

If you can somehow create a compilation database (cmake and ninja currently
can do so, adding support for scons shouldn't be too hard -
http://clang.llvm.org/docs/JSONCompilationDatabase.html), you can use
$ clang-check -analyze path/to/my/file.cpp

Cheers,
/Manuel

you can use bear <https://github.com/rizsotto/Bear> to get the compilation database… if you use linux/freebsd/osx, it works with scons.

regards,
Laszlo