From Bugzilla Helper: User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.3-20mdk i686) Description of problem: The attached program produces wrong output when compiled with the -O2 option: $ gcc -o gcctest gcctest.cpp $ ./gcctest result: -3.000000 $ gcc -o gcctest gcctest.cpp -O2 $ ./gcctest result: 3.000000 This is tested under gcc-2.96-69 (RH-7.0), gcc-2.96-85 (RH-7.1) and gcc-2.96-0.48mdk (Mandrake 8.0). Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. compile 2. run 3. Additional info:
Created attachment 32539 [details] .cpp file triggering the bug.
The compiler is mis-optimizing the code when -O2 set. The following code from init function implement "f = -(v0+1);": flds 12(%ebp) fadds .LC0 fstps 12(%ebp) flds 12(%ebp) /* load into fp register */ xorb $128, 15(%ebp) /* value in fp register, not memory */ fstps (%eax) movl -12(%ebp), %eax movl %eax, (%esi) The "xorb $128, 15(%ebp)" should be a "fchs" instruction.
Ok with 3.2