SeattleBus Diary: Using CLANG static analyzer with an iPhone project

Like a number of other Mac developers, I caught the word and then the bug for using Clang Static Analyzer. I remember when I first caught wind of it, hearing about it on twitter and spotting a number of del.icio.us links to it. The note that really caught my attention was someone mentioning it and saying “too bad you can’t use it with the iPhone development…”.

That completely surprised me, because the first project I tried it on was SeattleBus. It was great for identifying a few memory leaks and missing -dealloc methods, I was hooked right off the bat. It wasn’t until later that I started trying to figure out that statement and realized that the analyzer doesn’t support analyzing ARM binaries. It does a great job on intel binaries though, so I realized that when I set my project to default to building for the simulator, I could use the analysis program.

My workflow after I’ve really worked on the codebase is now:

  • Make sure the project default settings are “debug” and “simulator”
  • Close Xcode
  • open a terminal window and “cd” to the project directory
  • run rm -rf /tmp/scan-build*
  • run rm -rf build/;scan-build --view xcodebuild
  • Open Xcode and fix errors

That’s been working great for me ever since.

7 thoughts on “SeattleBus Diary: Using CLANG static analyzer with an iPhone project

  1. Thanks for this! I ran scan-build on my project, but after going after the “low hanging fruit”, I had problems running it again. I would get some build errors that didn’t come with much explanation (and things built just fine with xCode). After running those “rm” commands, it worked great!

    Like

  2. Hi!
    I am trying to get this running. I made sure, that all the steps you suggested are done and I did a xcodebuild clean before running scan-build. Unfortunately, this runs and displays a webpage, which only describes errors related to compiling: Namely: “-miphoneos-version-min=2.2.1 is invalid, expected something like ‘2.0’.”.
    Any Idea, what I can do to make this work for me? I really need help finding my leaks🙂

    Like

    • You should still be able to get Clang open source to function with the current SDK (gcc 4.2). However, I suspect that if you wait until September, the workarounds to get the open source project will be mitigated.

      Like

  3. Check dependencies
    Code Sign error: The identity ‘iPhone Developer’ doesn’t match any valid certificate/private key pair in the default keychain
    [BEROR]Code Sign error: The identity ‘iPhone Developer’ doesn’t match any valid certificate/private key pair in the default keychain
    ** BUILD FAILED **
    – I got this error, what does it mean.

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s