<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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;"><br>
<br>
Hi Jordan, good points. <br>
<br>
I've attached our current testfile that specifies wanted behaviour (regarding stack/heap etc.)<br>
<br>
Regarding "parameterize CallAndMessageChecker the same way as CheckSecuritySyntaxOnly.", I assume you would like to be able to turn on/off the new "check if const pointer arguments are uninitialized" functionality from the command line.
<br>
<br>
i.e. <br>
<br>
// only check if arguments are uninitialized (the old functionality only)<br>
clang -cc1 -analyze -analyzer-checker=core.callandmessage uninit-const.cpp<br>
<br>
// with extended functionality, i.e. "check if const pointer arguments are uninitialized" (also performs the old check).<br>
clang -cc1 -analyze -analyzer-checker=alpha.core.CallAndMessageUnInitRefArgChecker uninit-const.cpp<br>
<br>
/Per<br>
<br>
<br>
<div>
<div style="font-size:13px; font-family:Tahoma">
<p class="MsoNormal"><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:gray" lang="EN-US">.......................................................................................................................</span><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:black" lang="EN-US"><br>
Per Viberg </span><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:gray" lang="EN-US">Senior Engineer</span><span style="font-size:8.5pt; font-family:'Arial','sans-serif'; color:gray" lang="EN-US"><br>
Evidente ES East</span><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:gray" lang="EN-US"> AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden
</span><span style="font-size:10pt; font-family:'Tahoma','sans-serif'; color:black" lang="EN-US"></span></p>
<p class="MsoNormal"><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:gray" lang="EN-GB">Phone:    +46 (0)8 402 79 00<br>
Mobile:    +46 (0)70 912 42 52<br>
E-mail:     <a href="mailto:Per.Viberg@evidente.se" target="_blank"><font color="#0000ff">Per.Viberg@evidente.se</font></a>
</span><span style="font-size:8pt; font-family:'Arial','sans-serif'; color:black" lang="EN-GB"><br>
<br>
<a href="http://www.evidente.se" target="_blank"><font color="#0000ff">www.evidente.se</font></a></span></p>
<p class="MsoNormal"><span style="font-size:6pt; font-family:'Arial','sans-serif'" lang="EN-GB">This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in
 any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.</span></p>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF791178"><font color="#000000" face="Tahoma" size="2"><b>Från:</b> Jordan Rose [jordan_rose@apple.com]<br>
<b>Skickat:</b> den 20 februari 2014 05:21<br>
<b>Till:</b> Per Viberg<br>
<b>Cc:</b> "Clang Dev ‎[cfe-dev@cs.uiuc.edu]‎"<br>
<b>Ämne:</b> Re: [cfe-dev] Design draft: improving detection of uninitialized arguments (the CallAndMessageChecker)<br>
</font><br>
</div>
<div></div>
<div>
<div>This seems sensible to me. I am worried about one source of false positives: functions that take a pointer value solely for the purpose of using the pointer as an ID. However, this will never happen with stack variables, and static variables are always
 initialized, so it's only heap variables where this could be a problem. We could choose to special-case that or not.</div>
<div><br>
</div>
<div>Checking "const T&" parameters as well as "const T*" makes sense to me.</div>
<div><br>
</div>
<div>Please use SVal::getAsRegion instead of getAs<loc::MemRegionVal>. In almost all cases this makes no difference today, but the latter is at least easier to read and declares intent a little better, even though it will unnecessarily check for LocAsInteger
 values as well.</div>
<div><br>
</div>
<div>And finally, since this is a new set of checks with potential new false positives, please make a new entry in Checkers.td for it, and parameterize CallAndMessageChecker the same way as CheckSecuritySyntaxOnly.</div>
<div><br>
</div>
<div>This could be a very useful checker. Thank you for working on it!</div>
<div>Jordan</div>
<div><br>
</div>
<br>
<div>
<div>On Feb 19, 2014, at 0:58 , Per Viberg <<a href="mailto:Per.Viberg@evidente.se" target="_blank">Per.Viberg@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">
<div style="direction:ltr; font-family:Tahoma; font-size:10pt">Hi,<br>
<div><br>
Here is a proposed design draft to implement an extension of the check that warns for uninitialized arguments.<br>
Any objections/opinions on this solution?.<span class="Apple-converted-space"> </span><br>
<br>
Primarily looking for comments on: interfaces I plan to use and if it's correct to put the change in CallAndMessageChecker::checkPreCall etc.<br>
<br>
The new feature is to find arguments that are pointers to uninitialized variables, i.e. detect this:<br>
<b><font face="Courier New"><br>
void doStuff(const int *p);<br>
void f(void);<br>
<br>
void f(void) {<br>
      int x;<br>
      doStuff(&x);  // ← warning<span class="Apple-converted-space"> </span></font></b><b><font face="Courier New">"Function call argument is a pointer to uninitialized value"<span class="Apple-converted-space"> </span><br>
}</font></b><br>
<br>
I propose this design:<br>
<br>
1. Extend the CallAndMessageChecker::checkPreCall to analyse the parameters in conjunction with arguments.<br>
2. If argument is declared as const Type*,<span class="Apple-converted-space"> </span><br>
3. but corresponding parameter is pointer to undefined value in current function call,<br>
3. then generate warning "Function call argument is a pointer to uninitialized value"<br>
<br>
I am going to use mainly the following interfaces:<br>
SVal::getAs<loc::MemRegionVal>()<br>
MemRegionVal::getRegion()<br>
CheckerContext::&getState()<br>
SVal::isUndef()<br>
QualType::getTypePtr()<br>
Type::getPointeeType()<span class="Apple-converted-space"> </span><br>
QualType::isConstQualified()<br>
FunctionDecl::getParamDecl(unsigned i)<br>
<br>
any objects/opinions on the design?<br>
<br>
cheers!<br>
/Per<br>
<br>
<br>
<div style="font-size:13px; font-family:Tahoma">
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US">.......................................................................................................................</span><span style="font-size:8pt; font-family:Arial,sans-serif" lang="EN-US"><br>
Per Viberg<span class="Apple-converted-space"> </span></span><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US">Senior Engineer</span><span style="font-size:8.5pt; font-family:Arial,sans-serif; color:gray" lang="EN-US"><br>
Evidente ES East</span><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US"><span class="Apple-converted-space"> </span>AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden</span><span style="font-size:10pt; font-family:Tahoma,sans-serif" lang="EN-US"></span></div>
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-GB">Phone:    +46 (0)8 402 79 00<br>
Mobile:    +46 (0)70 912 42 52<br>
E-mail:    <span class="Apple-converted-space"> </span><a href="mailto:Per.Viberg@evidente.se" target="_blank"><font color="#0000ff">Per.Viberg@evidente.se</font></a><span class="Apple-converted-space"> </span></span><span style="font-size:8pt; font-family:Arial,sans-serif" lang="EN-GB"><br>
<br>
<a href="http://www.evidente.se/" target="_blank"><font color="#0000ff">www.evidente.se</font></a></span></div>
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:6pt; font-family:Arial,sans-serif" lang="EN-GB">This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee,
 employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.</span></div>
