[LLVMdev] bug or expected behaviour?

Richard Smith richard at metafoo.co.uk
Wed Jun 5 12:18:26 PDT 2013


On Wed, Jun 5, 2013 at 9:55 AM, Carl Norum <carl at lytro.com> wrote:

>
> On Jun 5, 2013, at 7:50 AM, John Regehr <regehr at cs.utah.edu> wrote:
>
> >> 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.
> >
> > 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.
>
> OK, cool, thanks.
>
> Why no warning or static analyzer error?  Other "this comparison is always
> true" or "this comparison is always false" warnings exist, right?


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.

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).

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130605/d75d433d/attachment.html>


More information about the llvm-dev mailing list