From: Ulrich Weigand Date: Sat, 1 May 2004 11:37:39 +0000 (+0000) Subject: re PR middle-end/15054 (Bad code due to overlapping stack temporaries) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e2655d15d9a2ae54844cd1adcba26dde3ba69cb9;p=gcc.git re PR middle-end/15054 (Bad code due to overlapping stack temporaries) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 445e736b053..85f3b6c7106 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-05-01 Ulrich Weigand + + 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 * simplify-rtx.c (simplify_ternary_operation): When diff --git a/gcc/expr.c b/gcc/expr.c index 9f246dcf6a3..c19741b1910 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -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); diff --git a/gcc/function.c b/gcc/function.c index b1f888f141f..8eeebfbe22d 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e8f8eedffb2..596e8ed4190 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-05-01 Ulrich Weigand + + PR middle-end/15054 + * g++.dg/opt/pr15054.C: New test. + 2004-04-30 Kaveh R. Ghazi * 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 index 00000000000..cfc48cf2498 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr15054.C @@ -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; +}