This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Avoid unwanted tree sharing (PR tree-optimization/21610)


Hi!

The testcase below causes ICE in make_decl_rtl.
The problem seems to be tree sharing.
decl_constant_value_for_broken_optimization returns DECL_INITIAL(p)
as is, then gimplifier modifies the tree in place (replaces the
0x4000 INTEGER_CST with a temporary automatic variable), then SSA_NAME.
On HEAD (where the testcase doesn't crash), it is later on replaced
in place with the 0x4000 INTEGER_CST again, but on 4.0 branch a new tree is
created, so when assemble_variable is called later on, it sees foo's
automatic variables in it.
As decl_constant_value will not return CONSTRUCTORs, I hope the following
fix does not cause noticable memory requirement increase and certainly
fixes the bug I was seeing.

Ok to commit if bootstrap/regtesting succeeds?  4.0 as well?

2005-05-16  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/21610
	* c-typeck.c (decl_constant_value_for_broken_optimization): If not
	returning DECL, call unshare_expr.

--- gcc/c-typeck.c.jj	2005-05-16 09:44:21.000000000 +0200
+++ gcc/c-typeck.c	2005-05-16 20:48:12.000000000 +0200
@@ -1249,10 +1249,18 @@ decl_constant_value (tree decl)
 static tree
 decl_constant_value_for_broken_optimization (tree decl)
 {
+  tree ret;
+
   if (pedantic || DECL_MODE (decl) == BLKmode)
     return decl;
-  else
-    return decl_constant_value (decl);
+
+  ret = decl_constant_value (decl);
+  /* Avoid unwanted tree sharing between the initializer and current
+     function's body where the tree can be modified e.g. by the
+     gimplifier.  */
+  if (ret != decl && TREE_STATIC (decl))
+    ret = unshare_expr (ret);
+  return ret;
 }
 
 
--- gcc/testsuite/gcc.c-torture/compile/20050516-1.c.jj	2005-05-16 20:51:37.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/compile/20050516-1.c	2005-05-16 20:51:02.000000000 +0200
@@ -0,0 +1,12 @@
+/* PR tree-optimization/21610 */
+
+struct S { char s; };
+struct T { struct S t; };
+
+struct S *const p = &((struct T * const) (0x4000))->t;
+
+void
+foo (void)
+{
+  p->s = 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]