------- Comment #2 from jakub at gcc dot gnu dot org  2008-01-21 12:45 -------
Actually, only the diagnostics is a regression introduced by PR33025 fix.
Before that (but after PR29286 fix) at -O1 and higher cc1plus ICEd in
gimplify_expr and at -O0 it silently miscompiled e.g.:
typedef __SIZE_TYPE__ size_t;
extern "C" void abort ();

struct T
{
  void *operator new (size_t, char *&);
  T () { i[0] = 1; i[1] = 2; }
  int i[2];
};

void *T::operator new (size_t size, char *&p)
{
  void *o = (void *) p;
  p += size;
  return o;
}

T *f (char *&x)
{
  return new (x) T ();
}

int main ()
{
  char buf[10 * sizeof (T)] __attribute__((aligned (__alignof (T))));
  char *p = buf;
  f (p);
  if (p != buf + sizeof (T))
    abort ();
}

Here get_temp_regvar created a temporary for the placement expr and that
temporary was passed by reference to operator new.  That means only the
temporary
was modified, not the user variable.

Do we still need avoid_placement_new_aliasing stuff now that we have PR33407
fix in?  If yes, we either need to do replacement of the original expression
with
get_target_expr after build_new_method_call/build_operator_new_call (and
replace it both in the newly created argument list, in placement and
placement_expr, and only if the pointer was passed by value, not by reference),
or somehow undo this target_expr if a reference is needed.


-- 

jakub at gcc dot gnu dot org changed:

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


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

Reply via email to