This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/41864] New: GCC optimization error
- From: "chuongdo at cs dot stanford dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Oct 2009 05:38:53 -0000
- Subject: [Bug c++/41864] New: GCC optimization error
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In this program, I am taking a 64-bit double and reinterpreting it as a 64-bit
long long. I am then reinterpreting that as a 64-bit double again. The
expected output of the program is "1", but when compiling with -O2, the answer
is gibberish.
---------------------------
chuongdo@kartoo:~/speed$ cat bug2.cc
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv) {
double x = 1;
long long y = *(long long *)(void *)&x;
double z = *(double *)(void *)&y;
z = *(double *)(void *)&y;
cerr << z << endl;
return 0;
}
chuongdo@kartoo:~/speed$ g++ --version
g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3
Copyright (C) 2008 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.
chuongdo@kartoo:~/speed$ uname -a
Linux kartoo 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:48:52 UTC 2009
x86_64 GNU/Linux
chuongdo@kartoo:~/speed$ g++ -o bug2 bug2.cc
chuongdo@kartoo:~/speed$ ./bug2
1
chuongdo@kartoo:~/speed$ g++ -o bug2 bug2.cc -O2
chuongdo@kartoo:~/speed$ ./bug2
6.95328e-310
--
Summary: GCC optimization error
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: chuongdo at cs dot stanford dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41864