[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
Mon Apr 16 12:24:33 PDT 2012


On Sun, Apr 15, 2012 at 10:43 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Mon, April 16, 2012 06:16, Eli Friedman wrote:
>> 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?
>
> That seems fine to me (though use getType(LHSValue.Base) to handle an Expr* or
> ValueDecl* base), along with a check for an incomplete base type.

r154849.

-Eli




More information about the cfe-commits mailing list