<div class="gmail_quote">On Tue, Jul 3, 2012 at 1:14 AM, Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Mon, Jul 02, 2012 at 11:23:05PM -0000, Richard Smith wrote:<br>
> Log:<br>
> -Wuninitialized: assume that an __attribute__((returns_twice)) function might<br>
> initialize any variable. This is extremely conservative, but is sufficient for<br>
> now.<br>
<br>
</div>Can this be reduced to following both code paths if the function call is<br>
part of a conditional?</blockquote><div><br></div><div>I'm not sure what you're suggesting; we do follow both code paths after a conditional. If you mean that we should track whether the function returned a nonzero value, and not apply this logic in that case, then I think that's out of scope for this check, and belongs in the static analyzer (if anywhere).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When I analysed the newly triggered warnings for<br>
-Wuninitialized in NetBSD, setjmp usage was something like 50%<br>
questionable w.r.t. conditional initialisation, so getting this more<br>
strict or optional is definitely a good idea.</blockquote><div><br></div><div>If we want to make this smarter, I think the way to approach it is to find variable initializations which are reachable from the returns_twice call (optionally only looking at ones where there is a function call afterwards), and to assume that all relevant variables are initialized by the setjmp call. But we would need to find an inexpensive way of computing this information. Perhaps a reasonable tradeoff would be to compute a set of variables which are initialized anywhere within the function, and to assume that setjmp initializes them all.</div>
<div><br></div><div>It might also be valuable to separate the setjmp case (which needs this special handling) from the fork case (which does not), but we don't currently have attributes to track that.</div></div>