This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/49820] New: Explicit check for integer negative after abs optimized away
- From: "agner at agner dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 23 Jul 2011 07:10:50 +0000
- Subject: [Bug c/49820] New: Explicit check for integer negative after abs optimized away
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: agner@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.