2

I've used the Clang Static Analyzer from the command line before. I wanted to try Xcode's built-in version via Build & Analyze. I never get any negative results even though i specially prepared my code with very obvious issues Clang was always able to point out:

    // over-releasing an object:
    [label release];
    [label release];

    // uninitialized vars, allocating but not freeing an object
    NSString* str;
    int number;
    CCLabel* newLabel = [[CCLabel alloc] initWithString:str fontName:str fontSize:number];
    [newLabel setPosition:CGPointZero];

The result is always the same: a green checkbox, no issues. I read that C++ code can cause issues. I'm running this with cocos2d that includes box2d. Could this be a cause? Did anyone get results from Build & Analyze with the cocos2d engine? What else could it be?

I also tried enabling the Static Analyzer Build Settings and then Build but the result was the same. I have restarted Xcode, cleaned all targets and emptied Xcode caches to no avail.


UPDATE: my issue could be caused by having added cocos2d as a cross-project reference to my project. Analyzing the cocos2d project itself seperately reveals some analyzer results.

In addition i found out that i get Analyzer results from my RELEASE build configurations but not from DEBUG builds.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217

3 Answers3

1

I'm using Cocos2d and Box2d, and I get plenty of warnings from Build and Analyze. Check to make sure your project's compiler is set to GCC 4.2 under "Compiler Version" in the Build Settings.

Chris Garrett
  • 4,824
  • 1
  • 34
  • 49
  • Actually it has to be set to "LLVM GCC 4.2" ... with that i'm getting analyze results! However, i also get a "can't exec" error precompiling the prefix header. I'll have to dig into that, maybe i need to update the LLVM GCC? – CodeSmile May 01 '10 at 10:10
  • i realized i still had SDK 3.2 Seed installed, i'll re-install SDK 3.2 final and check if i forgot to install something because the "llvm-gcc-4.2" executable doesn't exist in my Xcode install – CodeSmile May 01 '10 at 10:28
  • now i'm getting no results again ... argh. I think i'll just stick with the command line llvm gcc instead of wasting anymore time on this. – CodeSmile May 01 '10 at 12:46
  • Did you clean all targets first? – alexyorke Aug 28 '10 at 19:00
1

For anyone that might come across this thread (and for the OP in case the problem persists):

I had this problem when building for the Simulator. However, switching to Device build got the Analyzer running.

This site might shed some more light on the issue: http://useyourloaf.com/blog/2010/10/5/xcode-build-and-analyze-broken-for-simulator.html

stackdaemon
  • 309
  • 4
  • 10
0

I also get plenty of Analyze warnings with my Cocos2d game. I cleaned most of them up, but cocos2d 0.99.1 has 3 built-in! (Which should be easily fixed.)

I have noticed that sometimes the analyzer doesn't find things unless I have that particular file open when I run it... go figure.

Jeff B
  • 29,943
  • 7
  • 61
  • 90
  • 1
    for a full analysis you have to run a clean build, otherwise the compiler won't analyze already compiled files – CodeSmile May 01 '10 at 10:29