[cfe-dev] How does scan-build

Arthur O'Dwyer via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 18 06:59:55 PDT 2019


On Thu, Jul 18, 2019 at 5:54 AM Дилян Палаузов via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hello,
>
> how does scan-build exactly parse its parameters?
>
> How does “scan-build make” know, that it should just invoke make and not
> do anything until a compiler is invoked.
>

My understanding is that scan-build itself merely sets
`LD_PRELOAD=some-library.so` for all processes spawned directly or
indirectly from scan-build. Then it goes ahead and spawns a child process
to run whatever command you gave it — e.g., `make`.
`make` will eventually spawn a child or grandchild process for `clang`.
When that happens, `some-library.so` will notice and cause different
behavior. Either it will tell `clang` to invoke the static analyzer, or it
will write out "hey, clang is being called!" to an external trace log. This
external trace log is what Christian and Paulo are calling a "compilation
database." The trace can be used later to re-invoke the static analyzer for
each file that was compiled during the build, without having to `make
clean` the entire project.

I confirmed some of my recollections via this documentation:
https://github.com/rizsotto/scan-build


> Does “scan-build cc …” parse in fact the source code, or the generated
> object files and in the former case, is the
> compiler invoked or does scan-build just considers the parameters passed
> to the compiler?
>

`scan-build` causes the static analyzer to be invoked. The static analyzer
*must* parse the C++ source code. There is no way to "static-analyze" an
object file.

–Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190718/2f325719/attachment.html>


More information about the cfe-dev mailing list