[cfe-dev] Possible clang bug with -O2, wrong if branch entered, in clang version 2.1 (tags/Apple/clang-163.7.1)

Jonathan Sauer jonathan.sauer at gmx.de
Tue Feb 21 09:04:33 PST 2012


>>> Sorry, there was a problem with cut&paste of the gist URL, the correct
>> one is:
>>> https://gist.github.com/1876875
>> Hi Salvatore,
>> If I understand this code correctly, there is a signed overflow.
>> Signed overflow is undefined behavior.  Clang (or LLVM) apparently
>> takes advantage of that by optimizing (incr < 0 && value > oldvalue)
>> => false.
> And you can get clang to barf on such occurrences:
> <http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html>

Is there a reason why integer overflow checks are only inserted with -ftrapv, but not with
-fcatch-undefined-behavior? (clang r151042)


More information about the cfe-dev mailing list