开发者

Using an external Xcode Clang Static Analyzer binary, with additional checks

开发者 https://www.devze.com 2023-01-08 18:12 出处:网络
I’m using Xcode 3.2.4 and have setup the Clang Static Analyser feature to use a newer build of the binary, as detailed here: http://clang-analyzer.llvm.org/xcode.html

I’m using Xcode 3.2.4 and have setup the Clang Static Analyser feature to use a newer build of the binary, as detailed here: http://clang-analyzer.llvm.org/xcode.html

(Basically using the set-xcode-analyzer command line utility to change which copy of the Static Analyser that Xcode uses for Build and Analyze.)

What I can’t figure is how to set that binary to use additional checks, such as -analyzer-check-objc-missing-dealloc when using the binary via Xcode, as detailed here: http://loufranco.com/blog/files/scan-build-better-than-build-analyze.html and in scan-build --help.

    AVAILABLE ANALYSES (multiple analyses may be specified):

 (+) -analyzer-check-dead-stores
     -analyzer-check-llvm-conventions
 (+) -analyzer-check-objc-mem
 (+) -analyzer-check-objc-methodsigs
     -analyzer-check-objc-missing-dealloc
 (+) -analyzer-check-objc-unused-ivars
 (+) -analyzer-check-security-syntactic

 NOTE: "(+)" indicates that an analysis is enabled by default unless one
     开发者_如何学运维  or more analysis options are specified

How do you pass in extra options to the binary when used via Xcode?


Upon further investigation, it seems the best way to do this is to use a couple of entries in the Target Build Info, rather than the set-xcode-analyzer command line tool.

Add a User-defined setting, CC, containing the full path to the newer build of the binary, as follows (note that the /bin/clang on the end of the path):

CC = /Path/To/Folder/With/Clang/checker-244/bin/clang

Then in the Other Warning Flags entry add as many of the additional checks as you want, as follows:

WARNING_CFLAGS = -Xanalyzer -analyzer-check-llvm-conventions -Xanalyzer -analyzer-check-objc-missing-dealloc

Each is preceded by the argument -Xanalyzer which indicates that the next argument should be passed to the analyzer.

More on this can be found here: Mac OS X Developer Tools Manual Page.

Then, when you do a Build and Analyze in Xcode you should be using the external, newer binary running the additional checks.


The accepted answer no longer works (Xcode 4)

The format of Xcode's build file means you have to do it like this:

WARNING_CFLAGS = "-Xanalyzer -analyzer-check-llvm-conventions -analyzer-check-objc-missing-dealloc"

NB: the quotes surrounding the entire XAnalyzer phrase.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号