Hi!

Jason has added var ={v} {CLOBBER}; cleanup generation in the gimplifier,
unfortunately it works only for C++/Obj-C++, because other FEs don't add
the needed CLEANUP_POINT_EXPRs to the IL (because they don't use cleanups or
emit them differently).  Fixed by only adding the clobber cleanups
if inside of gimplification of some CLEANUP_POINT_EXPR.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2012-01-05  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/51761
        * gimple.h (struct gimplify_ctx): Add in_cleanup_point_expr
        field.
        * gimplify.c (gimplify_cleanup_point_expr): Save and set
        in_cleanup_point_expr before gimplify_stmt call and restore it
        afterwards.
        (gimplify_target_expr): Don't add {CLOBBER} cleanup if
        in_cleanup_point_expr is false.

        * gcc.c-torture/compile/pr51761.c: New test.

--- gcc/gimple.h.jj     2011-12-21 08:43:48.000000000 +0100
+++ gcc/gimple.h        2012-01-05 12:43:00.119573057 +0100
@@ -1092,6 +1092,7 @@ struct gimplify_ctx
   bool save_stack;
   bool into_ssa;
   bool allow_rhs_cond_expr;
+  bool in_cleanup_point_expr;
 };
 
 extern enum gimplify_status gimplify_expr (tree *, gimple_seq *, gimple_seq *,
--- gcc/gimplify.c.jj   2011-12-21 08:43:48.000000000 +0100
+++ gcc/gimplify.c      2012-01-05 12:45:34.567668259 +0100
@@ -5226,13 +5226,16 @@ gimplify_cleanup_point_expr (tree *expr_
      any cleanups collected outside the CLEANUP_POINT_EXPR.  */
   int old_conds = gimplify_ctxp->conditions;
   gimple_seq old_cleanups = gimplify_ctxp->conditional_cleanups;
+  bool old_in_cleanup_point_expr = gimplify_ctxp->in_cleanup_point_expr;
   gimplify_ctxp->conditions = 0;
   gimplify_ctxp->conditional_cleanups = NULL;
+  gimplify_ctxp->in_cleanup_point_expr = true;
 
   gimplify_stmt (&TREE_OPERAND (*expr_p, 0), &body_sequence);
 
   gimplify_ctxp->conditions = old_conds;
   gimplify_ctxp->conditional_cleanups = old_cleanups;
+  gimplify_ctxp->in_cleanup_point_expr = old_in_cleanup_point_expr;
 
   for (iter = gsi_start (body_sequence); !gsi_end_p (iter); )
     {
@@ -5408,7 +5411,8 @@ gimplify_target_expr (tree *expr_p, gimp
 
       /* Add a clobber for the temporary going out of scope, like
         gimplify_bind_expr.  */
-      if (needs_to_live_in_memory (temp))
+      if (gimplify_ctxp->in_cleanup_point_expr
+         && needs_to_live_in_memory (temp))
        {
          tree clobber = build_constructor (TREE_TYPE (temp), NULL);
          TREE_THIS_VOLATILE (clobber) = true;
--- gcc/testsuite/gcc.c-torture/compile/pr51761.c.jj    2012-01-05 
12:54:42.933557579 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr51761.c       2012-01-05 
12:55:07.864411771 +0100
@@ -0,0 +1,10 @@
+/* PR middle-end/51761 */
+
+struct S { unsigned int len; };
+struct S foo (struct S);
+
+struct S
+bar (struct S x)
+{
+  return ({ struct S a = x; foo (a); });
+}

        Jakub

Reply via email to