Bug Finding With Clang: 5 Resources To Get You Started
One of the most interesting bits to be spawned from Low Level Virtual Machine (LLVM) Compiler Infrastructure project is the LLVM/Clang Static Analyzer.
The Clang Static Analyzer, usually shortened to Clang (to the exasperation of its creators), uses compiler techniques to analyze the structure of C and Objective-C programs to identify bugs.
While described by its developers as being “very early in development,” its fans sing its praises:
Geoffrey Grosenbach, says “[it’s] indispensable for finding memory leaks. It prints a nice report with line-by-line commentary and suggestions for where objects should be released.”
Quentin Carnicell explains, “the Clang Checker has a vastly better understanding of your code than a compiler. It can detect memory leaks, double-frees, bad pointer references, and other such bugs that keep you up at night.”
We’ve compiled — pun intended — some resources to get you started:
The project’s Using the Static Analyzer page provides basic usage instructions, information on obtaining the analyzer, and recommended usage guidelines.
Basil Shkara posted terse, but helpful step-by-step directions for using Clang on an iPhone project.
Mike Ash’s Using the Clang Static Analyzer not only demonstrates its use, but shows how it can turn up very subtle bugs.
Ted Kremenek, one of the Apple Engineers working on the project, gave a presentation titled “Finding software bugs with the Clang Static Analyzer.” The video and slides are available for download.
Fraser Speirs shows how he uses git’s pre-commit hooks to automatically kick off the analyzer and block changes from being committed if errors are found.
The most easy to use package I found is:
https://www.karppinen.fi/analysistool/
It’s a Mac-App, which allows you to run the Clang-Static Analyzer on your Mac&iPhone projects with a single click. Very easy!
Rad stuff, Dan