Reputation: 21
How to check only one checker by CLANG?
When i use clang to check warning, i use this way
# clang --analyze *.c
I want to use ONLY ONE CHECKER to check it.
ex) core.DivideZero(C, C++, ObjC) only
Pls tell me some options to do it!
Upvotes: 2
Views: 920
Reputation: 12749
To run a single checker using clang --analyze
, add --analyzer-no-default-checks -Xanalyzer -analyzer-checker=<checker>
to the command line. For example:
$ clang --analyze --analyzer-no-default-checks -Xanalyzer -analyzer-checker=core.DivideZero hello.c
hello.c:44:12: warning: Division by zero
return 6 / z;
~~^~~
1 warning generated.
In this case, hello.c
contains three defects of various kinds that would be reported by default, but by enabling only core.DivideZero
, just that one is reported. The code fragment that provokes this report is:
int divide_by_zero()
{
int z = 0;
return 6 / z;
}
I figured out how to run a single checker mainly by looking at the Clang Command Line Argument Reference, but that's not very clear so it needed some trial and error as well. The clang
program is sort of a multi-purpose front-end that calls other tools under the hood, so getting all the switches in the right places with the right -X
, -
, and --
prefixes is a bit of a challenge.
Also useful is the list of Available Checkers, which includes names like core.DivideZero
.
I tested with clang+llvm versions 3.7.1 and 8.0.1 on Linux/x86_64.
Upvotes: 3