From 55a0f21aba28fac542ec1b092089140f00eec2ed Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 30 Jun 2016 20:45:18 +0200 Subject: [PATCH] re PR tree-optimization/71707 (ICE in get_stridx_plus_constant) 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 | 6 ++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/strlenopt-29.c | 27 +++++++++++++++++++++++++++ gcc/tree-ssa-strlen.c | 10 ++++++++-- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/strlenopt-29.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b27fabe422..7bdcb074cba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-06-30 Jakub Jelinek + + 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 * config/rs6000/altivec.md (darn_32): Change the condition to diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1f181dcc414..ac86ece33e3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2016-06-30 Jakub Jelinek + 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 index 00000000000..fb4b4c9cc71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/strlenopt-29.c @@ -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" } } */ diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 232594b92ab..489c8f0c0d7 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -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; -- 2.30.2