1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <title>Clang Static Analyzer
</title>
6 <link type=
"text/css" rel=
"stylesheet" href=
"content.css">
7 <link type=
"text/css" rel=
"stylesheet" href=
"menu.css">
8 <script type=
"text/javascript" src=
"scripts/menu.js"></script>
9 <!-- Generated from: http://www.spiffycorners.com/index.php -->
11 <style type=
"text/css">
12 .spiffy{display:block
}
24 border-left:1px solid
#f6f8fc;
25 border-right:1px solid
#f6f8fc;
32 border-left:1px solid
#fdfdfe;
33 border-right:1px solid
#fdfdfe;
38 border-left:1px solid
#eef2fa;
39 border-right:1px solid
#eef2fa;}
41 border-left:1px solid
#f6f8fc;
42 border-right:1px solid
#f6f8fc}
44 border-left:1px solid
#f0f3fb;
45 border-right:1px solid
#f0f3fb}
50 margin:0px; padding:10px;
54 #left h2
{ margin:1px; padding-top:0px; }
55 #right { float:left
; margin-left:20px; margin-right:20px; padding:0px ;}
56 #right h2
{ padding:0px; margin:0px; }
57 #wrappedcontent { padding:15px;}
63 <!--#include virtual="menu.html.incl"-->
67 <table style=
"margin-top:0px" width=
"100%" border=
"0" cellpadding=
"0px" cellspacing=
"0">
70 <h1>Clang Static Analyzer
</h1>
72 <p>The Clang Static Analyzer is a source code analysis tool that finds bugs in
73 C, C++, and Objective-C programs.
</p>
75 <p>The analyzer is
100% open source and is part of the
<a href=
"https://clang.llvm.org">Clang
</a>
76 project. Like the rest of Clang, the analyzer is implemented as a C++ library
77 that can be used by other tools and applications.
</p>
79 <div style=
"padding:0; margin-top:10px; font-size: 90%">
81 <b class=
"spiffy1"><b></b></b>
82 <b class=
"spiffy2"><b></b></b>
83 <b class=
"spiffy3"></b>
84 <b class=
"spiffy4"></b>
85 <b class=
"spiffy5"></b></b>
86 <div class=
"spiffyfg">
87 <div style=
"padding:15px">
89 <p>To get started with the Clang Static Analyzer, visit the
90 <a href=
"https://releases.llvm.org/download.html">LLVM
91 releases page
</a> for download and installation instructions. The official
92 releases include both the analyzer and
<a href=
"scan-build.html">scan-build
</a>,
93 a command-line tool for running the analyzer on your codebase.
</p>
95 <p>If you're installing Clang from a different source, such as
96 a Linux package repository, then scan-build may be packaged
97 separately as an individual package, or as part of
98 a
"clang tools" package.
</p>
100 <p>If your IDE is using Clang, it may natively integrate the static analyzer.
101 On macOS, the easiest way to use the static analyzer is to invoke it
102 <a href=
"https://clang.llvm.org/docs/analyzer/user-docs/UsingWithXCode.html">directly
105 <p>Additionally, if you're using
<a href=
"https://clang.llvm.org/extra/clang-tidy/">clang-tidy
</a>,
106 you can naturally make the static analyzer run alongside clang-tidy
107 by enabling the
<a href=
"https://clang.llvm.org/extra/clang-tidy/checks/list.html">clang-analyzer
</a>
112 <b class=
"spiffy5"></b>
113 <b class=
"spiffy4"></b>
114 <b class=
"spiffy3"></b>
115 <b class=
"spiffy2"><b></b></b>
116 <b class=
"spiffy1"><b></b></b></b>
120 </td><td style=
"padding-left:10px">
121 <a href=
"images/analyzer_xcode.png"><img src=
"images/analyzer_xcode.png" width=
"450" alt=
"analyzer in xcode"></a>
122 <div style=
"text-align:center"><b>Viewing static analyzer results in Xcode
</b></div>
123 <a href=
"images/analyzer_html.png"><img src=
"images/analyzer_html.png" width=
"450" alt=
"analyzer in browser"></a>
124 <div style=
"text-align:center"><b>Viewing static analyzer results in a web browser
</b></div>
127 <h2 id=
"StaticAnalysis">What is Static Analysis?
</h2>
129 <p>The term
"static analysis" is conflated, but here we use it to mean
130 a collection of algorithms and techniques used to analyze source code in order
131 to automatically find bugs. The idea is similar in spirit to compiler warnings
132 (which can be useful for finding coding errors) but to take that idea a step
133 further and find bugs that are traditionally found using run-time debugging
134 techniques such as testing.
</p>
136 <p>Static analysis bug-finding tools have evolved over the last several decades
137 from basic syntactic checkers to those that find deep bugs by reasoning about
138 the semantics of code. The goal of the Clang Static Analyzer is to provide a
139 industrial-quality static analysis framework for analyzing C, C++, and
140 Objective-C programs that is freely available, extensible, and has a high quality of implementation.
</p>
142 <h3 id=
"Clang">Part of Clang and LLVM
</h3>
144 <p>As its name implies, the Clang Static Analyzer is built on top of
<a
145 href=
"https://clang.llvm.org">Clang
</a> and
<a href=
"https://llvm.org">LLVM
</a>.
146 Strictly speaking, the analyzer is part of Clang, as Clang consists of a set of
147 reusable C++ libraries for building powerful source-level tools. The static
148 analysis engine used by the Clang Static Analyzer is a Clang library, and has
149 the capability to be reused in different contexts and by different clients.
</p>
151 <h2>Important Points to Consider
</h2>
153 <p>While we believe that the static analyzer is already very useful for finding
154 bugs, we ask you to bear in mind a few points when using it.
</p>
156 <h3>Work-in-Progress
</h3>
158 <p>The analyzer is a continuous work-in-progress. There are many planned
159 enhancements to improve both the precision and scope of its analysis algorithms
160 as well as the kinds of bugs it will find. While there are fundamental
161 limitations to what static analysis can do, we have a long way to go before
162 hitting that wall.
</p>
164 <h3>Slower than Compilation
</h3>
166 <p>Operationally, using static analysis to
167 automatically find deep program bugs is about trading CPU time for the hardening
168 of code. Because of the deep analysis performed by state-of-the-art static
169 analysis tools, static analysis can be much slower than compilation.
</p>
171 <p>While the Clang Static Analyzer is being designed to be as fast and
172 light-weight as possible, please do not expect it to be as fast as compiling a
173 program (even with optimizations enabled). Some of the algorithms needed to find
174 bugs require in the worst case exponential time.
</p>
176 <p>The Clang Static Analyzer runs in a reasonable amount of time by both
177 bounding the amount of checking work it will do as well as using clever
178 algorithms to reduce the amount of work it must do to find bugs.
</p>
180 <h3>False Positives
</h3>
182 <p>Static analysis is not perfect. It can falsely flag bugs in a program where
183 the code behaves correctly. Because some code checks require more analysis
184 precision than others, the frequency of false positives can vary widely between
185 different checks. Our long-term goal is to have the analyzer have a low false
186 positive rate for most code on all checks.
</p>
188 <p>Please help us in this endeavor by
<a href=
"filing_bugs.html">reporting false
189 positives
</a>. False positives cannot be addressed unless we know about
194 <p>Static analysis is not magic; a static analyzer can only find bugs that it
195 has been specifically engineered to find. If there are specific kinds of bugs
196 you would like the Clang Static Analyzer to find, please feel free to
197 file
<a href=
"filing_bugs.html">feature requests
</a> or contribute your own