[cfe-commits] PATCH: Enhance array bounds checking

Eli Friedman eli.friedman at gmail.com
Thu Jul 21 13:53:11 PDT 2011


On Thu, Jul 21, 2011 at 1:44 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>> void foo(int n) {
>>>   char x[5];
>>>   if (n > 0) bar(x + 6 - n);
>>> }
>>
>> Strictly speaking, that isn't a false positive... I can't think of how
>> we would actually produce anything other than the expected result,
>
> [I'm not sure how closely you were considering your knowledge of the
> implementation of clang (which is no doubt greater than my own)
> compared to things a C++ compiler could possibly do, even if clang
> doesn't do them today.]
>
> Actually it's not so hard to imagine a case just like this where this
> UB could result in some interesting results. It wouldn't be hard for
> the compiler to prove that x + 6 is out of range, therefor the
> condition (n > 0) must always be false, so it could just remove the
> code entirely. Chris gave some similar examples in his blog series on
> UB.

Right... I was mostly considering clang's implementation; we don't
aggressively transform provably undefined GEP's, at least at the
moment.

-Eli




More information about the cfe-commits mailing list