1*f4a2713aSLionel Sambuc<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2*f4a2713aSLionel Sambuc "http://www.w3.org/TR/html4/strict.dtd"> 3*f4a2713aSLionel Sambuc<html> 4*f4a2713aSLionel Sambuc<head> 5*f4a2713aSLionel Sambuc <title>Clang Static Analyzer</title> 6*f4a2713aSLionel Sambuc <link type="text/css" rel="stylesheet" href="content.css"> 7*f4a2713aSLionel Sambuc <link type="text/css" rel="stylesheet" href="menu.css"> 8*f4a2713aSLionel Sambuc <script type="text/javascript" src="scripts/menu.js"></script> 9*f4a2713aSLionel Sambuc <!-- Generated from: http://www.spiffycorners.com/index.php --> 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc<style type="text/css"> 12*f4a2713aSLionel Sambuc.spiffy{display:block} 13*f4a2713aSLionel Sambuc.spiffy *{ 14*f4a2713aSLionel Sambuc display:block; 15*f4a2713aSLionel Sambuc height:1px; 16*f4a2713aSLionel Sambuc overflow:hidden; 17*f4a2713aSLionel Sambuc font-size:.01em; 18*f4a2713aSLionel Sambuc background:#EBF0FA} 19*f4a2713aSLionel Sambuc.spiffy1{ 20*f4a2713aSLionel Sambuc margin-left:3px; 21*f4a2713aSLionel Sambuc margin-right:3px; 22*f4a2713aSLionel Sambuc padding-left:1px; 23*f4a2713aSLionel Sambuc padding-right:1px; 24*f4a2713aSLionel Sambuc border-left:1px solid #f6f8fc; 25*f4a2713aSLionel Sambuc border-right:1px solid #f6f8fc; 26*f4a2713aSLionel Sambuc background:#f0f3fb} 27*f4a2713aSLionel Sambuc.spiffy2{ 28*f4a2713aSLionel Sambuc margin-left:1px; 29*f4a2713aSLionel Sambuc margin-right:1px; 30*f4a2713aSLionel Sambuc padding-right:1px; 31*f4a2713aSLionel Sambuc padding-left:1px; 32*f4a2713aSLionel Sambuc border-left:1px solid #fdfdfe; 33*f4a2713aSLionel Sambuc border-right:1px solid #fdfdfe; 34*f4a2713aSLionel Sambuc background:#eef2fa} 35*f4a2713aSLionel Sambuc.spiffy3{ 36*f4a2713aSLionel Sambuc margin-left:1px; 37*f4a2713aSLionel Sambuc margin-right:1px; 38*f4a2713aSLionel Sambuc border-left:1px solid #eef2fa; 39*f4a2713aSLionel Sambuc border-right:1px solid #eef2fa;} 40*f4a2713aSLionel Sambuc.spiffy4{ 41*f4a2713aSLionel Sambuc border-left:1px solid #f6f8fc; 42*f4a2713aSLionel Sambuc border-right:1px solid #f6f8fc} 43*f4a2713aSLionel Sambuc.spiffy5{ 44*f4a2713aSLionel Sambuc border-left:1px solid #f0f3fb; 45*f4a2713aSLionel Sambuc border-right:1px solid #f0f3fb} 46*f4a2713aSLionel Sambuc.spiffyfg{ 47*f4a2713aSLionel Sambuc background:#EBF0FA} 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc.spiffyfg h2 { 50*f4a2713aSLionel Sambuc margin:0px; padding:10px; 51*f4a2713aSLionel Sambuc} 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc #left { float:left; } 54*f4a2713aSLionel Sambuc #left h2 { margin:1px; padding-top:0px; } 55*f4a2713aSLionel Sambuc #right { float:left; margin-left:20px; margin-right:20px; padding:0px ;} 56*f4a2713aSLionel Sambuc #right h2 { padding:0px; margin:0px; } 57*f4a2713aSLionel Sambuc #wrappedcontent { padding:15px;} 58*f4a2713aSLionel Sambuc</style> 59*f4a2713aSLionel Sambuc</head> 60*f4a2713aSLionel Sambuc<body> 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc<div id="page"> 63*f4a2713aSLionel Sambuc<!--#include virtual="menu.html.incl"--> 64*f4a2713aSLionel Sambuc<div id="content"> 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc<table style="margin-top:0px" width="100%" border="0" cellpadding="0px" cellspacing="0"> 68*f4a2713aSLionel Sambuc<tr><td> 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc<h1>Clang Static Analyzer</h1> 71*f4a2713aSLionel Sambuc 72*f4a2713aSLionel Sambuc<p>The Clang Static Analyzer is a source code analysis tool that finds bugs in 73*f4a2713aSLionel SambucC, C++, and Objective-C programs.</p> 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc<p>Currently it can be run either as a <a href="scan-build.html">standalone 76*f4a2713aSLionel Sambuctool</a> or <a href="xcode.html">within Xcode</a>. The standalone tool is 77*f4a2713aSLionel Sambucinvoked from the command line, and is intended to be run in tandem with a build 78*f4a2713aSLionel Sambucof a codebase.</p> 79*f4a2713aSLionel Sambuc 80*f4a2713aSLionel Sambuc<p>The analyzer is 100% open source and is part of the <a 81*f4a2713aSLionel Sambuchref="http://clang.llvm.org">Clang</a> project. Like the rest of Clang, the 82*f4a2713aSLionel Sambucanalyzer is implemented as a C++ library that can be used by other tools and 83*f4a2713aSLionel Sambucapplications.</p> 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambuc<h2>Download</h2> 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambuc<div style="padding:0px; font-size: 90%"> 88*f4a2713aSLionel Sambuc <b class="spiffy"> 89*f4a2713aSLionel Sambuc <b class="spiffy1"><b></b></b> 90*f4a2713aSLionel Sambuc <b class="spiffy2"><b></b></b> 91*f4a2713aSLionel Sambuc <b class="spiffy3"></b> 92*f4a2713aSLionel Sambuc <b class="spiffy4"></b> 93*f4a2713aSLionel Sambuc <b class="spiffy5"></b></b> 94*f4a2713aSLionel Sambuc <div class="spiffyfg"> 95*f4a2713aSLionel Sambuc <div style="padding:15px"> 96*f4a2713aSLionel Sambuc <h3 style="margin:0px;padding:0px">Mac OS X</h3> 97*f4a2713aSLionel Sambuc <ul> 98*f4a2713aSLionel Sambuc <li>Latest build (Intel-only binary, 10.5+):<br> 99*f4a2713aSLionel Sambuc <!--#include virtual="latest_checker.html.incl"--> 100*f4a2713aSLionel Sambuc </li> 101*f4a2713aSLionel Sambuc <li><a href="/release_notes.html">Release notes</a></li> 102*f4a2713aSLionel Sambuc <li>This build can be used both from the command line and from within Xcode</li> 103*f4a2713aSLionel Sambuc <li><a href="/installation.html">Installation</a> and <a href="/scan-build.html">usage</a></li> 104*f4a2713aSLionel Sambuc </ul> 105*f4a2713aSLionel Sambuc </div> 106*f4a2713aSLionel Sambuc </div> 107*f4a2713aSLionel Sambuc <b class="spiffy"> 108*f4a2713aSLionel Sambuc <b class="spiffy5"></b> 109*f4a2713aSLionel Sambuc <b class="spiffy4"></b> 110*f4a2713aSLionel Sambuc <b class="spiffy3"></b> 111*f4a2713aSLionel Sambuc <b class="spiffy2"><b></b></b> 112*f4a2713aSLionel Sambuc <b class="spiffy1"><b></b></b></b> 113*f4a2713aSLionel Sambuc</div> 114*f4a2713aSLionel Sambuc 115*f4a2713aSLionel Sambuc<div style="padding:0; margin-top:10px; font-size: 90%"> 116*f4a2713aSLionel Sambuc <b class="spiffy"> 117*f4a2713aSLionel Sambuc <b class="spiffy1"><b></b></b> 118*f4a2713aSLionel Sambuc <b class="spiffy2"><b></b></b> 119*f4a2713aSLionel Sambuc <b class="spiffy3"></b> 120*f4a2713aSLionel Sambuc <b class="spiffy4"></b> 121*f4a2713aSLionel Sambuc <b class="spiffy5"></b></b> 122*f4a2713aSLionel Sambuc <div class="spiffyfg"> 123*f4a2713aSLionel Sambuc <div style="padding:15px"> 124*f4a2713aSLionel Sambuc <h3 style="margin:0px;padding:0px">Other Platforms</h3> 125*f4a2713aSLionel Sambuc <p>For other platforms, please follow the instructions for <a 126*f4a2713aSLionel Sambuc href="/installation#OtherPlatforms">building the analyzer</a> from 127*f4a2713aSLionel Sambuc source code.<p> 128*f4a2713aSLionel Sambuc </div> 129*f4a2713aSLionel Sambuc </div> 130*f4a2713aSLionel Sambuc <b class="spiffy"> 131*f4a2713aSLionel Sambuc <b class="spiffy5"></b> 132*f4a2713aSLionel Sambuc <b class="spiffy4"></b> 133*f4a2713aSLionel Sambuc <b class="spiffy3"></b> 134*f4a2713aSLionel Sambuc <b class="spiffy2"><b></b></b> 135*f4a2713aSLionel Sambuc <b class="spiffy1"><b></b></b></b> 136*f4a2713aSLionel Sambuc</div> 137*f4a2713aSLionel Sambuc 138*f4a2713aSLionel Sambuc 139*f4a2713aSLionel Sambuc</td><td style="padding-left:10px"> 140*f4a2713aSLionel Sambuc<a href="images/analyzer_xcode.png"><img src="images/analyzer_xcode.png" width="450" alt="analyzer in xcode"></a> 141*f4a2713aSLionel Sambuc<div style="text-align:center"><b>Viewing static analyzer results in Xcode</b></div> 142*f4a2713aSLionel Sambuc<a href="images/analyzer_html.png"><img src="images/analyzer_html.png" width="450" alt="analyzer in browser"></a> 143*f4a2713aSLionel Sambuc<div style="text-align:center"><b>Viewing static analyzer results in a web browser</b></div> 144*f4a2713aSLionel Sambuc</td></tr></table> 145*f4a2713aSLionel Sambuc 146*f4a2713aSLionel Sambuc<h2 id="StaticAnalysis">What is Static Analysis?</h2> 147*f4a2713aSLionel Sambuc 148*f4a2713aSLionel Sambuc<p>The term "static analysis" is conflated, but here we use it to mean 149*f4a2713aSLionel Sambuca collection of algorithms and techniques used to analyze source code in order 150*f4a2713aSLionel Sambucto automatically find bugs. The idea is similar in spirit to compiler warnings 151*f4a2713aSLionel Sambuc(which can be useful for finding coding errors) but to take that idea a step 152*f4a2713aSLionel Sambucfurther and find bugs that are traditionally found using run-time debugging 153*f4a2713aSLionel Sambuctechniques such as testing.</p> 154*f4a2713aSLionel Sambuc 155*f4a2713aSLionel Sambuc<p>Static analysis bug-finding tools have evolved over the last several decades 156*f4a2713aSLionel Sambucfrom basic syntactic checkers to those that find deep bugs by reasoning about 157*f4a2713aSLionel Sambucthe semantics of code. The goal of the Clang Static Analyzer is to provide a 158*f4a2713aSLionel Sambucindustrial-quality static analysis framework for analyzing C, C++, and 159*f4a2713aSLionel SambucObjective-C programs that is freely available, extensible, and has a high quality of implementation.</p> 160*f4a2713aSLionel Sambuc 161*f4a2713aSLionel Sambuc<h3 id="Clang">Part of Clang and LLVM</h3> 162*f4a2713aSLionel Sambuc 163*f4a2713aSLionel Sambuc<p>As its name implies, the Clang Static Analyzer is built on top of <a 164*f4a2713aSLionel Sambuchref="http://clang.llvm.org">Clang</a> and <a href="http://llvm.org">LLVM</a>. 165*f4a2713aSLionel SambucStrictly speaking, the analyzer is part of Clang, as Clang consists of a set of 166*f4a2713aSLionel Sambucreusable C++ libraries for building powerful source-level tools. The static 167*f4a2713aSLionel Sambucanalysis engine used by the Clang Static Analyzer is a Clang library, and has 168*f4a2713aSLionel Sambucthe capability to be reused in different contexts and by different clients.</p> 169*f4a2713aSLionel Sambuc 170*f4a2713aSLionel Sambuc<h2>Important Points to Consider</h2> 171*f4a2713aSLionel Sambuc 172*f4a2713aSLionel Sambuc<p>While we believe that the static analyzer is already very useful for finding 173*f4a2713aSLionel Sambucbugs, we ask you to bear in mind a few points when using it.</p> 174*f4a2713aSLionel Sambuc 175*f4a2713aSLionel Sambuc<h3>Work-in-Progress</h3> 176*f4a2713aSLionel Sambuc 177*f4a2713aSLionel Sambuc<p>The analyzer is a continuous work-in-progress. There are many planned 178*f4a2713aSLionel Sambucenhancements to improve both the precision and scope of its analysis algorithms 179*f4a2713aSLionel Sambucas well as the kinds of bugs it will find. While there are fundamental 180*f4a2713aSLionel Sambuclimitations to what static analysis can do, we have a long way to go before 181*f4a2713aSLionel Sambuchitting that wall.</p> 182*f4a2713aSLionel Sambuc 183*f4a2713aSLionel Sambuc<h3>Slower than Compilation</h3> 184*f4a2713aSLionel Sambuc 185*f4a2713aSLionel Sambuc<p>Operationally, using static analysis to 186*f4a2713aSLionel Sambucautomatically find deep program bugs is about trading CPU time for the hardening 187*f4a2713aSLionel Sambucof code. Because of the deep analysis performed by state-of-the-art static 188*f4a2713aSLionel Sambucanalysis tools, static analysis can be much slower than compilation.</p> 189*f4a2713aSLionel Sambuc 190*f4a2713aSLionel Sambuc<p>While the Clang Static Analyzer is being designed to be as fast and 191*f4a2713aSLionel Sambuclight-weight as possible, please do not expect it to be as fast as compiling a 192*f4a2713aSLionel Sambucprogram (even with optimizations enabled). Some of the algorithms needed to find 193*f4a2713aSLionel Sambucbugs require in the worst case exponential time.</p> 194*f4a2713aSLionel Sambuc 195*f4a2713aSLionel Sambuc<p>The Clang Static Analyzer runs in a reasonable amount of time by both 196*f4a2713aSLionel Sambucbounding the amount of checking work it will do as well as using clever 197*f4a2713aSLionel Sambucalgorithms to reduce the amount of work it must do to find bugs.</p> 198*f4a2713aSLionel Sambuc 199*f4a2713aSLionel Sambuc<h3>False Positives</h3> 200*f4a2713aSLionel Sambuc 201*f4a2713aSLionel Sambuc<p>Static analysis is not perfect. It can falsely flag bugs in a program where 202*f4a2713aSLionel Sambucthe code behaves correctly. Because some code checks require more analysis 203*f4a2713aSLionel Sambucprecision than others, the frequency of false positives can vary widely between 204*f4a2713aSLionel Sambucdifferent checks. Our long-term goal is to have the analyzer have a low false 205*f4a2713aSLionel Sambucpositive rate for most code on all checks.</p> 206*f4a2713aSLionel Sambuc 207*f4a2713aSLionel Sambuc<p>Please help us in this endeavor by <a href="filing_bugs.html">reporting false 208*f4a2713aSLionel Sambucpositives</a>. False positives cannot be addressed unless we know about 209*f4a2713aSLionel Sambucthem.</p> 210*f4a2713aSLionel Sambuc 211*f4a2713aSLionel Sambuc<h3>More Checks</h3> 212*f4a2713aSLionel Sambuc 213*f4a2713aSLionel Sambuc<p>Static analysis is not magic; a static analyzer can only find bugs that it 214*f4a2713aSLionel Sambuchas been specifically engineered to find. If there are specific kinds of bugs 215*f4a2713aSLionel Sambucyou would like the Clang Static Analyzer to find, please feel free to 216*f4a2713aSLionel Sambucfile <a href="filing_bugs.html">feature requests</a> or contribute your own 217*f4a2713aSLionel Sambucpatches.</p> 218*f4a2713aSLionel Sambuc 219*f4a2713aSLionel Sambuc</div> 220*f4a2713aSLionel Sambuc</div> 221*f4a2713aSLionel Sambuc</body> 222*f4a2713aSLionel Sambuc</html> 223*f4a2713aSLionel Sambuc 224