| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| "http://www.w3.org/TR/html4/strict.dtd"> |
| <html> |
| <head> |
| <title>Clang Static Analyzer</title> |
| <link type="text/css" rel="stylesheet" href="content.css"> |
| <link type="text/css" rel="stylesheet" href="menu.css"> |
| <script type="text/javascript" src="scripts/menu.js"></script> |
| <!-- Generated from: http://www.spiffycorners.com/index.php --> |
| |
| <style type="text/css"> |
| .spiffy{display:block} |
| .spiffy *{ |
| display:block; |
| height:1px; |
| overflow:hidden; |
| font-size:.01em; |
| background:#EBF0FA} |
| .spiffy1{ |
| margin-left:3px; |
| margin-right:3px; |
| padding-left:1px; |
| padding-right:1px; |
| border-left:1px solid #f6f8fc; |
| border-right:1px solid #f6f8fc; |
| background:#f0f3fb} |
| .spiffy2{ |
| margin-left:1px; |
| margin-right:1px; |
| padding-right:1px; |
| padding-left:1px; |
| border-left:1px solid #fdfdfe; |
| border-right:1px solid #fdfdfe; |
| background:#eef2fa} |
| .spiffy3{ |
| margin-left:1px; |
| margin-right:1px; |
| border-left:1px solid #eef2fa; |
| border-right:1px solid #eef2fa;} |
| .spiffy4{ |
| border-left:1px solid #f6f8fc; |
| border-right:1px solid #f6f8fc} |
| .spiffy5{ |
| border-left:1px solid #f0f3fb; |
| border-right:1px solid #f0f3fb} |
| .spiffyfg{ |
| background:#EBF0FA} |
| |
| .spiffyfg h2 { |
| margin:0px; padding:10px; |
| } |
| |
| #left { float:left; } |
| #left h2 { margin:1px; padding-top:0px; } |
| #right { float:left; margin-left:20px; margin-right:20px; padding:0px ;} |
| #right h2 { padding:0px; margin:0px; } |
| #wrappedcontent { padding:15px;} |
| </style> |
| </head> |
| <body> |
| |
| <div id="page"> |
| <!--#include virtual="menu.html.incl"--> |
| <div id="content"> |
| |
| |
| <table style="margin-top:0px" width="100%" border="0" cellpadding="0px" cellspacing="0"> |
| <tr><td> |
| |
| <h1>Clang Static Analyzer</h1> |
| |
| <p>The Clang Static Analyzer is a source code analysis tool that finds bugs in |
| C, C++, and Objective-C programs.</p> |
| |
| <p>The analyzer is 100% open source and is part of the <a href="https://clang.llvm.org">Clang</a> |
| project. Like the rest of Clang, the analyzer is implemented as a C++ library |
| that can be used by other tools and applications.</p> |
| |
| <div style="padding:0; margin-top:10px; font-size: 90%"> |
| <b class="spiffy"> |
| <b class="spiffy1"><b></b></b> |
| <b class="spiffy2"><b></b></b> |
| <b class="spiffy3"></b> |
| <b class="spiffy4"></b> |
| <b class="spiffy5"></b></b> |
| <div class="spiffyfg"> |
| <div style="padding:15px"> |
| |
| <p>To get started with the Clang Static Analyzer, visit the |
| <a href="https://releases.llvm.org/download.html">LLVM |
| releases page</a> for download and installation instructions. The official |
| releases include both the analyzer and <a href="scan-build.html">scan-build</a>, |
| a command-line tool for running the analyzer on your codebase.</p> |
| |
| <p>If you're installing Clang from a different source, such as |
| a Linux package repository, then scan-build may be packaged |
| separately as an individual package, or as part of |
| a "clang tools" package.</p> |
| |
| <p>If your IDE is using Clang, it may natively integrate the static analyzer. |
| On macOS, the easiest way to use the static analyzer is to invoke it |
| <a href="https://clang.llvm.org/docs/analyzer/user-docs/UsingWithXCode.html">directly |
| from Xcode</a>.</p> |
| |
| <p>Additionally, if you're using <a href="https://clang.llvm.org/extra/clang-tidy/">clang-tidy</a>, |
| you can naturally make the static analyzer run alongside clang-tidy |
| by enabling the <a href="https://clang.llvm.org/extra/clang-tidy/checks/list.html">clang-analyzer</a> |
| checks.</p> |
| </div> |
| </div> |
| <b class="spiffy"> |
| <b class="spiffy5"></b> |
| <b class="spiffy4"></b> |
| <b class="spiffy3"></b> |
| <b class="spiffy2"><b></b></b> |
| <b class="spiffy1"><b></b></b></b> |
| </div> |
| |
| |
| </td><td style="padding-left:10px"> |
| <a href="images/analyzer_xcode.png"><img src="images/analyzer_xcode.png" width="450" alt="analyzer in xcode"></a> |
| <div style="text-align:center"><b>Viewing static analyzer results in Xcode</b></div> |
| <a href="images/analyzer_html.png"><img src="images/analyzer_html.png" width="450" alt="analyzer in browser"></a> |
| <div style="text-align:center"><b>Viewing static analyzer results in a web browser</b></div> |
| </td></tr></table> |
| |
| <h2 id="StaticAnalysis">What is Static Analysis?</h2> |
| |
| <p>The term "static analysis" is conflated, but here we use it to mean |
| a collection of algorithms and techniques used to analyze source code in order |
| to automatically find bugs. The idea is similar in spirit to compiler warnings |
| (which can be useful for finding coding errors) but to take that idea a step |
| further and find bugs that are traditionally found using run-time debugging |
| techniques such as testing.</p> |
| |
| <p>Static analysis bug-finding tools have evolved over the last several decades |
| from basic syntactic checkers to those that find deep bugs by reasoning about |
| the semantics of code. The goal of the Clang Static Analyzer is to provide a |
| industrial-quality static analysis framework for analyzing C, C++, and |
| Objective-C programs that is freely available, extensible, and has a high quality of implementation.</p> |
| |
| <h3 id="Clang">Part of Clang and LLVM</h3> |
| |
| <p>As its name implies, the Clang Static Analyzer is built on top of <a |
| href="https://clang.llvm.org">Clang</a> and <a href="https://llvm.org">LLVM</a>. |
| Strictly speaking, the analyzer is part of Clang, as Clang consists of a set of |
| reusable C++ libraries for building powerful source-level tools. The static |
| analysis engine used by the Clang Static Analyzer is a Clang library, and has |
| the capability to be reused in different contexts and by different clients.</p> |
| |
| <h2>Important Points to Consider</h2> |
| |
| <p>While we believe that the static analyzer is already very useful for finding |
| bugs, we ask you to bear in mind a few points when using it.</p> |
| |
| <h3>Work-in-Progress</h3> |
| |
| <p>The analyzer is a continuous work-in-progress. There are many planned |
| enhancements to improve both the precision and scope of its analysis algorithms |
| as well as the kinds of bugs it will find. While there are fundamental |
| limitations to what static analysis can do, we have a long way to go before |
| hitting that wall.</p> |
| |
| <h3>Slower than Compilation</h3> |
| |
| <p>Operationally, using static analysis to |
| automatically find deep program bugs is about trading CPU time for the hardening |
| of code. Because of the deep analysis performed by state-of-the-art static |
| analysis tools, static analysis can be much slower than compilation.</p> |
| |
| <p>While the Clang Static Analyzer is being designed to be as fast and |
| light-weight as possible, please do not expect it to be as fast as compiling a |
| program (even with optimizations enabled). Some of the algorithms needed to find |
| bugs require in the worst case exponential time.</p> |
| |
| <p>The Clang Static Analyzer runs in a reasonable amount of time by both |
| bounding the amount of checking work it will do as well as using clever |
| algorithms to reduce the amount of work it must do to find bugs.</p> |
| |
| <h3>False Positives</h3> |
| |
| <p>Static analysis is not perfect. It can falsely flag bugs in a program where |
| the code behaves correctly. Because some code checks require more analysis |
| precision than others, the frequency of false positives can vary widely between |
| different checks. Our long-term goal is to have the analyzer have a low false |
| positive rate for most code on all checks.</p> |
| |
| <p>Please help us in this endeavor by <a href="filing_bugs.html">reporting false |
| positives</a>. False positives cannot be addressed unless we know about |
| them.</p> |
| |
| <h3>More Checks</h3> |
| |
| <p>Static analysis is not magic; a static analyzer can only find bugs that it |
| has been specifically engineered to find. If there are specific kinds of bugs |
| you would like the Clang Static Analyzer to find, please feel free to |
| file <a href="filing_bugs.html">feature requests</a> or contribute your own |
| patches.</p> |
| |
| </div> |
| </div> |
| </body> |
| </html> |