<br><br><div>On Tue Jan 14 2014 at 5:56:08 PM, Michel Morin <<a href="mailto:mimomorin@gmail.com">mimomorin@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for looking into the PR, Michael.<br>
<br>
Michael Bao wrote:<br>
> I'm looking at this bug report here:<br>
> <a href="http://llvm.org/bugs/show_bug.cgi?id=17558" target="_blank">http://llvm.org/bugs/show_bug.<u></u>cgi?id=17558</a><br>
[...]<br>
> I've narrowed down the issue ClassifyRefs::VisitCastExpr.<br>
<br>
I don't know the internals of clang, but I don't think the cast is essential.<br>
For example, here is a test case without casting:<br>
<br>
#include <iostream><br>
<br>
int main()<br>
{<br>
    int x;<br>
    bool b = (&x == 0);<br>
<br>
    std::cout << x << std::endl; // Missing "uninitialized" warning<br>
    std::cout << b << std::endl;<br>
}<br></blockquote><div><br></div><div>The more general issue here is that if we see a local variable having its address taken, we assume the variable escapes the analysis, and that we can no longer reason about whether it is initialized. This is tricky to fix in general; Michael's patch addresses one particular corner of this, but if possible it'd be better to introduce a more holistic fix (addressing your case, his, and lots of others).</div>
<div><br></div><div>To get a feeling for why this is tricky, we would like to diagnose:</div><div><br></div><div>int x; bool b = (&x == 0); f(b); return x;</div><div><br></div><div>... and ...</div><div><br></div><div>
int x; bool b = &x; f(b); return x;</div><div><br></div><div>... but not ...</div><div><br></div><div>int x; int *b = &x; f(b); return x;</div><div><br></div><div>... because 'f' might initialize 'x'. In general, we would like to look at the context in which '&x' appears, and determine if that context could possibly store through the pointer or save it somewhere.</div>
<div><br></div><div>We'd probably want to keep the analysis simple and local, however, so we'd likely still miss the bug in this code:</div><div><br></div><div>int x; int *b = &x; if (cond) return x;</div><div>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
P.S.<br>
Richard, I'd like to say thank you for fixing PR16054 (Missing<br>
"uninitialized" warning). Spotting such uninitialized bugs without<br>
running static analyzer is very helpful in a C primer course.<br></blockquote><div><br></div><div>=) You're welcome! <br></div>