analyzer: invoking a single analyzer from the static analysis tools.

Hello,

I have developed a simple checker, just to become familiar with Clang’s Checker API. I have sucessfully compiled it and installed in package alpha.security. For the sake of understanding and tracing the execution flow of the checker, I have added some “debug” lines like the following (I’m aware this is discouraged):

llvm::outs() << “BEGIN: checkPreStmt” << “\n”;

I run scan-build or clang --analyze, as suggested in previous answers, but I don’t see the messages printed out. The commands I’m running are:

(1) clang --analyze my_file.c

(2) scan-build clang -c my_file.c

Reading the manual, I understand that the reason is that “my” checker is not enabled by default, only a few.

So I tried the following command to enable it:

(3) scan-build -enable-checker alpha.security.DCL41C clang -c my_file.c

but again my “debugging” messages don’t appear in the standard output. So enabling verbose info with “-v -v” in command (3), I can see the complete command line run behind the scenes, and scan-build is passing:

‘-analyzer-checker’ ‘alpha.security.DCL41C’

but I’ve remarked that the checkers enabled by default are being enabled like this:

‘-analyzer-checker=core’ ‘-analyzer-checker=unix’ ‘-analyzer-checker=deadcode’ ‘-analyzer-checker=security.insecureAPI.UncheckedReturn’

So I saved the complete command lie to a shell script, and changed the options ‘-analyzer-checker’ ‘alpha.security.DCL41C’ to ‘-analyzer-checker=alpha.security.DCL41C’

The same problem: I don’t see the messages of llvm:outs, so I don’t whether my checker is being called, or the output of llvm::outs is going to some other place I don’t know.

My Clang version is a build that dates back to late Dec. 2013. I hope it’s not a bug :frowning:

clang version 3.5 (trunk 197976) (llvm/trunk 197973)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Any help would he highly appreciated

I’ve gone down a similar road within the last couple of days. I’m not sure I’ll be able to solve your problem – I’m just familiarizing myself with the tools and code myself – but I did get what you’re talking about to work for the simple checker that I made. Would you mind posting the entirety of the shell script you made?