Created attachment 127100 [details] demonstration
In the attached program are 32-bit and 64-bit factorial functions. The 32-bit function works fine. The 64-bit function works with no optimizations but loops forever with -Os. $ uname -a Linux rosalyn.slamb.org 2.6.15-1.1831_FC4 #1 Tue Feb 7 13:37:42 EST 2006 i686 athlon i386 GNU/ Linux $ gcc --version gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8) $ gcc miscompile-64bit-Os.c $ ./a.out factorial_32(5) = 120 factorial_64(5) = 120 $ gcc -Os miscompile-64bit-Os.c $ ./a.out factorial_32(5) = 120 ... For what it's worth, this same program works fine on my G4 running OS X 10.4 Tiger. gcc --version there returns: powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5247)
Works correctly with GCC 4.1.0-3 (FC5 gcc). Tracked upstream as PR27003.