<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}
p
        {margin-top:0;
        margin-bottom:0}
-->
P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;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?. <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 </font></b><b><font face="Courier New">"Function call argument is a pointer to uninitialized value"
<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*, <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() <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">
<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="divRpF283255"><font color="#000000" face="Tahoma" size="2"><b>Från:</b> Per Viberg<br>
<b>Skickat:</b> den 14 februari 2014 13:41<br>
<b>Till:</b> Clang Dev ‎[cfe-dev@cs.uiuc.edu]‎<br>
<b>Ämne:</b> improving detection of uninitialized arguments (the CallAndMessageChecker)<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; 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);  // </font></b><b><font face="Courier New"><b><font face="Courier New">warning: Function call argument is an uninitialized value</font></b></font></b><br>
<br>
<br>
/Per<br>
<br>
<br>
<br>
<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">
<br>
</div>
</div>
</div>
</div>
</div>
</body>
</html>