re PR middle-end/79089 (error: incorrect sharing of tree nodes)
authorJakub Jelinek <jakub@redhat.com>
Mon, 16 Jan 2017 21:35:30 +0000 (22:35 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 16 Jan 2017 21:35:30 +0000 (22:35 +0100)
PR c/79089
* gimplify.c (gimplify_init_constructor): If want_value and
object == lhs, unshare lhs to avoid invalid tree sharing.  Formatting
fix.

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

From-SVN: r244507

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr79089.c [new file with mode: 0644]

index cc2e1d0c9f08639c21a444ed567be7c90b6cd7c6..70f200be883178e5e1ea1ccbfebe5a6a34574d3f 100644 (file)
@@ -1,5 +1,10 @@
 2017-01-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/79089
+       * gimplify.c (gimplify_init_constructor): If want_value and
+       object == lhs, unshare lhs to avoid invalid tree sharing.  Formatting
+       fix.
+
        PR target/79080
        * loop-doloop.c (doloop_modify): Call unshare_all_rtl_in_chain on
        sequence.  Formatting fixes.
index e1e9ce9e903049b8fdcfda453455000a4e0c7610..2777a23eb937f896d7dc87fba364fadb96fca6df 100644 (file)
@@ -4586,8 +4586,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
     }
 
   object = TREE_OPERAND (*expr_p, 0);
-  ctor = TREE_OPERAND (*expr_p, 1) =
-    optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
+  ctor = TREE_OPERAND (*expr_p, 1)
+    optimize_compound_literals_in_ctor (TREE_OPERAND (*expr_p, 1));
   type = TREE_TYPE (ctor);
   elts = CONSTRUCTOR_ELTS (ctor);
   ret = GS_ALL_DONE;
@@ -4911,6 +4911,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
     {
       tree lhs = TREE_OPERAND (*expr_p, 0);
       tree rhs = TREE_OPERAND (*expr_p, 1);
+      if (want_value && object == lhs)
+       lhs = unshare_expr (lhs);
       gassign *init = gimple_build_assign (lhs, rhs);
       gimplify_seq_add_stmt (pre_p, init);
     }
index 2ac159733c47cb2c23afd586572dae8fc26bd548..ef1fea51a877f1e040ee549f1437cbc40fca8b5d 100644 (file)
@@ -1,5 +1,8 @@
 2017-01-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/79089
+       * gcc.c-torture/compile/pr79089.c: New test.
+
        PR target/79080
        * gcc.dg/pr79080.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr79089.c b/gcc/testsuite/gcc.c-torture/compile/pr79089.c
new file mode 100644 (file)
index 0000000..5237988
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR c/79089 */
+
+struct S { int b; };
+struct T { struct S c; } a;
+int d;
+struct S e;
+
+void
+foo ()
+{
+  e = ({ d++; a.c = (struct S) {}; });
+}