re PR middle-end/15054 (Bad code due to overlapping stack temporaries)
authorUlrich Weigand <uweigand@de.ibm.com>
Sat, 1 May 2004 11:37:39 +0000 (11:37 +0000)
committerUlrich Weigand <uweigand@gcc.gnu.org>
Sat, 1 May 2004 11:37:39 +0000 (11:37 +0000)
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.

PR middle-end/15054
* g++.dg/opt/pr15054.C: New test.

From-SVN: r81384

gcc/ChangeLog
gcc/expr.c
gcc/function.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr15054.C [new file with mode: 0644]

index 445e736b053fd32ef7228c0bd2bf7b98db61e28e..85f3b6c71067ec4689ae4ba2a89336026ba6f001 100644 (file)
@@ -1,3 +1,11 @@
+2004-05-01  Ulrich Weigand  <uweigand@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.
+
 2004-05-01  Paolo Bonzini  <bonzini@gnu.org>
 
        * simplify-rtx.c (simplify_ternary_operation): When
index 9f246dcf6a3ac3710a5403ecb4686b0afd4e3ab5..c19741b1910defe18385c7cfbf452fa636f02536 100644 (file)
@@ -8537,8 +8537,6 @@ expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
            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, /*rescan=*/false);
index b1f888f141f9e28641454a9c99f92a9f199cfa01..8eeebfbe22d047069cb315d3b677bc7141284d37 100644 (file)
@@ -780,7 +780,7 @@ assign_stack_temp_for_type (enum machine_mode mode, HOST_WIDE_INT size, int keep
   if (keep == 2)
     {
       p->level = target_temp_slot_level;
-      p->keep = 0;
+      p->keep = 1;
     }
   else if (keep == 3)
     {
index e8f8eedffb2f1ca7941c210780786e8957a47427..596e8ed41907cd6c5b4508ad51736a61b670c179 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-01  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       PR middle-end/15054
+       * g++.dg/opt/pr15054.C: New test.
+
 2004-04-30  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/torture/builtin-rounding-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/opt/pr15054.C b/gcc/testsuite/g++.dg/opt/pr15054.C
new file mode 100644 (file)
index 0000000..cfc48cf
--- /dev/null
@@ -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;
+}