[cfe-commits] r154794 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval-64.c test/Sema/const-eval.c

Eli Friedman eli.friedman at gmail.com
Sun Apr 15 22:16:04 PDT 2012


On Sun, Apr 15, 2012 at 10:00 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> Hi Eli,
>
> This "breaks" pointer arithmetic for some cases with undefined behavior (but
> which are probably common anyway):
>
>   int a;
>   bool b = &a - 1 < &a;
>
> I suspect (without evidence) that this happens frequently in real
> code. Perhaps we should refuse to fold a pointer comparison for a non-null
> base if either (unsigned) offset is greater than the size of the base
> object?

I hope it doesn't happen frequently... but yes, we should refuse to
fold it.  That's basically the same as my FIXME: in the general case,
we can't tell whether &a - N < &a is true at compile-time.

Can we use Context.getTypeSizeInChars(LHSValue.Base->getType()) to
compute the size, or is there some other way you would suggest?

-Eli




More information about the cfe-commits mailing list