public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26824] New: optimisation bug with -0x80000000
@ 2006-03-23 11:37 simonmar at microsoft dot com
2006-03-23 14:12 ` [Bug middle-end/26824] " pinskia at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: simonmar at microsoft dot com @ 2006-03-23 11:37 UTC (permalink / raw)
To: gcc-bugs
The following code is compiled incorrectly with -O2:
#include <stdlib.h>
void f(int x) {
if (x < 0) {
if (-x > 0) {
exit(1);
}
}
}
int main() {
f(-0x80000000);
exit(0);
}
$ gcc foo.c; ./a.out
$ gcc -O2 foo.c; ./a.out
zsh: 4407 exit 1 ./a.out
$
--
Summary: optimisation bug with -0x80000000
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: simonmar at microsoft dot com
GCC build triplet: x86_64-redhat-linux
GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
@ 2006-03-23 14:12 ` pinskia at gcc dot gnu dot org
2006-03-23 14:44 ` falk at debian dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-23 14:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-03-23 14:12 -------
-0x80000000 is going to overflow and for signed integers overflow is undefined.
If you want signed integers to be defined to be wrapping use -fwrapv.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|c |middle-end
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
2006-03-23 14:12 ` [Bug middle-end/26824] " pinskia at gcc dot gnu dot org
@ 2006-03-23 14:44 ` falk at debian dot org
2006-03-23 14:49 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: falk at debian dot org @ 2006-03-23 14:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from falk at debian dot org 2006-03-23 14:44 -------
Wait a minute. 0x80000000 is unsigned. So -0x80000000 is well-defined, and
is 0x80000000 (unsigned). This is then converted to signed. Since 0x80000000
cannot be represented in signed, the result is implementation specific.
We document it to be -0x80000000. So the call is just fine.
--
falk at debian dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
2006-03-23 14:12 ` [Bug middle-end/26824] " pinskia at gcc dot gnu dot org
2006-03-23 14:44 ` falk at debian dot org
@ 2006-03-23 14:49 ` pinskia at gcc dot gnu dot org
2006-03-23 14:57 ` falk at debian dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-23 14:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-03-23 14:49 -------
It is the -x in f where x = 0x80000000 which is undefined as it overflows.
--
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=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (2 preceding siblings ...)
2006-03-23 14:49 ` pinskia at gcc dot gnu dot org
@ 2006-03-23 14:57 ` falk at debian dot org
2006-03-23 15:10 ` [Bug c/26824] " simonmar at microsoft dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: falk at debian dot org @ 2006-03-23 14:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from falk at debian dot org 2006-03-23 14:57 -------
(In reply to comment #3)
> It is the -x in f where x = 0x80000000 which is undefined as it overflows.
Oh. I see. Right.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (3 preceding siblings ...)
2006-03-23 14:57 ` falk at debian dot org
@ 2006-03-23 15:10 ` simonmar at microsoft dot com
2006-03-23 15:14 ` rearnsha at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: simonmar at microsoft dot com @ 2006-03-23 15:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from simonmar at microsoft dot com 2006-03-23 15:10 -------
I see your point, but I still think there's a bug. Let me change the code
slightly:
#include <stdlib.h>
#include <stdio.h>
void f(int x) {
long y;
if (x < 0) {
y = -x;
if (y > 0) {
printf("%d\n",y);
}
}
}
int main() {
f(-0x80000000);
exit(0);
}
$ gcc -O2 foo.c
$ ./a.out
-2147483648
so, we're in the y > 0 branch, but y is clearly < 0.
--
simonmar at microsoft dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Component|middle-end |c
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (4 preceding siblings ...)
2006-03-23 15:10 ` [Bug c/26824] " simonmar at microsoft dot com
@ 2006-03-23 15:14 ` rearnsha at gcc dot gnu dot org
2006-03-23 15:15 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2006-03-23 15:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rearnsha at gcc dot gnu dot org 2006-03-23 15:14 -------
Pinskia is right, and this is just as undefined as your previous example
(negating INT_MIN is just undefined, however you do it). All you've done is
obfuscated things a bit more.
--
rearnsha at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (5 preceding siblings ...)
2006-03-23 15:14 ` rearnsha at gcc dot gnu dot org
@ 2006-03-23 15:15 ` pinskia at gcc dot gnu dot org
2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-23 15:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pinskia at gcc dot gnu dot org 2006-03-23 15:15 -------
(In reply to comment #5)
> I see your point, but I still think there's a bug. Let me change the code
> slightly:
The code is still undefined, as you are comparing an overflowed variable to
something.
-x is still undefined for x being 0x80000000 as it overflows and overflow
signed integer is undefined runtime code.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (7 preceding siblings ...)
2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
@ 2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-23 15:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from pinskia at gcc dot gnu dot org 2006-03-23 15:17 -------
Reopening to ...
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/26824] optimisation bug with -0x80000000
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
` (6 preceding siblings ...)
2006-03-23 15:15 ` pinskia at gcc dot gnu dot org
@ 2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-23 15:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from pinskia at gcc dot gnu dot org 2006-03-23 15:17 -------
Mark as a dup of bug 25329.
*** This bug has been marked as a duplicate of 25329 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26824
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-03-23 15:17 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-23 11:37 [Bug c/26824] New: optimisation bug with -0x80000000 simonmar at microsoft dot com
2006-03-23 14:12 ` [Bug middle-end/26824] " pinskia at gcc dot gnu dot org
2006-03-23 14:44 ` falk at debian dot org
2006-03-23 14:49 ` pinskia at gcc dot gnu dot org
2006-03-23 14:57 ` falk at debian dot org
2006-03-23 15:10 ` [Bug c/26824] " simonmar at microsoft dot com
2006-03-23 15:14 ` rearnsha at gcc dot gnu dot org
2006-03-23 15:15 ` pinskia at gcc dot gnu dot org
2006-03-23 15:17 ` pinskia at gcc dot gnu dot org
2006-03-23 15:17 ` pinskia at gcc dot gnu 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).