<p dir="ltr"><br>
2015. okt. 19. du. 3:14 ezt írta ("Daniel Marjamäki" <<a href="mailto:Daniel.Marjamaki@evidente.se">Daniel.Marjamaki@evidente.se</a>>):<br>
><br>
>  <br>
><br>
> Hello!<br>
><br>
>  <br>
><br>
> In my humble opinion that is a genuine false positive.<br>
><br>
>  <br>
><br>
> Unless we can see that printInt modifies zero, we should not write a warning. I would assume that external functions are “well behaved”.<br>
><br>
>  <br>
><br>
> Ø  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.<br>
><br>
>  <br>
><br>
> Then the translation unit would have to for instance have a globally accessible function that modifies zero.<br>
><br>
>  </p>
<p dir="ltr">Checking whether a globally available function can modify the static variable sounds like a good idea. I think it might worth a patch, to preserve the value in this case. </p>
<p dir="ltr">><br>
> As I see it.. we know that zero is not modified neither directly/indirectly by printInt if the provided code is the entire TU.<br>
><br>
>  <br>
><br>
> Best regards,<br>
><br>
> Daniel Marjamäki<br>
><br>
>  <br>
><br>
>  <br>
><br>
>  <br>
><br>
>  <br>
><br>
>  <br>
><br>
> On 19 October 2015 at 13:13, Bhargava Shastry via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
><br>
> 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">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>
</p>