===================================================================
@@ -1690,6 +1690,36 @@ evaluate_stmt (gimple stmt)
return val;
}
+/* Try to find a BUILT_IN_STACK_RESTORE after gsi_stmt (I) and insert a clobber
+ of T before it. */
+
+static void
+insert_clobber_before_stack_restore (gimple_stmt_iterator i, tree t)
+{
+ bool found = false;
+ tree clobber;
+
+ for (; !gsi_end_p (i); gsi_next (&i))
+ {
+ gimple stmt = gsi_stmt (i);
+
+ if (!gimple_call_builtin_p (stmt, BUILT_IN_STACK_RESTORE))
+ continue;
+
+ found = true;
+ break;
+ }
+
+ /* We should try harder, but for now, just return. */
+ if (!found)
+ return;
+
+ clobber = build_constructor (TREE_TYPE (t), NULL);
+ TREE_THIS_VOLATILE (clobber) = 1;
+ gsi_insert_before (&i, gimple_build_assign (t, clobber),
+ GSI_SAME_STMT);
+}
+
/* Detects a __builtin_alloca_with_align with constant size argument. Declares
fixed-size array and returns the address, if found, otherwise returns
NULL_TREE. */
@@ -1824,7 +1854,9 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi
if (new_rhs)
{
bool res = update_call_from_tree (gsi, new_rhs);
+ tree var = TREE_OPERAND (TREE_OPERAND (new_rhs, 0),0);
gcc_assert (res);
+ insert_clobber_before_stack_restore (*gsi, var);
return true;
}
}
===================================================================
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+
+int g(int*);
+
+int f(void)
+{
+ int tt = 0;
+ int t = 4;
+ {
+ int a[t];
+ tt = g(a);
+ tt += a[0];
+ }
+ {
+ int a[4];
+ tt += g(a);
+ tt += a[0];
+ }
+ return tt;
+}
+
+/* { dg-final { scan-rtl-dump-times "Partition" 1 "expand"} } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */