Is there a way to disable the static analyzer per file?

Moderator
Posts: 3,573
Joined: 2003.06
Post: #1
I like using the static analyzer every build nowadays. Even though it's a little paranoid about a few things, it has definitely helped me make better code. But I have some files from someone else included in my project and they did a whole bunch of err = blahblah() and they hardly ever actually *read* err, which drives the analyzer nuts, and so I get a crap-load of messages telling me about it. Since that's not my code, I don't feel like going through the hassle of cleaning it up just for this, but it'd be nice to get the static analyzer to skip those files. Anybody know how to exclude those files from the analyzer's sight in Xcode? I somehow doubt it, but I figured it was worth asking.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
http://clang-analyzer.llvm.org/annotations.html gives a few suggestions for how to conditionalize various things for the analyzer, not sure if any are helpful to you.

If you're not compiling with clang just now, #if !defined(__clang__) around the whole file would certainly do for now. There might be an analyzer-specific define too..
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Just checked:

Code:
$ echo | /Developer/usr/bin/clang -dM -E -x c - > clangmacros.txt
$ echo | /Developer/usr/bin/clang --analyze -dM -E -x c - > clanganalyzemacros.txt
clang: warning: argument unused during compilation: '--analyze'
$ diff clangmacros.txt clanganalyzemacros.txt
[no output]
$ rm clangmacros.txt clanganalyzemacros.txt

So nope, no way to distinguish the analyzer from the compiler. File a bug.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #4
OneSadCookie Wrote:So nope, no way to distinguish the analyzer from the compiler. File a bug.

Will do. Thanks.
Quote this message in a reply
Post Reply