re PR tree-optimization/57230 (tree-ssa-strlen incorrectly optimizes a strlen to 0)
authorJakub Jelinek <jakub@redhat.com>
Mon, 13 May 2013 07:46:53 +0000 (09:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 13 May 2013 07:46:53 +0000 (09:46 +0200)
PR tree-optimization/57230
* tree-ssa-strlen.c (handle_char_store): Add missing integer_zerop
check.

* gcc.dg/strlenopt-23.c: New test.

From-SVN: r198813

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/strlenopt-23.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c

index 51deae8..2d1bbea 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/57230
+       * tree-ssa-strlen.c (handle_char_store): Add missing integer_zerop
+       check.
+
 2013-05-12  Joern Rennecke  <joern.rennecke@embecosm.com>
 
        * config/epiphany/epiphany.c (epiphany_init): Check size of
index 424f687..52ccf1a 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/57230
+       * gcc.dg/strlenopt-23.c: New test.
+
 2013-05-12  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/57108
diff --git a/gcc/testsuite/gcc.dg/strlenopt-23.c b/gcc/testsuite/gcc.dg/strlenopt-23.c
new file mode 100644 (file)
index 0000000..75dab2a
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/57230 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include "strlenopt.h"
+
+int
+main ()
+{
+  char p[] = "hello world";
+  p[0] = (char) (strlen (p) - 1);
+  if (strlen (p) != 11)
+    abort ();
+  return 0;
+}
index bea0c28..4b6cfda 100644 (file)
@@ -1703,7 +1703,7 @@ handle_char_store (gimple_stmt_iterator *gsi)
               its length may be decreased.  */
            adjust_last_stmt (si, stmt, false);
        }
-      else if (si != NULL)
+      else if (si != NULL && integer_zerop (gimple_assign_rhs1 (stmt)))
        {
          si = unshare_strinfo (si);
          si->length = build_int_cst (size_type_node, 0);