Bug 197349 - c++ optimization too agressive with -g *and* -O2 flag
c++ optimization too agressive with -g *and* -O2 flag
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
5
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-06-30 09:21 EDT by Rene van Paassen
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-11-28 04:15:44 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
example 3ds file for testing (from www.delta3d.org) (267.23 KB, application/octet-stream)
2006-06-30 09:21 EDT, Rene van Paassen
no flags Details
Result after pre-processor stage (1.50 MB, text/plain)
2006-08-03 08:45 EDT, Rene van Paassen
no flags Details

  None (edit)
Description Rene van Paassen 2006-06-30 09:21:06 EDT
Description of problem:

gcc miscompiles a part of OpenSceneGraph; combination of -g and -O2 flags
results in optimization that throws out a function call

Version-Release number of selected component (if applicable):

gcc-c++-4.1.1-1.fc5

OpenSceneGraph-1.0-3

How reproducible:

Use osgviewer to view a 3ds file; I used a file from delta3d; file included in
bug report:

osgviewer terrain.3ds



Steps to Reproduce:
1. yum install OpenSceneGraph
2. osgviewer terrain.3ds
  
Actual results:

Warning:: Picked up error in TriangleIntersect
   (330.151 57.2903 5445.48,    343.484 58.24 5672.46,  330.151 56.3407 5444.31)
  (nan,        nan,    nan)
Warning:: Picked up error in TriangleIntersect
   (343.484 58.24 5672.46,      343.484 57.2903 5672.07,        330.151 56.3407
5444.31)
   (nan,        nan,    nan)
Warning:: Picked up error in TriangleIntersect
   (330.151 56.3407 5444.31,    343.484 57.2903 5672.07,        330.151 55.391
5445.88)

etc, to infinity + memory usage runs up

Expected results:

Picture of terrain

Additional info:

Recompile OpenSceneGraph with either -g, or -O2, (not in combination), and the
viewer works. I traced this down to some code in
OpenSceneGraph/src/osgUtil/IntersectVisitor.cpp 

In line 532 and onward, the following is done:

532            TriangleFunctor<TriangleIntersect> ti;
533            ti.set(*sitr->second);
534            drawable.accept(ti);
534            if (ti._hit)

TriangleIntersect has two constructors, one with arguments, other without. The
template parameter of TriangleFunctor becomes its second parent. The 
"set" function initializes the ti object. In code compiled with a combination of
-O2 and -g, the call to the "set" function appears optimized out, and the object
is used with uninitialized data, resulting in the error. I have tried, but have
not been able to reproduce the error on a simpler file. 

Of course, the -g flag should not influence optimization. Apparently it does...
Comment 1 Rene van Paassen 2006-06-30 09:21:06 EDT
Created attachment 131806 [details]
example 3ds file for testing (from www.delta3d.org)
Comment 2 Jakub Jelinek 2006-07-17 14:56:29 EDT
Can you please attach preprocessed IntersectVisitor.ii (just replace
-c -O2 -g on the g++ command line with -E -O2 -g -o IntersectVisitor.ii)
and mention the exact command line options used to compile that file.
If -O2 works and -O2 -g doesn't (which would be really strange), it would be
detectable already at the .s level.
Comment 3 Rene van Paassen 2006-08-03 08:45:13 EDT
Created attachment 133550 [details]
Result after pre-processor stage

Prepared with following command:
g++ -g -O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables -W -Wall -fPIC -pipe -DOSGUTIL_LIBRARY
-I../../../include  -E -o IntersectVisitor.ii ../IntersectVisitor.cpp
Comment 4 Rene van Paassen 2006-11-28 04:15:44 EST
The problem is with OpenSceneGraph code, and strict aliasing rules in later
versions of gcc. osgviewer works correctly when compiled with -fno-strict-aliasing

Note You need to log in before you can comment on or make changes to this bug.