aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2018-09-29 10:06:09 -0600
committerJeff Law <law@gcc.gnu.org>2018-09-29 10:06:09 -0600
commit7d583f4259a56c9054c28e883c375f9c57f8755d (patch)
tree797b7466a6780a7072c673f67d18031bf368e779 /gcc/gimple-fold.c
parent23bce99cbe7016a04e14c2163ed3fe6a5a64f4e2 (diff)
downloadgcc-7d583f4259a56c9054c28e883c375f9c57f8755d.zip
gcc-7d583f4259a56c9054c28e883c375f9c57f8755d.tar.gz
gcc-7d583f4259a56c9054c28e883c375f9c57f8755d.tar.bz2
builtins.c (unterminated_array): Pass in c_strlen_data * to c_strlen rather than just a tree *.
* builtins.c (unterminated_array): Pass in c_strlen_data * to c_strlen rather than just a tree *. (c_strlen): Change NONSTR argument to a c_strlen_data pointer. Update recursive calls appropriately. If caller did not provide a suitable data pointer, create a local one. When a non-terminated string is discovered, bubble up information about the string via the c_strlen_data object. * builtins.h (c_strlen): Update prototype. (c_strlen_data): New structure. * gimple-fold.c (get_range_strlen): Update calls to c_strlen. For a type 2 call, if c_strlen indicates a non-terminated string use the length of the non-terminated string. (gimple_fold_builtin_stpcpy): Update calls to c_strlen. From-SVN: r264712
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 1e84722..cf04c92 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1337,7 +1337,23 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
return false;
}
else
- val = c_strlen (arg, 1, nonstr, eltsize);
+ {
+ c_strlen_data data;
+ memset (&data, 0, sizeof (c_strlen_data));
+ val = c_strlen (arg, 1, &data, eltsize);
+
+ /* If we potentially had a non-terminated string, then
+ bubble that information up to the caller. */
+ if (!val)
+ {
+ *nonstr = data.decl;
+ /* If TYPE is asking for a maximum, then use any
+ length (including the length of an unterminated
+ string) for VAL. */
+ if (type == 2)
+ val = data.len;
+ }
+ }
if (!val && fuzzy)
{
@@ -2812,21 +2828,22 @@ gimple_fold_builtin_stpcpy (gimple_stmt_iterator *gsi)
}
/* Set to non-null if ARG refers to an unterminated array. */
- tree nonstr = NULL;
- tree len = c_strlen (src, 1, &nonstr, 1);
+ c_strlen_data data;
+ memset (&data, 0, sizeof (c_strlen_data));
+ tree len = c_strlen (src, 1, &data, 1);
if (!len
|| TREE_CODE (len) != INTEGER_CST)
{
- nonstr = unterminated_array (src);
- if (!nonstr)
+ data.decl = unterminated_array (src);
+ if (!data.decl)
return false;
}
- if (nonstr)
+ if (data.decl)
{
/* Avoid folding calls with unterminated arrays. */
if (!gimple_no_warning_p (stmt))
- warn_string_no_nul (loc, "stpcpy", src, nonstr);
+ warn_string_no_nul (loc, "stpcpy", src, data.decl);
gimple_set_no_warning (stmt, true);
return false;
}