Blob Blame History Raw
2004-05-01 Ulrich Weigand <weigand@de.ibm.com>

	PR middle-end/15054
	* expr.c (expand_expr_real): Do not call preserve_temp_slots 
	on a TARGET_EXPR temp.
	* function.c (assign_stack_temp_for_type): Set 'keep' flag for
	TARGET_EXPR temp slots.

	* g++.dg/opt/pr15054.C: New test.

2006-04-25  Jakub Jelinek  <jakub@redhat.com>

	* g++.dg/opt/pr15054-2.C: New test.

--- gcc/expr.c.orig	2006-02-24 04:51:46.000000000 -0300
+++ gcc/expr.c	2006-04-11 03:53:02.000000000 -0300
@@ -8676,8 +8676,6 @@ expand_expr (exp, target, tmode, modifie
 	    else
 	      {
 		target = assign_temp (type, 2, 0, 1);
-		/* All temp slots at this level must not conflict.  */
-		preserve_temp_slots (target);
 		SET_DECL_RTL (slot, target);
 		if (TREE_ADDRESSABLE (slot))
 		  put_var_into_stack (slot);
--- gcc/function.c.orig	2006-02-24 04:51:52.000000000 -0300
+++ gcc/function.c	2006-04-11 03:53:02.000000000 -0300
@@ -803,7 +803,7 @@ assign_stack_temp_for_type (mode, size, 
   if (keep == 2)
     {
       p->level = target_temp_slot_level;
-      p->keep = 0;
+      p->keep = 1;
     }
   else if (keep == 3)
     {
--- gcc/testsuite/g++.dg/opt/pr15054.C	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/opt/pr15054.C	2006-04-11 03:54:31.000000000 -0300
@@ -0,0 +1,36 @@
+// PR middle-end/15054
+// This used to abort due to overlapping stack temporaries.
+
+// { dg-do run }
+// { dg-options "-O" }
+
+extern "C" void abort (void);
+
+struct pointer
+{
+  void* ptr;
+
+  pointer(void* x = 0) : ptr(x) {}
+  pointer(const pointer& x) : ptr(x.ptr) {}
+};
+
+struct element
+{
+  int canary;
+
+  element() : canary(123) { }
+  ~element() { pointer(); if (canary != 123) abort (); }
+};
+
+inline pointer
+insert(const element& x)
+{
+  return pointer(new element(x));
+}
+
+int
+main (void)
+{
+  insert(element());
+  return 0;
+}
--- gcc/testsuite/g++.dg/opt/pr15054-2.C	2006-04-19 19:21:31.748476000 +0200
+++ gcc/testsuite/g++.dg/opt/pr15054-2.C	2006-04-25 15:55:07.000000000 +0200
@@ -0,0 +1,39 @@
+// PR middle-end/15054
+
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" void abort (void);
+
+void
+__attribute__((noinline))
+check (long x, long y)
+{
+  if (x != y)
+    abort ();
+}
+
+struct A
+{
+  A() : a(2) { check (a, 2); }
+  ~A() { check (a, 2); }
+private:
+  long a;
+};
+
+class B {
+  long b;
+  B& operator =(const B& );
+public:
+  B (long p) : b(p) { check (b, 6); }
+  B (const B& p) : b(p.b) { check (b, 6); }
+  ~B () { check (b, 6); A obj; check (b, 6); }
+  B foo() { return B(*this); }
+};
+
+int main ()
+{
+  B o(6);
+  o.foo().foo();
+  return 0;
+}