diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-10-27 19:04:43 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-10-27 19:04:43 +0000 |
commit | 7c1542207cac8cff9283c42b1dffd19e07eb50af (patch) | |
tree | 56195b1d9984506fd5e4184d26654edacf22069c /gcc/tree-ssa-strlen.c | |
parent | 99bef0c58255ed32d26b45fe82ab62ef67208408 (diff) | |
download | gcc-7c1542207cac8cff9283c42b1dffd19e07eb50af.tar.gz |
* 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).
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180574 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 72da15e9893..a37633a920f 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; } |