Oct 11
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.

November 17th, 2008 at 10:34 am
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!
January 2nd, 2009 at 8:11 pm
[...] for device builds no … but the simulator uses Intel binaries! Convenient, no? Thanks to this post for explaining to us My workflow after I’ve really worked on the codebase is [...]
May 4th, 2009 at 10:11 am
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
June 11th, 2009 at 5:30 pm
It seem that it does not work for sdk 3.0 wrong gcc
June 11th, 2009 at 9:30 pm
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.