<div dir="ltr"><div><div><div><div>Hi!<br><br></div>The static analyzer can only reason about one translation unit at once. With only local knowledge the static analyzer can not assume that zero is not modified by the time f is called. For this reason I think the analyzer evaluates both branches of your first if. On the branch, where zero is not 0 it calls into printInt. The definition of printInt is not available, so the analyzer have to assume that, the value of zero is changed. Why? Because even though it is static and printInt should not be able to modify it, printInt might be able to call into another function which can modify the value of zero. So by the time you reach the second if statment on this branch you do not have any reliable information about the value of zero. The reason why it work with standard functions is that, there are some heuristics which assumes that standard library functions are well behaved and do not modify global state. All in all it all boils down to that it is impossible to reason about global state rigorously with local knowledge. This problem could be mitigated using some annotations that some functions are not going to modify the global state.<br><br></div>I hope  I could answer your question.<br><br></div>Regards,<br></div>Gabor<br><div><div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 19 October 2015 at 13:13, Bhargava Shastry via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
<br>
I came across a curious pattern of FPs while evaluating Clang SA:<br>
<br>
$ cat garbageread-fp.c<br>
1. extern void printInt(int x); // prints int<br>
2.<br>
3. static int zero = 0;<br>
4.<br>
5. void f() {<br>
6.   int x;<br>
7.   if (zero != 0)<br>
8.        printInt(0); // dead code<br>
9.   else<br>
10.        x = 0;<br>
11.  if (zero == 0) {<br>
12.        if (!x)<br>
13.                printInt(x);<br>
14.   }<br>
15. }<br>
<br>
$ clang --analyze garbageread-fp.c<br>
garbageread-fp.c:12:8: warning: Branch condition evaluates to a garbage<br>
value<br>
        if (!x)<br>
            ^~<br>
1 warning generated.<br>
<br>
I have uploaded an html report here: <a href="http://output.jsbin.com/jiqewevihi" rel="noreferrer" target="_blank">http://output.jsbin.com/jiqewevihi</a><br>
<br>
Why does Clang SA forget the constraint down the execution path?<br>
<br>
Notes:<br>
1. Replacing static with extern retains the FP.<br>
2. The FP has something to do with function inlining. Replacing printInt<br>
with standard library function makes the FP go away!<br>
<br>
Regards,<br>
Bhargava<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div></div></div></div></div></div></div>