diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-12-09 17:55:35 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2008-12-09 17:55:35 +0100 |
commit | bab4e8fbed8e7d10eb9c99635d513b3ee4197db0 (patch) | |
tree | e1fc6db592f653e87c5ae59795210387846d1c3f /gcc | |
parent | b3b30b2401e192a42d4a75728dd198223573dd81 (diff) | |
download | gcc-bab4e8fbed8e7d10eb9c99635d513b3ee4197db0.zip gcc-bab4e8fbed8e7d10eb9c99635d513b3ee4197db0.tar.gz gcc-bab4e8fbed8e7d10eb9c99635d513b3ee4197db0.tar.bz2 |
re PR tree-optimization/35468 (LHS of assignment can be folded to a constant causing ICE)
PR tree-optimization/35468
* 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.
From-SVN: r142598
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr35468.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr35468.c | 10 | ||||
-rw-r--r-- | gcc/tree-ssa-ccp.c | 9 |
5 files changed, 36 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ae10870..9c9ad1f1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 07c5eb0..7cb6b4f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..16d064b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr35468.c @@ -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 index 0000000..085c073 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr35468.c @@ -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; +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 82933f8..0908d54 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -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; |