[Bug c/109507] Optimizer creates incorrect program
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109507 Aran Clauson changed: What|Removed |Added Status|RESOLVED|CLOSED --- Comment #4 from Aran Clauson --- Disregard.
[Bug c/109507] Optimizer creates incorrect program
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109507 --- Comment #3 from Jonathan Wakely --- When you created this bug report there was a red banner at the top of the page that begins by asking you to read https://gcc.gnu.org/bugs/ and that tells you to try -fsanitize=undefined
[Bug c/109507] Optimizer creates incorrect program
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109507 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #2 from Andrew Pinski --- -fsanitize=undefined, at runtime gives: /app/example.cpp:4:7: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself Note the message is slightly wrong but points you to the right reason. There is an overflow. because ~0x8000 is 2147483648 and then you add 1 to it giving you an overflow which is undefined. Note ~a+1 is the same as -a as both cases will overflow at the same time with 0x8000 which is why GCC is providing that error message rather then on dealing with +1 like clang does: Note clang gives: /app/example.cpp:4:15: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
[Bug c/109507] Optimizer creates incorrect program
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109507 Sam James changed: What|Removed |Added CC||sjames at gcc dot gnu.org --- Comment #1 from Sam James --- UBSAN with GCC: ``` $ /tmp/foo /tmp/foo.c:4:7: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself 0 ``` UBSAN with Clang: ``` /tmp/foo.c:4:15: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /tmp/foo.c:4:15 in 0 ```