http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47282
Summary: GCC 4.2 gives different result for the same computation with -O3, depending on irrelevant code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: ichu...@algebra.com Created attachment 22961 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22961 tstdouble.cpp -- compile with gcc-4.2 -O3 -o tstdouble tstdouble.cpp The attached C++ code depends only on stdio.h and string.h. It calls the same function (DoubleToInt) twice: once from main( ... ) and once from Test( ... ). Both main() and Test() call DoubleToInt with exact same values of v and factor. DoubleToInt include some junk code surrounded by "if( False() ) { ... }". That junk code, though it never executes, has the effect of altering the result of calling DoubleToInt, so the second call's result does not match the first call's result. Even taking out a couple of lines from the big condition of if statement inside if( False() ) { ... }, causes the values to become correct. Similarly, taking out printf in DoubleToInt, also causes the printed values to be correct (identical). So some flakiness exists in computations, depending on irrelevant code that never executes. We tried very hard to distill it into smallest possible code. This seems to NOT occur in GCC 4.3 and GCC 4.4. It only occurs with -O3. To compile: gcc-4.2 -O3 -o tstdouble tstdouble.cpp