Running clang with a smaller set of Checkers

Hi,

I wrote a checker which I need to run on all translation units, then
summarize its output and re-run clang on all translation units
(inter-procedural by a pass to collect data and a second pass using it).

I wish to run clang for the first pass, disabling all checkers but my data
collector, but I fail to do this. Any idea?

I could change the core checkers set (checkers.td), but having to recompile
clang and hold two clang versions for thew two passes seems excessive.

Thanks, Yuval.

Hi, Yuval. The analyzer will not run properly if the “core” checkers are not run—they help prune infeasible paths. (For example, if you divide by a number ‘x’, we know that ‘x’ is non-zero after that point.) However, the other checkers can be turned off using an internal option -analyzer-disable-checker=unix,osx,cplusplus,deadcode; in order to make sure this option reaches the analyzer, you’ll have to prepend it with -Xclang.

If you want to be 100% sure all the other checkers are off, you can see the command line generated by clang --analyze by adding -### to the end. Then you can strip out all the checkers besides “core”, and add your own. However, I don’t recommend saving the resulting command line because new options are added all the time, and while “clang --analyze” will always do the right thing, “clang -cc1 -analyze…” may be missing some critical options down the line.

Does this solve your problem?
Jordan

P.S. I’d be interested in seeing your setup once you’ve finished it. General cross-translation-unit analysis is something still off in the future for the analyzer, but when we get there some day we’ll need a solid design.

Ah, I see. If you’re only running syntax-based checkers (checkASTDecl, checkASTCodeBody, and checkEndOfTranslationUnit), then it’s perfectly fine to run without the core checkers.

We’ve been meaning to make it so the core checkers are enabled by default (and can’t be disabled) if any other path-sensitive checkers are enabled, but for now --analyze still has to enable them explicitly.

As I mentioned below, you can make sure the -analyzer-disable-checker option reaches the analyzer by using “-Xclang -analyzer-disable-checker=core,unix,cplusplus,osx,deadcode”.

Jordan