This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
painful optimization bug in 19980921
- To: egcs-bugs at cygnus dot com
- Subject: painful optimization bug in 19980921
- From: Corey Kosak <kosak at cs dot cmu dot edu>
- Date: Sun, 27 Sep 1998 15:51:10 -0400
Hello,
This strange little program prints the wrong answers when optimization
is turned on. Note that the if(0) line is required to trigger the bug.
% g++ -v
Reading specs from /afs/cs.cmu.edu/project/cmcl-kosak/various-gcc/egcs-19980921/i386_linux2/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.92.11/specs
gcc version egcs-2.92.11 19980921 (gcc2 ss-980609 experimental)
% g++ pp2.cc ; a.out
1000
1000
% g++ -O pp2.cc ; a.out
1000
666
% cat pp2.cc
#include <iostream.h>
template<class T> void func(const T &x) {}
int main()
{
unsigned int optimalDistance=1000;
unsigned int currentDistance=666;
cerr << optimalDistance << "\n";
for(int i=0; i<1; ++i) {
cerr << optimalDistance << "\n";
if(currentDistance<optimalDistance) {
optimalDistance=currentDistance;
if(0)
func(optimalDistance); //never called!
}
}
}