aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-strlen.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-09-14 03:34:19 +0000
committerJeff Law <law@gcc.gnu.org>2018-09-13 21:34:19 -0600
commit6ab24ea809555eeb869fe49595f22ed9c8737cc4 (patch)
treea6a98bb3c25e71934a2ae133c6e5116dcb9349b9 /gcc/tree-ssa-strlen.c
parentd01b568a78351beb6b693b613e6b48bcb2475eae (diff)
downloadgcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.zip
gcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.tar.gz
gcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.tar.bz2
builtins.h (c_srlen): Add argument.
* builtins.h (c_srlen): Add argument. * builtins.c (warn_string_no_nul): New function. (c_strlen): Add argument and use it. Update recursive calls. Pass DECL argument to string_constant to get info on non terminated strings. Update *NONSTR as needed. (fold_builtin_strlen): Add argument to calls to c_strlen. Warn for unterminated arrays. (warn_string_no_null): Add prototype. * expr.c (string_constant): Update arguments. Update recursive calls appropriately. Detect missing NUL terminator and outermost declaration its missing in. Improve checks for arrays with nonzero lower bound or elements that are not a single byte. Simplify offset computation. Simplify checks for non-NUL terminated strings. * gimple-fold.c (get_range_strlen): Add argument to c_strlen call. * gimple-ssa-sprintf.c (get_string_length): Remove unnecessary code. * gcc.dg/warn-strlen-no-nul.c: New test. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Co-Authored-By: Jeff Law <law@redhat.com> From-SVN: r264302
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r--gcc/tree-ssa-strlen.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index d625b94..3fa5ef5 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -291,8 +291,6 @@ get_addr_stridx (tree exp, tree ptr, unsigned HOST_WIDE_INT *offset_out)
static int
get_stridx (tree exp)
{
- tree s, o;
-
if (TREE_CODE (exp) == SSA_NAME)
{
if (ssa_ver_to_stridx[SSA_NAME_VERSION (exp)])
@@ -336,18 +334,10 @@ get_stridx (tree exp)
return idx;
}
- s = string_constant (exp, &o, NULL, NULL);
- if (s != NULL_TREE
- && (o == NULL_TREE || tree_fits_shwi_p (o))
- && TREE_STRING_LENGTH (s) > 0)
- {
- HOST_WIDE_INT offset = o ? tree_to_shwi (o) : 0;
- const char *p = TREE_STRING_POINTER (s);
- int max = TREE_STRING_LENGTH (s) - 1;
+ const char *p = c_getstr (exp);
+ if (p)
+ return ~(int) strlen (p);
- if (p[max] == '\0' && offset >= 0 && offset <= max)
- return ~(int) strlen (p + offset);
- }
return 0;
}