XCode 4.3 and Clang vs AppCode static analysis question.

Hello,

Please bear with me, I'm new to iOS development and Objective-C.

We have our XCode project setup to perform static analysis and have never seen the analyzer generate a message to date. I use AppCode to edit my code and I decided to evaluate its project level static analysis.

AppCode picked up 54 ivars that were not properly de-allocated. At least 50 of these were legit, (we nailed a couple memory leaks in fact.)

Should Clang have identified these?

I have attempted to run Clang from the command line to see if its an issue with the XCode project but encounter this error:
  clang: error: unsupported option '--serialize-diagnostics'

(I'm trying to find out what this option is and where its set in the project.)

NB, This project was originally started in XCode 4 , pre-ARC, and I have no idea if the project required tweaks or fixes in order to build.

Any pointers in understanding the capabilities of clang and how to work with it properly would be appreciated.

TIA
Seamus

Hello, Seamus. Clang does have support for this check, but it's disabled by default (possibly because of http://llvm.org/bugs/show_bug.cgi?id=8838 ).

To run the analyzer from the command line, see the instructions at http://clang-analyzer.llvm.org/scan-build.html . You can use "-enable-checker experimental.osx.cocoa.Dealloc" to see if it would have caught your problems.

I'm not sure if there are immediate plans to re-enable this check, but your e-mail demonstrates there is clearly interest in it. Ted or Anna might have something more definite to say on this.

Jordy

Hello,

I have attempted to run Clang from the command line to see if its an issue with the XCode project but encounter this error:
clang: error: unsupported option ‘–serialize-diagnostics’

You can investigate if the analyzer is triggered on your code by adding a function with a bug in it and analyzing the code base.
Ex: Add the following function and run XCode->Product->Analyze:

int foo(int x) {
if (x == 0)
return 5/x;
return 10/x;
}

I am not sure exactly how you are analyzing from command line, but the error you are getting is probably due to mismatched versions of XCode and the analyzer.

(I’m trying to find out what this option is and where its set in the project.)

There is also an option in the XCode Build settings called “Run Static Analyzer”, which would enable the analyzes during the build.

Hi Seamus,

You are running a version of the analyzer that is too old for that version of Xcode. You need to grab a newer checker build from clang-analyzer.llvm.org website.

Cheers,
Ted