On Wed, Jun 5, 2013 at 9:55 AM, Carl Norum <span dir="ltr"><<a href="mailto:carl@lytro.com" target="_blank">carl@lytro.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On Jun 5, 2013, at 7:50 AM, John Regehr <<a href="mailto:regehr@cs.utah.edu">regehr@cs.utah.edu</a>> wrote:<br>
<br>
>> The optimizer can therefore conclude that if this program has well-defined behavior, then x can never point to the null pointer constant (since the null pointer constant is not part of any array object). As a result, the "if (!x)" branch would never trigger, and is dead code.<br>

><br>
> This is correct: in C you can't create a null pointer by decrementing a valid pointer.  The code in question is dangerous and wrong, and needs to be reviewed to look for other similar problems.<br>
<br>
</div>OK, cool, thanks.<br>
<br>
Why no warning or static analyzer error?  Other "this comparison is always true" or "this comparison is always false" warnings exist, right?</blockquote><div><br></div><div>There's no warning in the frontend, because this is not "locally" obvious -- we would need (very simple, in this case) reasoning about control flow to see this, and we don't have many such checks, because they're significantly more expensive than local checks.</div>
<div><br></div><div>There's no warning from the middle-end optimizers which remove the check, because we don't like the optimizer to produce warnings (they have stability issues and generally give a very poor diagnostic experience).</div>
<div><br></div><div>The static analyzer would be a good place to warn on this, but presumably it's just not been taught to issue this warning yet.</div></div>