Hi All,
I am new to the development side of Clang, I have built from source and am
trying to run the static analyzer on the test files included in the clang
source. I'm using the arguments within each test file but I am not able to
get anything specific to work.
Example: I run the following command
clang -cc1 -analyze -analyzer-checker=core,core.experimental.CastToStruct
And get this error in return:
Argument unused during compilation: '-analyze'
Argument unused during compilation: '-analyze-checker'
It appears to me that the checkers are not being ran at all. Any advice on
how to rectify this problem? Thank you for your time!
Eric
Right now the recommended way to run the checkers for external
projects is using the 'scan-build' tool (located under
./llvm/tools/clang/tools/scan-build, and its cousin, scan-view for
viewing reports.) It's basically a hack^H^H^H^H perl script that
transposes the clang analyzer into your build, followed by running
your real compiler (like gcc) over it. So it really makes the analysis
'transparent' to your regular build system. You can effectively just
put the 'scan-build' command in front of your regular build system
command, and the script will 'do the rest' (by properly setting CC
vars, etc..)
The situation isn't optimal since scan-build isn't full proof, but it
works in a surprising amount of situations (I've had success with
make, xcodebuild, waf, etc etc.) There are outstanding bugs on the
tracker related to moving scan-build functionality into the clang
driver, but I there are probably still some issues to work out
relating to the design before that can be done (like how the user
should invoke the driver, should compilation proceed with the
analyzer, or do you only want to run the analyzer and abandon actual
codegen? etc.)
scan-build also does not enable all checkers (such as experimental
ones) by default. If you run 'scan-build -h' you can see the list of
available checkers and what's enabled by default, and you can use
'-enable-checker <name>' to enable an extra one.
If you're curious, you can also invoke 'scan-build -v' when you run it
and it'll show you the list of arguments it directly passes to the
clang -cc1 driver during the compilation, so you can see the 'real'
command line needed to invoke the analyzer. Last time I tried this the
arguments were somewhat involved, so if possible it'd probably be best
to just use scan-build and save yourself the trouble (or if that
doesn't work, perhaps help move scan-build into the compiler
driver...)
Thanks for the quick response Austin!
The main reason why I have rebuilt Clang in the first place was because I
created a new checker and I wanted to test it out on some code that I wrote.
Is there any way to get scan-build to point to my executable of clang in my
build directory? Just for some context, I created the checker.cpp file,
added it to checker directory and added a new line in checkers.td then
subsequently built llvm+clang. All and all, my primary goal is to extend
clang in terms of new checkers and have been trying to get the analysis to
run with these new checkers. If there is any advice or guidance it would be
greatly appreciated! Thanks again for taking your time to help!
Eric
The main reason why I have rebuilt Clang in the first place was because I
created a new checker and I wanted to test it out on some code that I wrote.
Is there any way to get scan-build to point to my executable of clang in my
build directory?
I'd guess that scan-build will use whatever clang executable it finds
first on your PATH. Perhaps just set your PATH to point to your clang
build before any other, and then try?
Note: I can't verify this, it's just reasonable speculation. Ted or
someone would have to chime in to tell you the truth with any
confidence.
Just for some context, I created the checker.cpp file,
added it to checker directory and added a new line in checkers.td then
subsequently built llvm+clang. All and all, my primary goal is to extend
clang in terms of new checkers and have been trying to get the analysis to
run with these new checkers. If there is any advice or guidance it would be
greatly appreciated! Thanks again for taking your time to help!
I've written a few checkers in my spare time too and honestly I
normally end up putting them in the 'Core' package (in Checkers.td)
during development so they are always on by default and I can just use
'scan-build,' and move them to other packages (like core.experimental)
later once I'm done. Granted I only wrote tiny ones that I didn't push
upstream (because coincidentally, other people ended up
re-implementing them within the same day or two. 