<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1" style="word-wrap:break-word">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello!<br>
<br>
> I think Richard was asking about false positives/true positives ratio and I do not see any false positives in the list below. It looks like all the reports you found are valid. Did you run this check on large C++ codebases?<br>
<br>
I reported all positives I could see.<br>
<br>
I admit it would be good to test it more.<br>
<br>
I have not tried it on any SFINAE projects AFAIK. It seems SFINAE uses sizeof on function calls and templates? Since this check warns for BinaryOperator, maybe it doesn't report about SFINAE patterns?<br>
<br>
Best regards,<br>
Daniel Marjamäki<br>
<div><br>
<br>
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt">..................................................................................................................</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:black; font-size:8pt">Daniel Marjamäki
</span><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt">Senior Engineer</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8.5pt" lang="EN-US">Evidente ES East</span><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-US"> AB<span> 
</span>Warfvinges väg 34<span>  </span>SE-112 51 Stockholm<span>  </span>Sweden </span>
</p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-US"></span> </p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-GB">Mobile</span><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-GB">:<span>                
</span>+46 (0)709 12 42 62</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-GB"></span><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-GB">E-mail:<span>   
</span><span>             <a href="mailto:Daniel.Marjamaki@evidente.se" tabindex="0">
Daniel.Marjamaki</a></span><a href="mailto:Daniel.Marjamaki@evidente.se" tabindex="0">@evidente.se</a><span>     
</span><span>                 </span></span></p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; color:gray; font-size:8pt" lang="EN-GB"></span> </p>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:'Arial','sans-serif'; font-size:8pt" lang="EN-GB">www.evidente.se</span></p>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF287709"><font color="#000000" face="Tahoma" size="2"><b>Från:</b> Anna Zaks [ganna@apple.com]<br>
<b>Skickat:</b> den 23 oktober 2013 17:35<br>
<b>Till:</b> Daniel Marjamäki<br>
<b>Cc:</b> Ted Kremenek; Anders Rönnholm; Richard Smith; cfe-commits@cs.uiuc.edu; Jordan Rose<br>
<b>Ämne:</b> Re: [PATCH] [StaticAnalyzer] New checker Sizeof on expression<br>
</font><br>
</div>
<div></div>
<div>Daniel,
<div><br>
</div>
<div>I think Richard was asking about false positives/true positives ratio and I do not see any false positives in the list below. It looks like all the reports you found are valid. Did you run this check on large C++ codebases?</div>
<div><br>
</div>
<div>As far as I can tell there are two outstanding issues:</div>
<div> - Addressing these questions from Richard:</div>
<div>
<blockquote type="cite">
<div style="word-wrap:break-word">
<div style="direction:ltr; font-family:Tahoma; font-size:10pt">
<div style="font-family:'Times New Roman'; font-size:16px">
<blockquote type="cite">
<div style="font-family:Helvetica; font-size:12px; word-wrap:break-word">
<blockquote type="cite">
<div style="word-wrap:break-word">
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div>sizeof(expression) is a common idiom in SFINAE contexts. Is that covered here?</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
Richard, can you provide examples?</div>
<div>
<blockquote type="cite">
<div style="word-wrap:break-word">
<div style="direction:ltr; font-family:Tahoma; font-size:10pt">
<div style="font-family:'Times New Roman'; font-size:16px">
<blockquote type="cite">
<div style="font-family:Helvetica; font-size:12px; word-wrap:break-word">
<blockquote type="cite">
<div style="word-wrap:break-word">
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div><br>
</div>
<div>sizeof(sizeof(int)) is a "traditional" way to get sizeof(size_t). Why should we warn on that?</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<div>(I personally think that if this check goes into the analyzer, it's fine to warn in the second case.)</div>
<div><br>
</div>
<div>
<div> - Where this check should go (compiler or the analyzer)?</div>
</div>
<div>I think that if you can address the questions above, this check could go into the compiler.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Anna.</div>
<div><br>
<div>
<div>On Oct 14, 2013, at 12:43 PM, Daniel Marjamäki <<a href="mailto:Daniel.Marjamaki@evidente.se" target="_blank">Daniel.Marjamaki@evidente.se</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; word-wrap:break-word">
<div style="direction:ltr; font-family:Tahoma; font-size:10pt"><br>
Hello!<br>
<br>
As I understood it.. you wanted to know what the hit ratio is. I have investigated the hit ratio on a number of packages in debian. Below is the negative and positives I've found. I provide the package URLs so you can look for yourself..<br>
<br>
I will continue investigating and let you know if I see any false positives...<br>
<br>
<br>
NEGATIVE (macro)<br>
package:<span class="Apple-converted-space"> </span><a href="http://ftp.us.debian.org/debian/pool/main/a/agedu/agedu_9723.orig.tar.gz" target="_blank">http://ftp.us.debian.org/debian/pool/main/a/agedu/agedu_9723.orig.tar.gz</a><br>
<br>
#define sresize(array, number, type) \<br>
    ( (void)sizeof((array)-(type *)0), \<br>
      (type *) srealloc ((array), (number) * sizeof (type)) )<br>
<br>
We don't warn about this since it's in a macro. However it is interesting:<br>
    sizeof((array)-(type *)0)<br>
It seems to be written this way by intention. To get sizeof(ptrdiff_t)? Maybe sizeof(ptr-ptr) should be ok.<br>
<br>
<br>
<br>
POSITIVE<br>
package:<span class="Apple-converted-space"> </span><a href="http://ftp.us.debian.org/debian/pool/main/a/argus-client_3.0.0.orig.tar.gz" target="_blank">http://ftp.us.debian.org/debian/pool/main/a/argus-client_3.0.0.orig.tar.gz</a><br>
<br>
file: argus-clients-3.0.0/radump/print-ldp.c<br>
line: 607<br>
            print_unknown_data(tptr+sizeof(sizeof(struct ldp_msg_header)),"\n\t  ",<br>
                               msg_len);<br>
<br>
file: argus-clients-3.0.0/radump/print-lmp.c<br>
line: 878<br>
            print_unknown_data(tptr+sizeof(sizeof(struct lmp_object_header)),"\n\t    ",<br>
                               lmp_obj_len-sizeof(struct lmp_object_header));<br>
<br>
Not sure if these are intended to be sizeof(size_t) or sizeof(struct lmp_object_header) but I guess the latter.<br>
<br>
<br>
<br>
POSITIVE<br>
package:<span class="Apple-converted-space"> </span><a href="http://ftp.us.debian.org/debian/pool/main/b/babel/babel_1.4.0.dfsg.orig.tar.gz" target="_blank">http://ftp.us.debian.org/debian/pool/main/b/babel/babel_1.4.0.dfsg.orig.tar.gz</a><br>
file: babel-1.4.0.dfsg/regression/output/libC/synch_RegOut_Impl.c<br>
<br>
332:    if ((res < 0) || (res > sizeof(s_result_strings)/sizeof(sizeof(char *)))) {<br>
<br>
This "sizeof(sizeof(char *))" should be "sizeof(char*)" since s_result_strings is a array of char * pointers<br>
<br>
<br>
<br>
POSITIVE<br>
package:<span class="Apple-converted-space"> </span><a href="http://ftp.us.debian.org/debian/pool/main/b/bird/bird_1.3.7.orig.tar.gz" target="_blank">http://ftp.us.debian.org/debian/pool/main/b/bird/bird_1.3.7.orig.tar.gz</a><br>
file: bird-1.3.7/lib/mempool.c<br>
<br>
253:<br>
  return ALLOC_OVERHEAD + sizeof(struct linpool) +<br>
    cnt * (ALLOC_OVERHEAD + sizeof(sizeof(struct lp_chunk))) +<br>
    m->total + m->total_large;<br>
<br>
Not sure if this is intended to be sizeof(size_t) or sizeof(struct lp_chunk) but I guess the latter.<br>
<br>
<br>
POSITIVE:<br>
package:<span class="Apple-converted-space"> </span><a href="http://ftp.us.debian.org/debian/pool/main/b/blender/blender_2.49.2~dfsg.orig.tar.gz" target="_blank">http://ftp.us.debian.org/debian/pool/main/b/blender/blender_2.49.2~dfsg.orig.tar.gz</a><br>
file: blender-2.49b.orig/source/blender/blenloader/intern/readfile.c<br>
6987:    if(0==strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name+2))) {<br>
6991:    if(0==strncmp(ima->id.name+2, "Render Result", sizeof(ima->id.name+2))) {<br>
<br>
These are bad, ima->id.name is an array, it should probably be changed to:<br>
    if(0==strncmp(ima->id.name+2, "Viewer Node", sizeof(ima->id.name) - 2)) {<br>
<br>
<br>
Best regards,<br>
Daniel Marjamäki<br>
<div><br>
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt">..................................................................................................................</span></div>
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; font-size:8pt">Daniel Marjamäki<span class="Apple-converted-space"> </span></span><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt">Senior Engineer</span></div>
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8.5pt" lang="EN-US">Evidente ES East</span><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-US"><span class="Apple-converted-space"> </span>AB<span> <span class="Apple-converted-space"> </span></span>Warfvinges
 väg 34<span> <span class="Apple-converted-space"> </span></span>SE-112 51 Stockholm<span> <span class="Apple-converted-space"> </span></span>Sweden</span></div>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-US"></span> </p>
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-GB">Mobile</span><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-GB">:<span>                <span class="Apple-converted-space"> </span></span>+46
 (0)709 12 42 62</span></div>
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-GB"></span><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-GB">E-mail:<span>   <span class="Apple-converted-space"> </span></span><span>            <span class="Apple-converted-space"> </span><a href="mailto:Daniel.Marjamaki@evidente.se" tabindex="0" target="_blank">Daniel.Marjamaki</a></span><a href="mailto:Daniel.Marjamaki@evidente.se" tabindex="0" target="_blank">@evidente.se</a><span>     <span class="Apple-converted-space"> </span></span><span>                </span></span></div>
<p class="MsoNormal" style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; color:gray; font-size:8pt" lang="EN-GB"></span> </p>
<div style="margin:0cm 0cm 0pt"><span style="font-family:Arial,sans-serif; font-size:8pt" lang="EN-GB"><a href="http://www.evidente.se/" target="_blank">www.evidente.se</a></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="font-family:'Times New Roman'; font-size:16px">
<hr tabindex="-1">
<div id="divRpF633884" style="direction:ltr"><font face="Tahoma" size="2"><b>Från:</b><span class="Apple-converted-space"> </span><a href="mailto:cfe-commits-bounces@cs.uiuc.edu" target="_blank">cfe-commits-bounces@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>[<a href="mailto:cfe-commits-bounces@cs.uiuc.edu" target="_blank">cfe-commits-bounces@cs.uiuc.edu</a>]
 för Anna Zaks [<a href="mailto:ganna@apple.com" target="_blank">ganna@apple.com</a>]<br>
<b>Skickat:</b><span class="Apple-converted-space"> </span>den 8 oktober 2013 18:18<br>
<b>Till:</b><span class="Apple-converted-space"> </span>Ted Kremenek<br>
<b>Cc:</b><span class="Apple-converted-space"> </span>Anders Rönnholm; Richard Smith;
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<b>Ämne:</b><span class="Apple-converted-space"> </span>Re: [PATCH] [StaticAnalyzer] New checker Sizeof on expression<br>
</font><br>
</div>
<div></div>
<div><br>
<div>
<div>On Oct 7, 2013, at 10:05 PM, Ted Kremenek <<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; word-wrap:break-word">
On Oct 7, 2013, at 6:05 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>> wrote:<br>
<div><br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="word-wrap:break-word"><br>
<div>
<div>On Oct 7, 2013, at 13:58, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div dir="ltr">On Mon, Oct 7, 2013 at 9:55 AM, Jordan Rose<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br>
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-color:rgb(204,204,204); border-left-style:solid; padding-left:1ex">
<div style="word-wrap:break-word">I'm fine with this staying in the analyzer for now, unless David, Richard, or Eli feel it should be a warning right away.</div>
</blockquote>
<div><br>
</div>
<div>Do we have evidence that we want this? Does it catch bugs? If so, what do they look like? It seems like this would trigger on legitimate code; how does a user suppress the warning in that case, and does that suppression make their code clearer?<br>
</div>
<div><br>
</div>
<div>What is the false/true positive ratio for bug finding here?</div>
<div><br>
</div>
<div>sizeof(expression) is a common idiom in SFINAE contexts. Is that covered here?</div>
<div><br>
</div>
<div>sizeof(sizeof(int)) is a "traditional" way to get sizeof(size_t). Why should we warn on that?</div>
<div><br>
</div>
<div>And more as a general question than something specific to this patch: Is there a region in the space of false positive ratios where we think a syntactic warning should go into the static analyzer? If so, why? And what is that region? I would have thought
 that the static analyzer, like the clang warnings, would be aimed at (eventually) having a false positive ratio of near zero. If so, then should we ever put a warning in the static analyzer if it doesn't require the static analyzer's technology (or have a
 high runtime cost)?<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>On this last (and bringing in Ted and Anna):</div>
<div><br>
</div>
<div>I think the main difference between compiler warnings and syntactic analyzer checks is that we try very hard to turn new compiler warnings on by default. A second-order effect of this is that we generally avoid style warnings. The analyzer can be a bit
 looser about this, though: because people<span class="Apple-converted-space"> </span><i>know</i> the analyzer is stricter and more in-depth, I think they might also accept that a particular check doesn't fit their project.</div>
<div><br>
</div>
<div>On the other hand, we still haven't gotten around to designing a proper bug tracking and/or manual suppression system, so that's one advantage of compiler warnings. And as you say, checks without a high runtime cost don't really have a<span class="Apple-converted-space"> </span><i>technical</i> reason
 to be in the analyzer.</div>
</div>
</blockquote>
<br>
</div>
<div>Richard’s point is correct that we want the static analyzer to also have a high signal-to-noise ratio.  Otherwise it is a useless tool.  I’m also not a fan of having the analyzer having a bunch of “junk” checkers that aren’t on by default, but if a checker,
 when it is enabled, is HIGHLY useful to some set of people (e.g., security experts who are more tolerant of false positive rates if they want to do an aggressive code audit)  I think the analyzer is a reasonable place to put them, given the current warning
 policy in Clang where we want the warnings there to be generally useful to everybody.</div>
<div><br>
</div>
<div>To put it in more context, in the beginning the guiding principal of what goes in the static analyzer was:</div>
<div><br>
</div>
<div>(a) The warning is very expensive to compute.</div>
<div><br>
</div>
<div> OR</div>
<div><br>
</div>
<div>(b) The warning is very domain-specific.  For example, an API such as CFNumberCreate() on OS X has some interesting API invariants, but we generally should not be hacking those API-specific warnings into the compiler.  Exceptions exist of course, e.g.,
 printf checking, but often the are grounded when such APIs are fairly standard (e.g., in the C standard itself) or the checking is based on some annotation like __attribute__((format)) where the compiler doesn’t know anything about a specific function itself,
 just the annotation.</div>
<div><br>
</div>
<div>Style warnings can sometimes fall into (a) (in which case not putting them in the compiler makes obvious sense), but one could argue that they are more the flavor of (b) then a traditional compiler warning.  As I mentioned earlier, the static analyzer
 can be home to some highly specialized checkers that may not be generally useful for everybody but when enabled are very useful to certain people.  Style warnings often fit in this category of warnings.</div>
<div><br>
</div>
<div>A related problem is that we don’t have an ontology for style warnings in clang (the compiler).  Should they really be lumped into the same group of all other compiler warnings?  What about their behavior with -Werror?  -Weverything?  Style warnings really
 are about personal style, and users can be highly polarized about them.  For example, it would be highly useful for Clang to have a -W80-columns or -Wspaces-instead-of-tabs (not a serious proposal).  Both would be cheap to compute, would obviously benefit
 LLVM developers, but they wouldn’t work for everybody, or even the majority of software developers.  Where should they go?  The compiler?  The static analyzer?  Both have discoverability and usability concerns in either location.  I’d argue that these two
 warnings would be better suited in the compiler because (when the user wants them) they’d get run all the time, but having these warnings counteracts the general guiding principal that compiler warnings should generally be useful to most people, or clear categories
 of people (e.g, library authors), but not specific groups of people (e.g., LLVM developers).</div>
<div><br>
</div>
<div>This is not a thought out proposal, but I would not be opposed to a new category of warnings, say -Wstyle, and have all style warnings under -Wstyle, perhaps named “-Wstyle-80-columns” or “-Wstyle-spaces-instead-of-tabs”.  None of these warnings would
 be on by default.  If we want these kind of warnings in the compiler, I think these kind of warnings are worth calling out as being something “different” that people shouldn’t get hung up about if they don’t think the warning applies to them.  Also, having
 them in a special category of them own allows institutions to set broad warning polices such as “-Werror -Wno-error=style” where they want regular warnings to be treated as error, but not style warnings, etc.</div>
</div>
</blockquote>
</div>
<div><br>
</div>
I agree with Ted. Currently, there is no good way of adding style and highly specialized warnings to clang; given the behavior of Werror and Weverything. For example, we encourage users to learn about new generic warnings by turning on Weverything, so the specialized
 warnings should not be included there. </div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>