This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Aliasing problem? gcc-3.3 miscompiles mozilla-1.4


Hi Franz,

This is my first shot at a simple testcase but I can not get it to compile 
yet.

Hopefully one of you can modify this and make use of it.

Hope this helps,

Kevin

#include <cstdlib>
#include <cstdio>

template <class T>
struct already_AddRefed
  {
    already_AddRefed( T* aRawPtr )
        : mRawPtr(aRawPtr)
      {

      }

    T* get() const { return mRawPtr; }

    T* mRawPtr;
  };



template <class T>
inline
const already_AddRefed<T>
getter_AddRefs( T* aRawPtr )
  {
    return already_AddRefed<T>(aRawPtr);
  }



template <class T>
inline
const already_AddRefed<T>
getter_AddRefs( const already_AddRefed<T> aAlreadyAddRefedPtr )
  {
    return aAlreadyAddRefedPtr;
  }



class mc0 {
public:
  int hello;
  int setHello(int j) { hello = j; }
};

class mc1 : public mc0 {
 public:
  virtual int SetMutable(int) = 0;
};


class mc2 : public mc1 {
public:
  int SetMutable(int k) { setHello(k); }
};

int
main(int argc, char** argv)
{

    // worlds simplest container class
    mc0* aFrames[1];

   // create our instance of this class
   // note gfxIImageFrame is a pure virtual class
    mc2* myframe;

    aFrames[0]=static_cast<mc0*> (&myframe);

    // now create a local copy of this frame
    mc2* currentFrame;

    // use the template class trick to get the address of our local copy
    mc2** retval = getter_AddRefs(currentFrame);

   // now read from the container and copy it to the address from above
    mc0* _elem = aFrames[0];
    *retval = static_cast< mc2* >(_elem);

   // now invoke that instances SetMutable and get the instant segfault
    currentFrame->SetMutable(0);

    fprintf(stderr,"done\n"); fflush(stderr);
    return 0;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]