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 51deae8e4af56f5b79b517763de931de9149b5e6..2d1bbeaeb3a7604a2219accb429dc746b1cc01fd 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 424f68707ef5a61e1089ca0d02fe6866d2f7e739..52ccf1a2653c990cb0faa5a4f166b7260536531f 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 bea0c28ad4588b65303cdf3b87f30a8b6b931f91..4b6cfda5db2adc5c733b3d57087cac90fc91a758 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);