[cfe-dev] How does scan-build
Дилян Палаузов via cfe-dev
cfe-dev at lists.llvm.org
Thu Jul 18 09:25:00 PDT 2019
Hello Arthur,
intercepting calls by scan-build, during it calls make or ninja, does make sense, to detect when clang is actually
invoked.
But a possible way to call scan-build is with the form “scan-build >any-compiler< compile-options”. The compiler could
be clang, gcc or anything else. How can a preloaded library intercept the execution of any compiler, but not for a non-
compiler?
Regards
Дилян
On Thu, 2019-07-18 at 09:59 -0400, Arthur O'Dwyer wrote:
> 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
More information about the cfe-dev
mailing list