Bug 38777 - gcc optimize flag causes different program behavior
Summary: gcc optimize flag causes different program behavior
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-09 08:16 UTC by Dov Grobgeld
Modified: 2012-01-13 06:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dov Grobgeld 2009-01-09 08:16:40 UTC
I downloaded a opengl source tutorial from
http://nehe.gamedev.net/data/lessons/linuxsdl/lesson40.tar.gz and compiled it
twice. The first time with the default Makefile as provided in the tarball. The
program then worked as described in the tutorial, a simulation of a string fell
down the ground and came to a standstill. I then edited the Makefile and
replaced -g with -O2 and recompiled. When running the program the string never
settled but instead I got chaotic motion. 

It thus appears that there is an optimization bug that causes numeric
instability of this particualar program. 

The tests were conducted with the gcc-4.3.2 under Fedora which has the internal version gcc-4.3.2-7.src.rpm.

Steps to Reproduce:
1. wget http://nehe.gamedev.net/data/lessons/linuxsdl/lesson40.tar.gz
2. tar -xf lesson40.tar.gz
3. cd lesson40_linux_sdl
4. make
5. ./lesson40
6. perl -pi~ -e 's/-g/-O2/' Makefile
7. make clean
8. make
9. ./lesson40

Actual results:

The second run of lesson40 yields chaotic motion.

Expected results:

The second run of lesson40 should give identical result to the first run.
Comment 1 Richard Biener 2009-01-09 10:34:42 UTC
Try -fno-strict-aliasing -fno-strict-overflow.  This is likely a program bug.
Hard to say without a testcase though.
Comment 2 Jakub Jelinek 2009-01-09 10:38:20 UTC
Also, if it is floating point using app on i?86, -msse2 -mfpmath=sse or -ffloat-store.
Comment 3 Dov Grobgeld 2009-01-09 10:46:15 UTC
The only flag that had any affect was the -ffloat-store option, which made the problem disappear.
Comment 4 Andrew Pinski 2009-01-09 20:41:04 UTC
Then this is most likely a dup of bug 323 which will be fixed for 4.5.
Comment 5 Andrew Pinski 2012-01-13 06:28:44 UTC
As mentioned this is a dup of bug 323.

*** This bug has been marked as a duplicate of bug 323 ***