public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40189] New: gcc 4.4.0 incorrectly folds add-as-comparison
@ 2009-05-18 19:35 mat at lcs dot mit dot edu
2009-05-18 19:47 ` [Bug c/40189] " schwab at linux-m68k dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: mat at lcs dot mit dot edu @ 2009-05-18 19:35 UTC (permalink / raw)
To: gcc-bugs
This code:
int
foo(int arg0)
{
if ((-2147483647 - 1) + arg0)
return 20;
else
return 11;
}
when compiled with gcc-4.4.0 at -O2 or higher, simply returns 20
unconditionally:
$ ~/x86-gcc4/bin/gcc -m32 -O2 -S ~/baz.c -o /dev/tty
.file "baz.c"
.text
.p2align 4,,15
.globl foo
.type foo, @function
foo:
pushl %ebp
movl $20, %eax
movl %esp, %ebp
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 4.4.0"
.section .note.GNU-stack,"",@progbits
This bug appears to be architecture-independent (I've seen it on x86,
x86_64, and another chip).
The bug did not happen in gcc-4.0.2.
Here is some information about my system:
$ ~/x86-gcc4/bin/gcc --version
gcc (GCC) 4.4.0
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ uname -a
Linux ld-1 2.6.9-42.0.8.ELsmp #1 SMP Tue Jan 30 12:18:01 EST 2007 x86_64 x86_64
x86_64 GNU/Linux
$ file bin/gcc
bin/gcc: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux
2.4.0, dynamically linked (uses shared libs), not stripped
--
Summary: gcc 4.4.0 incorrectly folds add-as-comparison
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mat at lcs dot mit dot edu
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40189
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/40189] gcc 4.4.0 incorrectly folds add-as-comparison
2009-05-18 19:35 [Bug c/40189] New: gcc 4.4.0 incorrectly folds add-as-comparison mat at lcs dot mit dot edu
@ 2009-05-18 19:47 ` schwab at linux-m68k dot org
2009-05-18 19:48 ` pinskia at gcc dot gnu dot org
2009-05-18 20:53 ` mat at lcs dot mit dot edu
2 siblings, 0 replies; 4+ messages in thread
From: schwab at linux-m68k dot org @ 2009-05-18 19:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from schwab at linux-m68k dot org 2009-05-18 19:47 -------
Not a bug. If arg0 is negative you get undefined behavior due to overflow.
Use -fwrapv to get wrapping semantics.
--
schwab at linux-m68k dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40189
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/40189] gcc 4.4.0 incorrectly folds add-as-comparison
2009-05-18 19:35 [Bug c/40189] New: gcc 4.4.0 incorrectly folds add-as-comparison mat at lcs dot mit dot edu
2009-05-18 19:47 ` [Bug c/40189] " schwab at linux-m68k dot org
@ 2009-05-18 19:48 ` pinskia at gcc dot gnu dot org
2009-05-18 20:53 ` mat at lcs dot mit dot edu
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-18 19:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2009-05-18 19:48 -------
INT_MIN + any number is never going to be zero because INT_MIN = - INT_MAX -1.
Also signed integer overflow is undefined which gives that the above.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40189
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/40189] gcc 4.4.0 incorrectly folds add-as-comparison
2009-05-18 19:35 [Bug c/40189] New: gcc 4.4.0 incorrectly folds add-as-comparison mat at lcs dot mit dot edu
2009-05-18 19:47 ` [Bug c/40189] " schwab at linux-m68k dot org
2009-05-18 19:48 ` pinskia at gcc dot gnu dot org
@ 2009-05-18 20:53 ` mat at lcs dot mit dot edu
2 siblings, 0 replies; 4+ messages in thread
From: mat at lcs dot mit dot edu @ 2009-05-18 20:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from mat at lcs dot mit dot edu 2009-05-18 20:53 -------
Fair enough, thanks (this came up running a compiler test suite that checks
even undefined edge cases).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40189
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-18 20:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-18 19:35 [Bug c/40189] New: gcc 4.4.0 incorrectly folds add-as-comparison mat at lcs dot mit dot edu
2009-05-18 19:47 ` [Bug c/40189] " schwab at linux-m68k dot org
2009-05-18 19:48 ` pinskia at gcc dot gnu dot org
2009-05-18 20:53 ` mat at lcs dot mit dot edu
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).