Bug 34943 - -fno-strict-overflow fails to prevent use of signed overflow
-fno-strict-overflow fails to prevent use of signed overflow
Status: NEW
Product: gcc
Classification: Unclassified
Component: tree-optimization
4.2.0
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks: 4.4pending
  Show dependency treegraph
 
Reported: 2008-01-23 16:45 UTC by Ian Lance Taylor
Modified: 2008-01-23 16:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-23 16:48:42


Attachments
Proposed patch (2.19 KB, patch)
2008-01-23 16:46 UTC, Ian Lance Taylor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2008-01-23 16:45:12 UTC
Consider this C test case:

const char *
f(long v)
{
  if (v < 0)
    v = - v;
  if (v > 0x7fffffff)
    return "negative";
  else
    return "positive";
}

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.
Comment 1 Ian Lance Taylor 2008-01-23 16:46:16 UTC
Created attachment 15009 [details]
Proposed patch

I believe that this is the correct patch for this bug.  This should be tested and committed for gcc 4.4.
Comment 2 Andrew Pinski 2008-01-23 16:48:41 UTC
Confirmed.