<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 05:22:05 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>astrange - 2009-11-12 18:50:52</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>&amp;gt; So, gcc internals aren't as bad as I think, except for where they are? Funny.
&lt;br /&gt;
&lt;br /&gt;Just for completeness: there are three ends in a compiler, and the middle-end (platform-independent optimization) is the most important.</description><guid isPermaLink="true">d6b3db8674097bf3155f988062c2b587</guid><pubDate>Thu, 12 Nov 2009 18:50:52 GMT</pubDate></item><item><title>ceeAge - 2009-04-02 19:12:50</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>thx John McLaughlin, for pointing to the 'karppinen' tool. however, this won't be useful on PPC. it doesn't look like a UB build.</description><guid isPermaLink="true">c010ef01d53d965f502da6581d951a38</guid><pubDate>Thu, 02 Apr 2009 19:12:50 GMT</pubDate></item><item><title>mikeash - 2009-03-10 09:08:27</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>Wow, so Clang is really responsive to bug reports. Version 0.170 of the static analyzer, now available from the web site, fixes the nameC/kindC mixup with this code. Way cool.</description><guid isPermaLink="true">7a8d3ee22cfce422704586d739760ae4</guid><pubDate>Tue, 10 Mar 2009 09:08:27 GMT</pubDate></item><item><title>mikeash - 2009-03-10 02:15:29</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>&lt;b&gt;bork:&lt;/b&gt; What's your point? I don't believe anyone ever said that name is leaked.</description><guid isPermaLink="true">5af18cd7a363e4434d0168c9ebdad03b</guid><pubDate>Tue, 10 Mar 2009 02:15:29 GMT</pubDate></item><item><title>bork - 2009-03-10 01:34:20</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>I'm pretty sure that 'name' is returned as an autoreleased object, so it is not leaked.</description><guid isPermaLink="true">3e7649765b1700f93f813634da90e838</guid><pubDate>Tue, 10 Mar 2009 01:34:20 GMT</pubDate></item><item><title>foobaz - 2009-03-10 01:20:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>I never tried clang until this post inspired me.  I wasn't quite surprised and frightened, but I was very impressed with what it found, like rare memory leaks caused by early returns and me passing a BOOL when I should be passing an enum.  AnalysisTool is great, too.</description><guid isPermaLink="true">e2d427217807ae9f7e514a48b58e3e89</guid><pubDate>Tue, 10 Mar 2009 01:20:12 GMT</pubDate></item><item><title>mikeash - 2009-03-08 01:01:58</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt; And gcc internals may not be very modular but they certainly aren't as bad as you think. (well, except for the backend, anyway)&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;So, gcc internals aren't as bad as I think, except for where they are? Funny.</description><guid isPermaLink="true">0768659ca6a8c0911e769e7a363fc0db</guid><pubDate>Sun, 08 Mar 2009 01:01:58 GMT</pubDate></item><item><title>Sebastian Redl - 2009-03-07 18:56:43</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>The static analysis comes from a separate component in the Clang project, but it's not the same as the rest of the compiler.
&lt;br /&gt;Specifically, Clang consists of the following components:
&lt;br /&gt;Basic: Support code
&lt;br /&gt;Lex: Lexing and preprocessing
&lt;br /&gt;Parse: Parsing
&lt;br /&gt;AST: AST representation
&lt;br /&gt;Sema: Semantic analysis, builds the AST
&lt;br /&gt;Analyze: Static code analysis, the core logic of CSA
&lt;br /&gt;Rewrite: Code rewriting support
&lt;br /&gt;
&lt;br /&gt;CSA combines everything except Rewrite to form the tool, but the real analysis is done in libanalyze.
&lt;br /&gt;
&lt;br /&gt;Note, also, that CSA has two modes of running: flow-based analysis and path-based analysis. Flow-based is faster, but less accurate. It produces the false uninitialized warnings like GCC, which astrange mentioned. This is because it doesn't consider the possible paths through control structures. As such, it will give a false positive here:
&lt;br /&gt;
&lt;br /&gt;void f(int a)
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;int b;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;if (a &amp;gt; 0) b = 1;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;if (a &amp;gt; 5) printf("%d", b);
&lt;br /&gt;}
&lt;br /&gt;
&lt;br /&gt;Path-based tracks possible value ranges of variables and traces out every possible path through the function. That makes it a lot slower (runtime is exponential in the number of branches, in theory, though the component aggressively culls paths), but also more accurate. The path-based analysis recognizes that it's impossible to enter the second if if the first wasn't also entered, and will not warn about an uninitialized b.</description><guid isPermaLink="true">dbb69119b2da6d3515135501b79dc8ea</guid><pubDate>Sat, 07 Mar 2009 18:56:43 GMT</pubDate></item><item><title>astrange - 2009-03-07 17:47:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>I'm almost certain the static analysis comes from clang itself, not LLVM. Clang does lots of cheap bitvector dataflow inside the C frontend so it can provide warnings no matter what the optimization level is; these are just a kind of really thorough warning. (you'll notice the analyses still give false uninitialized warnings where gcc does, and can't see through function calls)
&lt;br /&gt;
&lt;br /&gt;And gcc internals may not be very modular but they certainly aren't as bad as you think. (well, except for the backend, anyway)</description><guid isPermaLink="true">b2bcc4ff4583d69d04373d342209899e</guid><pubDate>Sat, 07 Mar 2009 17:47:12 GMT</pubDate></item><item><title>mikeash - 2009-03-07 11:47:37</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>Yep, you're right, that's a bug with the static analyzer. I wrote the code with the expectation that one would be good and one would be a bug, and I never realized that the output was backwards!</description><guid isPermaLink="true">8c85666bbb94b6f263cc76081db8273b</guid><pubDate>Sat, 07 Mar 2009 11:47:37 GMT</pubDate></item><item><title>Vasi - 2009-03-07 11:05:28</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>Er, is it just me, or is it kindC[0] in the example that should be giving the null-dereference warning? You return if name is NULL, so nameC should always be a valid pointer.</description><guid isPermaLink="true">df96ef67b479d94a68a6b381bb949cd2</guid><pubDate>Sat, 07 Mar 2009 11:05:28 GMT</pubDate></item><item><title>John McLaughlin - 2009-03-07 08:07:56</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>Also see analysis tool for a nice front end.
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://www.karppinen.fi/analysistool/"&gt;http://www.karppinen.fi/analysistool/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;(It uses clang but adds additional checks)
&lt;br /&gt;
&lt;br /&gt;-john
&lt;br /&gt;</description><guid isPermaLink="true">d4528e4ab98d12ee05dec3e11aa31c47</guid><pubDate>Sat, 07 Mar 2009 08:07:56 GMT</pubDate></item><item><title>Jean-Daniel Dupas - 2009-03-07 07:38:49</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-03-06-using-the-clang-static-analyzer.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;I will now abbreviate as CSA even though everybody calls it "clang"&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;
&lt;br /&gt;
&lt;br /&gt;In fact, not everybody call it "clang", some people also use "as-yet-unnamed clang static analyzer" ;-)
&lt;br /&gt;
&lt;br /&gt;The clang community is looking for a better name than "scan-build", or CSA.
&lt;br /&gt;
&lt;br /&gt;This tool is young and miss some important features (like cross module analysis), but it is really useful.
&lt;br /&gt;
&lt;br /&gt;It even report things like missing release call in dealloc of synthesized properties, or check good usage of NSError** objects.
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><guid isPermaLink="true">53f511d25c9bcd10630a48cb0d9651b6</guid><pubDate>Sat, 07 Mar 2009 07:38:49 GMT</pubDate></item></channel></rss>
