Clang Static Analyzer Plugin doesn't work with xcodebuild

Hi,

I’m trying to use a clang static analyzer plugin with xcodebuild, but it doesn’t seem to load my plugin. I also tried the example plugin MainCallChecker at clang/examples/analyzer-plugin/MainCallChecker.cpp but no joy here. However, the plugin worked fine with makefile and when I directly used clang.

Here’s my simple test program [1]. It builds fine with xcodebuild [2].

Now, load the example plugin SampleAnalyzerPlugin.dylib via the -load-plugin switch and build the same project with xcodebuild [3]. Notice the error "no analyzer checkers are associated with ‘example.MainCallChecker’”. Is this a bug in xcodebuild or scan-build?

Thanks,
JS

[1]

jamesstark@taiko /tmp $ cat hello/hello/main.cpp
#include <stdio.h>

int main(int argc, const char * argv[])
{
printf(“Hi”);
return 0;
}

[2]
jamesstark@taiko /tmp $ xcodebuild -project hello/hello.xcodeproj
=== BUILD TARGET hello OF PROJECT hello WITH THE DEFAULT CONFIGURATION (Release) ===

Check dependencies

** BUILD SUCCEEDED **

[3]
jamesstark@taiko /tmp/hello $ scan-build -load-plugin /Users/jamesstark/llvm-release/Release+Asserts/lib/SampleAnalyzerPlugin.dylib --use-analyzer /Users/jamesstark/llvm-release/Release+Asserts/bin/clang -enable-checker example.MainCallChecker xcodebuild -project hello.xcodeproj
scan-build: Using ‘/Users/jamesstark/llvm-3.4-release/Release+Asserts/bin/clang’ for static analysis
Build settings from command line:
CLANG_ANALYZER_EXEC = /Users/jamesstark/llvm-3.4-release/Release+Asserts/bin/clang
CLANG_ANALYZER_OTHER_FLAGS = -analyzer-checker example.MainCallChecker
CLANG_ANALYZER_OUTPUT = plist-html
CLANG_ANALYZER_OUTPUT_DIR = /var/folders/j0/k921s0mn1njdbts14yns077c0000gn/T/scan-build-2014-06-27-175336-26848-1
RUN_CLANG_STATIC_ANALYZER = YES

=== ANALYZE TARGET hello OF PROJECT hello WITH THE DEFAULT CONFIGURATION (Release) ===

Check dependencies

AnalyzeShallow hello/main.cpp
cd /tmp/hello
export LANG=en_US.US-ASCII
/Users/jamesstark/llvm-3.4-release/Release+Asserts/bin/clang -x c++ -arch x86_64 -fmessage-length=150 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -std=gnu++11 -stdlib=libc++ -fmodules -Wno-trigraphs -fpascal-strings -Os -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.9 -g -fvisibility=hidden -fvisibility-inlines-hidden -Wno-sign-conversion -D__clang_analyzer__ -Xclang -analyzer-output=plist-html -Xclang -analyzer-config -Xclang path-diagnostics-alternate=true -Xclang -analyzer-config -Xclang report-in-main-source-file=true -Xclang -analyzer-config -Xclang mode=shallow -Xclang -analyzer-checker -Xclang security.insecureAPI.UncheckedReturn -Xclang -analyzer-checker -Xclang security.insecureAPI.getpw -Xclang -analyzer-checker -Xclang security.insecureAPI.gets -Xclang -analyzer-checker -Xclang security.insecureAPI.mkstemp -Xclang -analyzer-checker -Xclang security.insecureAPI.mktemp -Xclang -analyzer-disable-checker -Xclang security.insecureAPI.rand -Xclang -analyzer-disable-checker -Xclang security.insecureAPI.strcpy -Xclang -analyzer-checker -Xclang security.insecureAPI.vfork -Xclang -analyzer-checker -Xclang example.MainCallChecker -iquote /tmp/hello/build/hello.build/Release/hello.build/hello-generated-files.hmap -I/tmp/hello/build/hello.build/Release/hello.build/hello-own-target-headers.hmap -I/tmp/hello/build/hello.build/Release/hello.build/hello-all-target-headers.hmap -iquote /tmp/hello/build/hello.build/Release/hello.build/hello-project-headers.hmap -I/tmp/hello/build/Release/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/tmp/hello/build/hello.build/Release/hello.build/DerivedSources/x86_64 -I/tmp/hello/build/hello.build/Release/hello.build/DerivedSources -F/tmp/hello/build/Release --analyze /tmp/hello/hello/main.cpp -o /var/folders/j0/k921s0mn1njdbts14yns077c0000gn/T/scan-build-2014-06-27-175336-26848-1/StaticAnalyzer/hello/hello/normal/x86_64/main.plist
error: no analyzer checkers are associated with 'example.MainCallChecker’
1 error generated.

** BUILD SUCCEEDED **

scan-build: Removing directory ‘/var/folders/j0/k921s0mn1njdbts14yns077c0000gn/T/scan-build-2014-06-27-175336-26848-1’ because it contains no reports.
scan-build: No bugs found.

jamesstark@taiko /tmp/hello $ xcodebuild -version
Xcode 5.1.1
Build version 5B1008

All Xcode (and Apple LLVM compiler) bugs and feature requests
should be filed directly to Apple [1]. This list is for the open
source project.

[1]: http://bugreport.apple.com/

...and the Xcode compiler does not support static analyzer plugins. However, you can use scan-build to build an Xcode project with a custom build of Clang.

Jordan