public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/34454]  New: [4.3 regression] Overflow check is optimized away when -O2 is enabled
@ 2007-12-13 19:33 ismail at pardus dot org dot tr
  2007-12-13 19:36 ` [Bug middle-end/34454] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ismail at pardus dot org dot tr @ 2007-12-13 19:33 UTC (permalink / raw)
  To: gcc-bugs

Testcase :

#include <sys/types.h>
#include <stdio.h>

void foo(ssize_t x)
{
 if (x >= 0) {
   if (x+x < 0) printf("Overflow\n");
}
}

main()
{
  volatile ssize_t x =2147483647;
  foo(x);
}

When compiled with -O2 it doesn't print Overflow, if you omit -O2 it prints
overflow.
gcc 3.4.6 works fine so this is a regression.


-- 
           Summary: [4.3 regression] Overflow check is optimized away when -
                    O2 is enabled
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ismail at pardus dot org dot tr


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


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

* [Bug middle-end/34454] [4.3 regression] Overflow check is optimized away when -O2 is enabled
  2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
@ 2007-12-13 19:36 ` pinskia at gcc dot gnu dot org
  2007-12-13 19:37 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-12-13 19:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-12-13 19:36 -------
This is not a bug, signed overflow is undefined so optimizing away this case is
correct as a positive + positive is always positive.

Use -fwarpv or what ever the strict overflow option is.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug middle-end/34454] [4.3 regression] Overflow check is optimized away when -O2 is enabled
  2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
  2007-12-13 19:36 ` [Bug middle-end/34454] " pinskia at gcc dot gnu dot org
@ 2007-12-13 19:37 ` pinskia at gcc dot gnu dot org
  2007-12-13 19:38 ` ismail at pardus dot org dot tr
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-12-13 19:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-12-13 19:37 -------
Or use unsigned types to do the addition.


-- 


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


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

* [Bug middle-end/34454] [4.3 regression] Overflow check is optimized away when -O2 is enabled
  2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
  2007-12-13 19:36 ` [Bug middle-end/34454] " pinskia at gcc dot gnu dot org
  2007-12-13 19:37 ` pinskia at gcc dot gnu dot org
@ 2007-12-13 19:38 ` ismail at pardus dot org dot tr
  2007-12-13 20:37 ` ian at airs dot com
  2007-12-13 20:49 ` ismail at pardus dot org dot tr
  4 siblings, 0 replies; 6+ messages in thread
From: ismail at pardus dot org dot tr @ 2007-12-13 19:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from ismail at pardus dot org dot tr  2007-12-13 19:37 -------
FWIW this triggers a crash in Python 2.5, see http://bugs.python.org/issue1608


-- 


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


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

* [Bug middle-end/34454] [4.3 regression] Overflow check is optimized away when -O2 is enabled
  2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
                   ` (2 preceding siblings ...)
  2007-12-13 19:38 ` ismail at pardus dot org dot tr
@ 2007-12-13 20:37 ` ian at airs dot com
  2007-12-13 20:49 ` ismail at pardus dot org dot tr
  4 siblings, 0 replies; 6+ messages in thread
From: ian at airs dot com @ 2007-12-13 20:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ian at airs dot com  2007-12-13 20:37 -------
Note that this gives a warning with -Wstrict-overflow.

And note that you get the desired behaviour if you compile with
-fno-strict-overflow.

As Pinski says, the code is simply incorrect according to standard C, but you
can use the -Wstrict-overflow and -fno-strict-overflow options to help fix
existing code bases.


-- 


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


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

* [Bug middle-end/34454] [4.3 regression] Overflow check is optimized away when -O2 is enabled
  2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
                   ` (3 preceding siblings ...)
  2007-12-13 20:37 ` ian at airs dot com
@ 2007-12-13 20:49 ` ismail at pardus dot org dot tr
  4 siblings, 0 replies; 6+ messages in thread
From: ismail at pardus dot org dot tr @ 2007-12-13 20:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ismail at pardus dot org dot tr  2007-12-13 20:48 -------
Guido agreed on using -fwrapv hence a patch submitted, thanks for the
diagnosis.


-- 


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


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

end of thread, other threads:[~2007-12-13 20:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-13 19:33 [Bug middle-end/34454] New: [4.3 regression] Overflow check is optimized away when -O2 is enabled ismail at pardus dot org dot tr
2007-12-13 19:36 ` [Bug middle-end/34454] " pinskia at gcc dot gnu dot org
2007-12-13 19:37 ` pinskia at gcc dot gnu dot org
2007-12-13 19:38 ` ismail at pardus dot org dot tr
2007-12-13 20:37 ` ian at airs dot com
2007-12-13 20:49 ` ismail at pardus dot org dot tr

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).