re PR tree-optimization/71707 (ICE in get_stridx_plus_constant)
authorJakub Jelinek <jakub@redhat.com>
Thu, 30 Jun 2016 18:45:18 +0000 (20:45 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 30 Jun 2016 18:45:18 +0000 (20:45 +0200)
PR tree-optimization/71707
* tree-ssa-strlen.c (get_stridx_plus_constant): Handle already present
strinfo even for ADDR_EXPR ptr.

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

From-SVN: r237889

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

index 2b27fabe42242f03d5c1323bdbe071a3c80b85ea..7bdcb074cbad3998c9dcaee51174e3578fa44775 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-30  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/71707
+       * tree-ssa-strlen.c (get_stridx_plus_constant): Handle already present
+       strinfo even for ADDR_EXPR ptr.
+
 2016-06-30  Kelvin Nilsen  <kelvin@gcc.gnu.org>
 
        * config/rs6000/altivec.md (darn_32): Change the condition to
index 1f181dcc41491e78be76221572c6863c6e1d4c5e..ac86ece33e3f791ee30e97ce2d92a99647528ed7 100644 (file)
@@ -1,5 +1,8 @@
 2016-06-30  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/71707
+       * gcc.dg/strlenopt-29.c: New test.
+
        PR fortran/71704
        * gfortran.dg/gomp/pr71704.f90: New test.
 
diff --git a/gcc/testsuite/gcc.dg/strlenopt-29.c b/gcc/testsuite/gcc.dg/strlenopt-29.c
new file mode 100644 (file)
index 0000000..fb4b4c9
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR tree-optimization/71707 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fdump-tree-strlen" } */
+
+#include "strlenopt.h"
+
+char a[32];
+size_t b;
+
+__attribute__((noinline, noclone)) char *
+foo (void)
+{
+  char *p = memcpy (a, "a", 2) + 1;
+  memcpy (&a[1], "b", 2);
+  b = strlen (a) + strlen (&a[1]) + strlen (p);
+  return p;
+}
+
+int
+main ()
+{
+  if (foo () != &a[1] || b != 4)
+    abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } */
index 232594b92ab0e4d47e97f78a26a2f39e1745ee08..489c8f0c0d79d2285f51528c4cec770951ccc763 100644 (file)
@@ -677,8 +677,14 @@ get_stridx_plus_constant (strinfo *basesi, HOST_WIDE_INT off, tree ptr)
        {
          if (r == 0)
            {
-             gcc_assert (TREE_CODE (ptr) == SSA_NAME);
-             ssa_ver_to_stridx[SSA_NAME_VERSION (ptr)] = si->idx;
+             if (TREE_CODE (ptr) == SSA_NAME)
+               ssa_ver_to_stridx[SSA_NAME_VERSION (ptr)] = si->idx;
+             else
+               {
+                 int *pidx = addr_stridxptr (TREE_OPERAND (ptr, 0));
+                 if (pidx != NULL && *pidx == 0)
+                   *pidx = si->idx;
+               }
              return si->idx;
            }
          break;