public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49820] New: Explicit check for integer negative after abs optimized away
@ 2011-07-23  7:11 agner at agner dot org
  2011-07-23  7:20 ` [Bug c/49820] " schwab@linux-m68k.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: agner at agner dot org @ 2011-07-23  7:11 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-07-27 14:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-23  7:11 [Bug c/49820] New: Explicit check for integer negative after abs optimized away agner at agner dot org
2011-07-23  7:20 ` [Bug c/49820] " schwab@linux-m68k.org
2011-07-23 17:23 ` pinskia at gcc dot gnu.org
2011-07-23 17:30 ` schwab@linux-m68k.org
2011-07-23 20:48 ` noloader at gmail dot com
2011-07-23 20:59 ` ebotcazou at gcc dot gnu.org
2011-07-23 22:28 ` noloader at gmail dot com
2011-07-24  8:10 ` ebotcazou at gcc dot gnu.org
2011-07-24  8:17 ` agner at agner dot org
2011-07-24  9:41 ` pinskia at gcc dot gnu.org
2011-07-25  7:44 ` agner at agner dot org
2011-07-25  7:46 ` ebotcazou at gcc dot gnu.org
2011-07-25 14:22 ` agner at agner dot org
2011-07-26 19:32 ` agner at agner dot org
2011-07-27 11:23 ` ebotcazou at gcc dot gnu.org
2011-07-27 14:28 ` agner at agner dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).