https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63459

            Bug ID: 63459
           Summary: operator new and returns_nonnull
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org

compinling:

struct A {
   virtual int foo(){return 1;}
};
struct B {
   virtual int bar(){return 4;}
};
struct C:B,A {
   virtual int foo(){return 2;}
};
static void
test (struct A *a)
{
  if (a->foo() != 2)
   __builtin_abort ();
}
int
m()
{
  struct A *a = new C;
  test (a);
  return 0;
}

Leads to:
int m() ()
{
  struct A * a;
  void * _4;
  struct A * iftmp.0_6;

  <bb 2>:
  _4 = operator new (16);
  C::C (_4);
  if (_4 != 0B)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  iftmp.0_6 = &MEM[(struct C *)_4].D.2251;

  <bb 4>:
  # a_1 = PHI <iftmp.0_6(3), 0B(2)>
  test (a_1);
  return 0;

}

in release_ssa dump.  It would be nice to use the fact that the default
operator new throw exception instead of returning NULL in out of memory case.

Can optimizer make assumption that THIS parameter to a method call is always
not NULL?

Reply via email to