From b3c3685ab0e11c79ad5673728f664495b23385d5 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 27 Oct 2011 21:04:43 +0200 Subject: [PATCH] tree-ssa-strlen.c: Include expr.h. * tree-ssa-strlen.c: Include expr.h. (get_stridx): Don't use c_strlen, instead use string_constant and compute string length from it. * Makefile.in (tree-ssa-strlen.o): Depend on $(EXPR_H). From-SVN: r180574 --- gcc/ChangeLog | 7 +++++++ gcc/Makefile.in | 2 +- gcc/tree-ssa-strlen.c | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 297192b..cc6dec0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-10-27 Jakub Jelinek + + * tree-ssa-strlen.c: Include expr.h. + (get_stridx): Don't use c_strlen, instead use string_constant + and compute string length from it. + * Makefile.in (tree-ssa-strlen.o): Depend on $(EXPR_H). + 2011-10-27 Eric Botcazou PR rtl-optimization/46603 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index ed6e31b..600fc27 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -3173,7 +3173,7 @@ tree-ssa-ccp.o : tree-ssa-ccp.c $(TREE_FLOW_H) $(CONFIG_H) \ $(DBGCNT_H) tree-pretty-print.h gimple-pretty-print.h gimple-fold.h tree-ssa-strlen.o : tree-ssa-strlen.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TREE_FLOW_H) $(TREE_PASS_H) domwalk.h alloc-pool.h tree-ssa-propagate.h \ - gimple-pretty-print.h $(PARAMS_H) + gimple-pretty-print.h $(PARAMS_H) $(EXPR_H) tree-sra.o : tree-sra.c $(CONFIG_H) $(SYSTEM_H) coretypes.h alloc-pool.h \ $(TM_H) $(TREE_H) $(GIMPLE_H) $(CGRAPH_H) $(TREE_FLOW_H) \ $(IPA_PROP_H) $(DIAGNOSTIC_H) statistics.h $(TREE_DUMP_H) $(TIMEVAR_H) \ diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 72da15e..a37633a 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-propagate.h" #include "gimple-pretty-print.h" #include "params.h" +#include "expr.h" /* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value is an index into strinfo vector, negative value stands for @@ -176,7 +177,7 @@ get_addr_stridx (tree exp) static int get_stridx (tree exp) { - tree l; + tree s, o; if (TREE_CODE (exp) == SSA_NAME) return VEC_index (int, ssa_ver_to_stridx, SSA_NAME_VERSION (exp)); @@ -188,14 +189,17 @@ get_stridx (tree exp) return idx; } - l = c_strlen (exp, 0); - if (l != NULL_TREE - && host_integerp (l, 1)) + s = string_constant (exp, &o); + if (s != NULL_TREE + && (o == NULL_TREE || host_integerp (o, 0)) + && TREE_STRING_LENGTH (s) > 0) { - unsigned HOST_WIDE_INT len = tree_low_cst (l, 1); - if (len == (unsigned int) len - && (int) len >= 0) - return ~(int) len; + HOST_WIDE_INT offset = o ? tree_low_cst (o, 0) : 0; + const char *p = TREE_STRING_POINTER (s); + int max = TREE_STRING_LENGTH (s) - 1; + + if (p[max] == '\0' && offset >= 0 && offset <= max) + return ~(int) strlen (p + offset); } return 0; } -- 2.7.4