Bug 12484 - virtual function yields bogus value when returning float constant (-O3 -fPIC)
Summary: virtual function yields bogus value when returning float constant (-O3 -fPIC)
Status: RESOLVED DUPLICATE of bug 10877
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-01 19:00 UTC by jonathan
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

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


Attachments
source code reproducing bug (280 bytes, text/plain)
2003-10-01 19:02 UTC, jonathan
Details
output from command g++ -v -save-temps (637 bytes, text/plain)
2003-10-01 19:03 UTC, jonathan
Details
preprocessed file (89.81 KB, application/octet-stream)
2003-10-01 19:05 UTC, jonathan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jonathan 2003-10-01 19:00:14 UTC
here's the code to reproduce the error...

//----
#include <iostream>

class Foo
{
public:
  Foo() : _value(1) {}
  virtual ~Foo() {}

  virtual float getValue() const { return float(1); }
  virtual float getMemberValue() const { return _value; }

private:
  float const _value;
};


void
useFoo(Foo const &f)
{

  std::cout << std::endl
	    << "Foo const &f; " 
	    << std::endl;

  std::cout << " f.getValue() = " 
	    << f.getValue()
	    << std::endl;

  std::cout << " f.getMemberValue() = " 
	    << f.getMemberValue()
	    << std::endl;
}



int
main()
{
  Foo foo;

  std::cout << std::endl
	    << "Foo foo; " 
	    << std::endl;

  std::cout << " foo.getValue() = " 
	    << foo.getValue()
	    << std::endl;

  std::cout << " foo.getMemberValue() = " 
	    << foo.getMemberValue()
	    << std::endl;

  useFoo(foo);

}
//---

note:

1) problem occurs with -O3 and -fPI; dropping to -O2 and/or omitting -fPIC
eliminates problem

2) bogus results occur only when returning constant (e.g. return float(1); );
returning member data is o.k. (e.g. return _value)

3) bogus results occur only when given const reference to object having virtual
member; seems to work o.k. given the object itself

4) g++ 3.3.1 gives same behavior
Comment 1 jonathan 2003-10-01 19:02:45 UTC
Created attachment 4877 [details]
source code reproducing bug
Comment 2 jonathan 2003-10-01 19:03:48 UTC
Created attachment 4878 [details]
output from command g++ -v -save-temps
Comment 3 jonathan 2003-10-01 19:05:31 UTC
Created attachment 4879 [details]
preprocessed file
Comment 4 Andrew Pinski 2003-10-01 19:06:28 UTC
What version of binutils are you using?
Also what target are you using, i686-pc-linux?
If so read < http://gcc.gnu.org/install/specific.html#ix86-*-linux* >: As of GCC 3.3, binutils 
2.13.1 or later is required for this platform.  See bug 10877 for more information.
Comment 5 jonathan 2003-10-01 19:56:43 UTC
yes, i'm using target i686-pc-linux.

the box where i first detected the problem uses binutils 2.11.93.0.2 20020207
jmw@vulcan:115>ld --version
GNU ld version 2.11.93.0.2 20020207

we have another machine using binutils 2.13.90.0.2 20020802
jmw@eric:16>ld --version
GNU ld version 2.13.90.0.2 20020802

this problem appears to be resolved when using the latter version of binutils.

thanks for your help.


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