http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49820

           Summary: Explicit check for integer negative after abs
                    optimized away
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: ag...@agner.org


Created attachment 24812
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24812
Example generating bug

The integer abs function can overflow if the argument is 0x80000000. An
intended check for overflow is ignored. The gcc compiler optimizes away a check
for the value < 0 after abs with -O2 optimization:
int b;
b = abs(b);
if (b < 0)  // check for overflow optimized away

The error occurs when compiling the attached file with -O2, 32 or 64 bit mode,
C or C++. The C/C++ language does not normally need to check for overflow, but
it should acknowledge an explicit check for overflow.

Reply via email to