GCC Bugzilla – Bug 34943
-fno-strict-overflow fails to prevent use of signed overflow
Last modified: 2008-01-23 16:48:41 UTC
Consider this C test case:
const char *
if (v < 0)
v = - v;
if (v > 0x7fffffff)
When this is compiled with -O2, it always returns "positive". This is fine because when v == LONG_MIN, negating it is undefined signed overflow. However, the same is true when this is compiled with -O2 -fno-strict-overflow, which is not fine. With -fno-strict-overflow, we can not assume that negating a signed value yields a nonnegative number.
This bug is neither serious nor a regression, so I'm recording it here in order to fix it for gcc 4.4.
Created attachment 15009 [details]
I believe that this is the correct patch for this bug. This should be tested and committed for gcc 4.4.