[Bug c++/17386] libstdc++ iostreams miscompilation

rth at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Sep 10 00:06:00 GMT 2004


------- Additional Comments From rth at gcc dot gnu dot org  2004-09-10 00:06 -------
The problem is that locale_init.cc is miscompiled.  Specifically, the
initialization of _ZN14__gnu_internal9num_put_cE in _ZNSt6locale5_ImplC2Ej
has two initializations of its vptr (fine), and the stores get interchanged
by the scheduler (not fine), because alias analysis sez that the stores do
not conflict.

A minimal test case is

struct A
{
  virtual void a();
  int x;
};
                                                                                
struct C : public A
{
  virtual void a();
};
                                                                                
inline void* operator new(__SIZE_TYPE__, void* __p) throw() { return __p; }
                                                                                
extern C obj;
                                                                                
void foo()
{
  new(&obj) C;
}

Examining the assembly at -O2 -fomit-frame-pointer we see

        movl    $_ZTV1A+8, obj
        movl    $_ZTV1C+8, obj
        ret

If alias analysis were working properly, we'd expect the first store to
be eliminated as dead.  By the rtl optimizer, at least, since we don't
do any field-level dead store elimination at the tree level at the moment.

The problem, I believe, is in the front end.  Looking at the last tree dump,

  obj.<D1575>._vptr.A = &_ZTV1A[2];
  obj._vptr.A = &_ZTV1C[2];

Obviously, the vptr field is at the same location in the base class as it
is in the derived class.  Yet we are accessing the field different ways.
I have not yet determined class C has a separate FIELD_DECL for this vptr,
or if we're simply applying the FIELD_DECL from class A to an object of
class C.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17386



More information about the Gcc-bugs mailing list