OSDN Git Service

PR tree-optimization/21610
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 May 2005 06:45:49 +0000 (06:45 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 May 2005 06:45:49 +0000 (06:45 +0000)
* c-typeck.c (decl_constant_value_for_broken_optimization): If not
returning DECL, call unshare_expr.

* gcc.c-torture/compile/20050516-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@99815 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20050516-1.c [new file with mode: 0644]

index 7bab281..99e0108 100644 (file)
@@ -1,3 +1,9 @@
+2005-05-17  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.
+
 2005-05-17  Hans-Peter Nilsson  <hp@axis.com>
 
        * config/cris/cris.md: Unquote preparation and output statements.
index 806a20a..b96328d 100644 (file)
@@ -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;
 }
 
 
index 2e99a36..e691174 100644 (file)
@@ -1,5 +1,8 @@
 2005-05-17  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/21610
+       * gcc.c-torture/compile/20050516-1.c: New test.
+
        PR fortran/15080
        * gfortran.fortran-torture/execute/forall_3.f90: Remove comment
        about the test failing.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20050516-1.c b/gcc/testsuite/gcc.c-torture/compile/20050516-1.c
new file mode 100644 (file)
index 0000000..2cdf696
--- /dev/null
@@ -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;
+}