</div>
</div>
<div style="font-family:'Times New Roman'; font-size:16px">
<hr tabindex="-1">
<div id="divRpF283255" style="direction:ltr"><font face="Tahoma" size="2"><b>Från:</b><span class="Apple-converted-space"> </span>Per Viberg<br>
<b>Skickat:</b><span class="Apple-converted-space"> </span>den 14 februari 2014 13:41<br>
<b>Till:</b><span class="Apple-converted-space"> </span>Clang Dev ‎[<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a>]‎<br>
<b>Ämne:</b><span class="Apple-converted-space"> </span>improving detection of uninitialized arguments (the CallAndMessageChecker)<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; font-size:10pt"><br>
<div>Hi,<br>
<br>
I'm looking into extending the check that warns for uninitialized arguments. Below I've described what should be detected. Any opinions on if it's a useful check or potential problems/drawbacks with it?.<br>
<br>
Check: should this be detected as a warning for uninitialized argument?:"<b><font face="Courier New">warning: Function call argument is an uninitialized value"</font></b><br>
<br>
<b><font face="Courier New">void doStuff(const int *p);<br>
void f(void);<br>
<br>
void f(void) {<br>
      int x;<br>
      doStuff(&x);  // ← warning?<br>
}</font></b><br>
<br>
My rationale behind the warning:<br>
1. it's not possible to write to *p, because it's of type const<br>
2. content of *p is uninitialized stack value, and shouldn't be used.<br>
3. the value of p is of no interest, since it's an address of an stack variable.<br>
<br>
if any of the above criteria are not fulfilled, then no warning. Thus the function prototype must state pointer to const for the argument, the variable that the function is called with must be address of local/stack variable.<br>
<br>
currently, only this is detected:<br>
<br>
<b><font face="Courier New">void doStuff2(int p);<br>
void g(void);<br>
<br>
void g(void) {<br>
      int y;<br>
      doStuff2(y);  //<span class="Apple-converted-space"> </span></font></b><b><font face="Courier New">warning: Function call argument is an uninitialized value</font></b><br>
<br>
<br>
/Per<br>
<br>
<br>
<br>
<div style="font-size:13px; font-family:Tahoma">
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US">.......................................................................................................................</span><span style="font-size:8pt; font-family:Arial,sans-serif" lang="EN-US"><br>
Per Viberg<span class="Apple-converted-space"> </span></span><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US">Senior Engineer</span><span style="font-size:8.5pt; font-family:Arial,sans-serif; color:gray" lang="EN-US"><br>
Evidente ES East</span><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-US"><span class="Apple-converted-space"> </span>AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden</span><span style="font-size:10pt; font-family:Tahoma,sans-serif" lang="EN-US"></span></div>
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:8pt; font-family:Arial,sans-serif; color:gray" lang="EN-GB">Phone:    +46 (0)8 402 79 00<br>
Mobile:    +46 (0)70 912 42 52<br>
E-mail:    <span class="Apple-converted-space"> </span><a href="mailto:Per.Viberg@evidente.se" target="_blank"><font color="#0000ff">Per.Viberg@evidente.se</font></a><span class="Apple-converted-space"> </span></span><span style="font-size:8pt; font-family:Arial,sans-serif" lang="EN-GB"><br>
<br>
<a href="http://www.evidente.se/" target="_blank"><font color="#0000ff">www.evidente.se</font></a></span></div>
<div style="margin-top:0px; margin-bottom:0px"><span style="font-size:6pt; font-family:Arial,sans-serif" lang="EN-GB">This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee,
 employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.</span></div>
</div>
</div>
<div style="font-family:'Times New Roman'; font-size:16px">
<hr tabindex="-1">
<br>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>