[Bug ipa/60963] [4.10 Regression] wrong devirt with placement new

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 25 12:33:00 GMT 2014


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-25
            Summary|ubsan runtime error: load   |[4.10 Regression] wrong
                   |of null pointer of type     |devirt with placement new
                   |'<unknown> *'               |
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
#include <new>

extern "C" void abort (void);

class EmbeddedObject {
public:
    virtual int val() { return 2; }
};

class Container {
    alignas(EmbeddedObject) char buffer[sizeof(EmbeddedObject)];
public:
    EmbeddedObject *obj() { return (EmbeddedObject*)buffer; }
    Container() { new (buffer) EmbeddedObject(); }
};

Container o;

int main()
{
  if (o.obj()->val() != 2)
    abort ();
}

It's interesting how the gcc_unreachable () makes writing a testcase that
aborts almost impossible (the above doesn't work, nor if I move the call
into a separate non-inlined function ...).



More information about the Gcc-bugs mailing list