<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi, Mathieu...sorry for the delay. There's no reason why a new checker wouldn't be able to check new kinds of annotations, but the annotations it supports today are the same attributes provided by the Clang compiler. Now, we can always add attributes to the compiler, but that's not something we usually want to do lightly.</div><div><br></div><div>Anna, Ted, and I have kicked around the idea of a more generic 'analyzer_annotate' attribute, which could make one-off analyzer language extensions cheaper, but we didn't quite finish designing it. Does this sound like the sort of thing you're asking about? This would require modifying Clang's attribute parser to support this generic attribute and provide convenient access to its possible fields for any checkers.</div><div><br></div><div>(Meanwhile, we've hacked some things together using the existing string-only 'annotate' attribute; see IvarInvalidationChecker. You could use this to prototype your checker if you didn't want to work on the general attribute problem just yet.)</div><div><br></div><div>In this particular case, something else we've thought of is an attribute that stipulates that a function return value is always non-null, and another requiring that the result is checked. These also haven't been fully designed yet (are they inherited? do they piggyback on existing attributes like 'nonnull', or do they get their own syntax?).</div><div><br></div><div>Jordan</div><div><br></div><br><div><div>On May 6, 2013, at 19:20 , Mathieu Baudet <<a href="mailto:mathieubaudet@fb.com">mathieubaudet@fb.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Hi list,
<div><br>
</div>
<div>Is anyone in the position to offer some insight on the question (below) about possibly using Clang analyzer for more "contract-based" null-pointer analyses?</div>
<div>
<div><br>
</div>
<div>--</div>
<div>Mathieu</div>
<div><br>
</div>
<div>On May 2, 2013, at 5:43 PM, Mathieu Baudet <<a href="mailto:mathieubaudet@fb.com">mathieubaudet@fb.com</a>> wrote:
<div><br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>On a slightly different topic, has anyone ever considered using the core of clang-analyzer to bring more fine-grained annotations to life, in the spirit of Findbugs for Java?</div>
<div> <a href="http://findbugs.sourceforge.net/manual/annotations.html">http://findbugs.sourceforge.net/manual/annotations.html</a></div>
<div><br>
</div>
<div>From this page</div>
<div> <a href="http://clang-analyzer.llvm.org/annotations.html">http://clang-analyzer.llvm.org/annotations.html</a></div>
<div>I understand that we can already attach attributes to various syntactic elements (not sure exactly which ones yet, though).</div>
<div><br>
</div>
<div>Is there any reason to believe that this project would require more than just writing a new checker?</div>
<div><br>
</div>
<div>-- Mathieu</div>
<br>
<div>
<div>On May 2, 2013, at 1:33 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>Hi, Mathieu. You've run into one of the analyzer's haziest features: false positive suppression based on return values. To put it simply, if there's a null pointer dereference, and it turns out the null pointer came from an inlined function, we suppress
the warning.</div>
<div><br>
</div>
<div>Why? Well, for better or for worse the analyzer does not have perfect information. Consider an example like this:</div>
<div><br>
</div>
<div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>targetMap[targetName]->process(input);</div>
<br>
</div>
<div>Seems harmless, right? Well, what does the map's operator[] look like?</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>Target *getItem(StringRef name) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (map contains a target for name)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return it</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return NULL;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><br>
</div>
<div>Most likely, the analyzer doesn't have perfect knowledge about the contents of the map, so it assumes both branches can be taken—which is totally reasonable! However, the caller could very well have some extra knowledge: the targetName is checked at the
beginning of the program, and so the map lookup will never fail at this point.</div>
<div><br>
</div>
<div>Usually, the response to this sort of bug is to add an assertion, but in this case you wouldn't be able to do that without introducing a temporary variable and breaking apart the original expression.</div>
<div><br>
</div>
<div>When we first turned on C++ inlining, this sort of example resulting in hundreds of false posiitves on the LLVM code base. It did find some true positives, such as unchecked calls to dyn_cast, but in general it was just not compatible with the way people
write code. A lot of times, generic functions have to handle error cases that the caller
<i>knows</i> won't happen, but would find annoying or difficult to actually assert() about. We've found that a lot of these cases correspond to a null value being returned, which is
<i>entirely</i> a heuristic.</div>
<div><br>
</div>
<div>The false positive suppression heuristics can definitely be improved, but in general false negatives are better for the analyzer than false positives. The former reduces bugs caught and confidence in the tool, but the latter results in people turning off
a checker wholesale or not running the analyzer at all.</div>
<div><br>
</div>
<div>Anyway, thanks for the report, and if you come up with any "counter-suppression" ideas, please send them to the list!</div>
<div><br>
</div>
<div>Jordan</div>
<div><br>
</div>
<br>
<div>
<div>On May 1, 2013, at 22:16 , Mathieu Baudet <<a href="mailto:mathieubaudet@fb.com">mathieubaudet@fb.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">Hi,<br>
<br>
As I was testing NonNullParamChecker this afternoon, I ran into this troubling example:<br>
<br>
// --------- example 1 ------------<br>
void *getNull() {<br>
return 0;<br>
}<br>
<br>
void check(void *p) __attribute__(( nonnull ));<br>
void check(void *p) {<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
void *p = getNull();<br>
check(p);<br>
return 0;<br>
}<br>
// --------------------------------<br>
<br>
This code gives no warning on the versions of clang that I could test:<br>
- Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)<br>
- clang version 3.3 (trunk 180768)<br>
- clang version 3.3 (trunk 180907) (llvm/trunk 180768)<br>
<br>
To get an error one I have to replace p = getNull() by p = 0.<br>
<br>
First I was tempted to think it was just a limitation of the core analyzer, but<br>
1) I obtain an error with a similar example where the nonnull attribute is replaced by a division by zero (see example 2 at the end)<br>
<br>
2) I debugged the file NonNullParamChecker.cpp : I am very new to this codebase but it seems that a report is actually emitted (lines 119-139). Then it never shows up for some reason...<br>
<br>
Is this a bug? If not, how can we improve this checker?<br>
<br>
Thanks!<br>
--<br>
Mathieu<br>
<br>
<br>
// --------- example 2 -----------<br>
int getX() {<br>
return 0;<br>
}<br>
<br>
void check(int p) {<br>
1 / p;<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
int x = getX();<br>
check(x);<br>
return 0;<br>
}<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote></div><br></body></html>