19 July 2008

Clang Static Code Analysis Rocks

Wow. I’d seen Quentin Carnicelli’s note about the Clang static analyzer, but my first attempt to use it was on a C++/Objective-C++ project, and all it did was find potential problems in open source libraries. Turns out it doesn’t really have a C++ parser yet.

Today I tried it on an Objective-C project, Opal. Pay dirt! It found a number of memory leaks (some in code that’s not released yet, but some in code that I didn’t exercise while looking for leaks, such as printing with headers). One of the reported leaks was actually a false positive, but the others were valid problems.

And dead store found some small optimizations (why calculate something you never use?).

The tool is trivial to use (just invoke it from the command line, it figures out your Xcode project from there), and really does find code flaws. Oh, and it’s free. I’m looking forward to being able to use with C++ code.

(It’s available pre-built for Mac OS X developers. Others will have to build it from source.) If you’re using C or Objective-C, you should use it.

No comments: