Clang ++ Static Analyzer and Makefile

I recently discovered a function of the static analyzer clang ++, and it's fantastic when I looked through my code with a thin jagged comb to find hidden errors. I just uncomment this line in the Makefile:

CXXFLAGS += --analyze -Xanalyzer -analyzer-output=text 

et voila, I'm in deep error checking mode.

However, one minor problem is that whenever the analyzer does not detect any problems in a particular .cpp file, no .o file is created.

Usually this will not be a big problem (I can always recompose the above line to create the actual executable), but usually when I see the analyzer warning, the first thing I want to do is try to fix the main problem and then run make again.

... which works, but since the .o files are not generated, make will begin to re-analyze all the .cpp files again from the very beginning, not just the .cpp files that I actually changed since the previous run. This means that I end up spending quite a lot of time re-checking .cpp files that haven't changed.

My question is, is there a way to get the static analyzer to output the .o file (it should not be a valid object file, just any file with an updated time stamp), so Make will know that the β€œclean” .cpp file does not need to be repeated processing? (i.e. make make work the same as with regular compilation)

+4
source share
1 answer

Browse the clan parser page and get the download package. You can use the supplied scan-build tool to do what you are trying.

The usual way to use it is to get rid of the flags you have and just run:

 $ scan-build make whatever 

And he should "just work." You may need to pass a few more flags or set some environment variables if you are not using the standard make variable names.

+3
source

Source: https://habr.com/ru/post/1501563/


All Articles