http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54498
Bug #: 54498 Summary: incorrect code generation from g++ -O on x86_64 Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: stev...@alum.mit.edu Created attachment 28136 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28136 preprocessed source exhibiting the problem The attached preprocessed source (bug.ii) illustrates an apparent incorrect code generation when it is compiled with g++ -O version 4.7.1 on x86_64 (Debian GNU/Linux). The program executes two iterations of a loop, calling a function that returns two slightly different complex numbers in the two iterations. After the second iteration, it prints the absolute value of the difference. The correct output (when compiled without optimization) is: ft (it = 0) = -491.697+887.05i ft (it = 1) = -491.692+887.026i abs(ft - prev_ft) = 0.0245153 (0.0245153 is the correct absolute difference of the two previous numbers.) When compiled with -O, it produces: ft (it = 0) = -491.697+887.05i ft (it = 1) = -491.692+887.026i abs(ft - prev_ft) = 491.692 Note that the first two numbers are the same, but the absolute value of the difference is wrong. The problem disappears if I use g++ 4.4.5, or if I make minor changes to the code; I've tried to boil it down to the minimal code that exhibits the problem. Steven PS. The preprocessed source is rather long only because it #includes <stdio.h> and <complex>; the program source at the end is quite short. PPS. Some of my g++ -v output follows, indicating the g++ configuration options etcetera: Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/home/stevenj/downloads/gcc/gcc-4.7.1/OBJ/../local --disable-multilib --enable-languages=c,c++ GNU C++ (GCC) version 4.7.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.7.1, GMP version 4.3.2, MPFR version 3.0.0-p3, MPC version 0.8.2 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072