<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>In addition to my previous letter. I'm very concerned that we may have no chance to analyze a big chunk of code in this case:<br>
</p>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><span style="font-family: Consolas, monospace; font-size: 9pt;"></span></div>
<div><span style="font-size: 9pt;"><span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">void clang_analyzer_warnIfReached();</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">int f()</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">{</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">  int i = 0;</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">  for(int i = 0; i < 100; i++){</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">    if(i > 10){</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">      clang_analyzer_warnIfReached();</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">      // a lot of code will never be analyzed</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">    }</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">  }</span></span><br style="font-family: Consolas, monospace;">
<span style="font-family: Consolas, monospace;"><span style="font-family: Consolas, monospace;">}</span></span></span></div>
</blockquote>
<p>Why don't we analyze loop bodies as functions, just substitute a var `i` <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
with </span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">s</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">ymbols(or
 constraint ranges)</span> after reaching the limits, not generating a sinks instead?<br>
</p>
<p>Or there are somewhere already disscussed plans for improvement?<br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<hr>
<div><b>Denys Petrov</b></div>
<div>Senior ó++ Developer | Kharkiv, Ukraine</div>
<div><br>
</div>
<div></div>
</div>
</div>
<div style="color: rgb(33, 33, 33);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>ïÔ:</b> Artem Dergachev <noqnoqneo@gmail.com><br>
<b>ïÔÐÒÁ×ÌÅÎÏ:</b> 28 ÉÀÌÑ 2020 Ç. 22:34<br>
<b>ëÏÍÕ:</b> Denis Petrov; cfe-dev<br>
<b>ôÅÍÁ:</b> Re: [cfe-dev] [analyzer] How to analyzer the code after an indefinite loop?</font>
<div> </div>
</div>
<div>
<div style="font-size:9pt; font-family:'Calibri',sans-serif">
<h3 style="background-color:#ffffff; font-size:10pt; border:1px dotted #003333; padding:.8em">
<span style="color:#ff6600">CAUTION:<strong> </strong></span>This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.  If you suspect potential phishing or spam
 email, report it to ReportSpam@accesssoftek.com</h3>
</div>
<div>Here's how you can find this out with the help of ExprInspection:<br>
<br>
<br>
$ cat test.c<br>
<br>
int f(int x, int flag)<br>
{<br>
  int i = 0;<br>
  while(i < x)<br>
    i++;<br>
<br>
  clang_analyzer_warnIfReached();<br>
}<br>
<br>
<br>
$ clang --analyze -Xclang -analyzer-checker=debug.ExprInspection test.c<br>
<br>
test.c:7:3: warning: REACHABLE [debug.ExprInspection]<br>
  clang_analyzer_warnIfReached();<br>
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
1 warning generated.<br>
<br>
<br>
Here's a slightly more interesting experiment:<br>
<br>
<br>
$ cat test.c<br>
<br>
int f(int x, int flag)<br>
{<br>
  int i = 0;<br>
  while(i < x)<br>
    i++;<br>
<br>
  if (flag) {<br>
    clang_analyzer_warnIfReached();<br>
    clang_analyzer_numTimesReached();<br>
    return i;<br>
  } else {<br>
    clang_analyzer_warnIfReached();<br>
    clang_analyzer_numTimesReached();<br>
    return 0;<br>
  }<br>
}<br>
<br>
<br>
$ clang --analyze -Xclang -analyzer-checker=debug.ExprInspection test.c<br>
<br>
test.c:8:5: warning: REACHABLE [debug.ExprInspection]<br>
    clang_analyzer_warnIfReached();<br>
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
test.c:9:5: warning: 4 [debug.ExprInspection]<br>
    clang_analyzer_numTimesReached();<br>
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
test.c:12:5: warning: REACHABLE [debug.ExprInspection]<br>
    clang_analyzer_warnIfReached();<br>
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
test.c:13:5: warning: 1 [debug.ExprInspection]<br>
    clang_analyzer_numTimesReached();<br>
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
4 warnings generated.<br>
<br>
<br>
Will you be able to figure out why is one branch reached 4 times while the other branch is reached only once? You can find all your answers on the exploded graph dump.<br>
<br>
<br>
<div class="moz-cite-prefix">On 7/28/20 5:59 AM, Denis Petrov via cfe-dev wrote:<br>
</div>
<blockquote type="cite"><style type="text/css" style="">
<!--
p
        {margin-top:0px;
        margin-bottom:0px}
-->
</style>
<p>Hi, community!<br>
</p>
<p><br>
</p>
<p>A quick question.<br>
</p>
<p><br>
</p>
<p>Is CSA Core able to analyze the code after some indefinite loop?<br>
</p>
<p>E.g.<br>
</p>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">void f(int x)</span></span></span></span></div>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">{</span></span></span></span><br style="font-family:Consolas,monospace">
</span></div>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">  int i = 0;</span></span></span></span><br style="font-family:Consolas,monospace">
</span></div>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">  while(i < x)</span></span></span></span></div>
<div><span style="font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">    i++;</span></span><br style="font-family:Consolas,monospace">
</span></div>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">  // Interested
 in some code here!!</span></span></span></span><br style="font-family:Consolas,monospace">
</span></div>
<div><span style="font-family:Consolas,monospace; font-size:9pt"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">}</span></span></span></span><br>
</div>
<p><br>
</p>
<p>I found that Exploded graph grows going through the loop 4 times and then stops to analyze the code further.<br>
</p>
<p>P.S. I know about -<span style="color:rgb(36,41,46); font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace; font-size:12px; white-space:pre; background-color:rgb(255,255,255)">analyzer-max-loop</span>(4)​.<br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<hr>
<div><b>Denys Petrov</b></div>
<div>Senior ó++ Developer | Kharkiv, Ukraine</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</body>
</html>