OSDN Git Service

PR tree-optimization/35468
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Dec 2008 16:55:35 +0000 (16:55 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Dec 2008 16:55:35 +0000 (16:55 +0000)
* tree-ssa-ccp.c (fold_stmt_r): Don't fold reads from constant
string on LHS.

* gcc.dg/pr35468.c: New test.
* gcc.c-torture/compile/pr35468.c: New test.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr35468.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr35468.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index ae10870..9c9ad1f 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/35468
+       * tree-ssa-ccp.c (fold_stmt_r): Don't fold reads from constant
+       string on LHS.
+
 2008-12-09  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/38445
index 07c5eb0..7cb6b4f 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/35468
+       * gcc.dg/pr35468.c: New test.
+       * gcc.c-torture/compile/pr35468.c: New test.
+
 2008-12-08  Jason Merrill  <jason@redhat.com>
 
        PR c++/38410
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr35468.c b/gcc/testsuite/gcc.c-torture/compile/pr35468.c
new file mode 100644 (file)
index 0000000..16d064b
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR tree-optimization/35468 */
+
+void
+foo (void)
+{
+  *(char *) "c" = 'x';
+}
diff --git a/gcc/testsuite/gcc.dg/pr35468.c b/gcc/testsuite/gcc.dg/pr35468.c
new file mode 100644 (file)
index 0000000..085c073
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR tree-optimization/35468 */
+/* { dg-do compile  }*/
+/* { dg-options "-O2 -fno-tree-dce" } */
+
+char *const f(void)
+{
+  char *const line = "/dev/ptyXX";
+  line[8] = 1;
+  return line;
+}
index 82933f8..0908d54 100644 (file)
@@ -2191,6 +2191,9 @@ fold_stmt_r (tree *expr_p, int *walk_subtrees, void *data)
 
       t = maybe_fold_stmt_indirect (expr, TREE_OPERAND (expr, 0),
                                    integer_zero_node);
+      /* Avoid folding *"abc" = 5 into 'a' = 5.  */
+      if (wi->is_lhs && t && TREE_CODE (t) == INTEGER_CST)
+       t = NULL_TREE;
       if (!t
          && TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR)
        /* If we had a good reason for propagating the address here,
@@ -2219,8 +2222,10 @@ fold_stmt_r (tree *expr_p, int *walk_subtrees, void *data)
         Otherwise we'd be wasting time.  */
     case ARRAY_REF:
       /* If we are not processing expressions found within an
-        ADDR_EXPR, then we can fold constant array references.  */
-      if (!*inside_addr_expr_p)
+        ADDR_EXPR, then we can fold constant array references.
+        Don't fold on LHS either, to avoid folding "abc"[0] = 5
+        into 'a' = 5.  */
+      if (!*inside_addr_expr_p && !wi->is_lhs)
        t = fold_read_from_constant_string (expr);
       else
        t = NULL;