Commit e09aa5bd by Martin Sebor Committed by Jeff Law

builtins.c (unterminated_array): Rename "data" to "lendata".

	* builtins.c (unterminated_array): Rename "data" to "lendata".  Fix
	a few comments.
	(expand_builtin_strnlen, expand_builtin_stpcpy_1): Likewise.
	(fold_builtin_strlen): Likewise.
	* gimple-fold.c (get_range_strlen): Likewise.  Also rename a couple
	instances of "type" to "optype" and "arg" to "fld".

Co-Authored-By: Jeff Law <law@redhat.com>

From-SVN: r267377
parent 3f46ef1f
2018-12-23 Martin Sebor <msebor@redhat.com> 2018-12-23 Martin Sebor <msebor@redhat.com>
Jeff Law <law@redhat.com> Jeff Law <law@redhat.com>
* builtins.c (unterminated_array): Rename "data" to "lendata". Fix
a few comments.
(expand_builtin_strnlen, expand_builtin_stpcpy_1): Likewise.
(fold_builtin_strlen): Likewise.
* gimple-fold.c (get_range_strlen): Likewise. Also rename a couple
instances of "type" to "optype" and "arg" to "fld".
* builtins.c (unterminated_array): Use empty brace initialization * builtins.c (unterminated_array): Use empty brace initialization
for c_strlen_data. for c_strlen_data.
(c_strlen, expand_builtin_strnlen): Likewise. (c_strlen, expand_builtin_strnlen): Likewise.
...@@ -575,25 +575,25 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */) ...@@ -575,25 +575,25 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */)
{ {
/* C_STRLEN will return NULL and set DECL in the info /* C_STRLEN will return NULL and set DECL in the info
structure if EXP references a unterminated array. */ structure if EXP references a unterminated array. */
c_strlen_data data = { }; c_strlen_data lendata = { };
tree len = c_strlen (exp, 1, &data); tree len = c_strlen (exp, 1, &lendata);
if (len == NULL_TREE && data.len && data.decl) if (len == NULL_TREE && lendata.len && lendata.decl)
{ {
if (size) if (size)
{ {
len = data.len; len = lendata.len;
if (data.off) if (lendata.off)
{ {
/* Constant offsets are already accounted for in data.len, but /* Constant offsets are already accounted for in LENDATA.MINLEN,
not in a SSA_NAME + CST expression. */ but not in a SSA_NAME + CST expression. */
if (TREE_CODE (data.off) == INTEGER_CST) if (TREE_CODE (lendata.off) == INTEGER_CST)
*exact = true; *exact = true;
else if (TREE_CODE (data.off) == PLUS_EXPR else if (TREE_CODE (lendata.off) == PLUS_EXPR
&& TREE_CODE (TREE_OPERAND (data.off, 1)) == INTEGER_CST) && TREE_CODE (TREE_OPERAND (lendata.off, 1)) == INTEGER_CST)
{ {
/* Subtract the offset from the size of the array. */ /* Subtract the offset from the size of the array. */
*exact = false; *exact = false;
tree temp = TREE_OPERAND (data.off, 1); tree temp = TREE_OPERAND (lendata.off, 1);
temp = fold_convert (ssizetype, temp); temp = fold_convert (ssizetype, temp);
len = fold_build2 (MINUS_EXPR, ssizetype, len, temp); len = fold_build2 (MINUS_EXPR, ssizetype, len, temp);
} }
...@@ -605,7 +605,7 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */) ...@@ -605,7 +605,7 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */)
*size = len; *size = len;
} }
return data.decl; return lendata.decl;
} }
return NULL_TREE; return NULL_TREE;
...@@ -3083,8 +3083,8 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) ...@@ -3083,8 +3083,8 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
/* FIXME: Change c_strlen() to return sizetype instead of ssizetype /* FIXME: Change c_strlen() to return sizetype instead of ssizetype
so these conversions aren't necessary. */ so these conversions aren't necessary. */
c_strlen_data data { }; c_strlen_data lendata = { };
tree len = c_strlen (src, 0, &data, 1); tree len = c_strlen (src, 0, &lendata, 1);
if (len) if (len)
len = fold_convert_loc (loc, TREE_TYPE (bound), len); len = fold_convert_loc (loc, TREE_TYPE (bound), len);
...@@ -3106,12 +3106,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) ...@@ -3106,12 +3106,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
strnlen (&a[i], sizeof a) strnlen (&a[i], sizeof a)
where the value of i is unknown. Unless i's value is where the value of i is unknown. Unless i's value is
zero, the call is unsafe because the bound is greater. */ zero, the call is unsafe because the bound is greater. */
data.decl = unterminated_array (src, &len, &exact); lendata.decl = unterminated_array (src, &len, &exact);
if (!data.decl) if (!lendata.decl)
return NULL_RTX; return NULL_RTX;
} }
if (data.decl if (lendata.decl
&& !TREE_NO_WARNING (exp) && !TREE_NO_WARNING (exp)
&& ((tree_int_cst_lt (len, bound)) && ((tree_int_cst_lt (len, bound))
|| !exact)) || !exact))
...@@ -3127,7 +3127,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) ...@@ -3127,7 +3127,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
"of at most %E of unterminated array"), "of at most %E of unterminated array"),
exp, func, bound, len)) exp, func, bound, len))
{ {
inform (DECL_SOURCE_LOCATION (data.decl), inform (DECL_SOURCE_LOCATION (lendata.decl),
"referenced argument declared here"); "referenced argument declared here");
TREE_NO_WARNING (exp) = true; TREE_NO_WARNING (exp) = true;
return NULL_RTX; return NULL_RTX;
...@@ -3160,12 +3160,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) ...@@ -3160,12 +3160,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
bool exact = true; bool exact = true;
if (!len || TREE_CODE (len) != INTEGER_CST) if (!len || TREE_CODE (len) != INTEGER_CST)
{ {
data.decl = unterminated_array (src, &len, &exact); lendata.decl = unterminated_array (src, &len, &exact);
if (!data.decl) if (!lendata.decl)
return NULL_RTX; return NULL_RTX;
} }
if (data.decl if (lendata.decl
&& !TREE_NO_WARNING (exp) && !TREE_NO_WARNING (exp)
&& (wi::ltu_p (wi::to_wide (len), min) && (wi::ltu_p (wi::to_wide (len), min)
|| !exact)) || !exact))
...@@ -3181,13 +3181,13 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode) ...@@ -3181,13 +3181,13 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
"the size of at most %E of unterminated array"), "the size of at most %E of unterminated array"),
exp, func, min.to_uhwi (), max.to_uhwi (), len)) exp, func, min.to_uhwi (), max.to_uhwi (), len))
{ {
inform (DECL_SOURCE_LOCATION (data.decl), inform (DECL_SOURCE_LOCATION (lendata.decl),
"referenced argument declared here"); "referenced argument declared here");
TREE_NO_WARNING (exp) = true; TREE_NO_WARNING (exp) = true;
} }
} }
if (data.decl) if (lendata.decl)
return NULL_RTX; return NULL_RTX;
if (wi::gtu_p (min, wi::to_wide (len))) if (wi::gtu_p (min, wi::to_wide (len)))
...@@ -4083,14 +4083,14 @@ expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode) ...@@ -4083,14 +4083,14 @@ expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode)
compile-time, not an expression containing a string. This is compile-time, not an expression containing a string. This is
because the latter will potentially produce pessimized code because the latter will potentially produce pessimized code
when used to produce the return value. */ when used to produce the return value. */
c_strlen_data data = { }; c_strlen_data lendata = { };
if (!c_getstr (src, NULL) if (!c_getstr (src, NULL)
|| !(len = c_strlen (src, 0, &data, 1))) || !(len = c_strlen (src, 0, &lendata, 1)))
return expand_movstr (dst, src, target, return expand_movstr (dst, src, target,
/*retmode=*/ RETURN_END_MINUS_ONE); /*retmode=*/ RETURN_END_MINUS_ONE);
if (data.decl && !TREE_NO_WARNING (exp)) if (lendata.decl && !TREE_NO_WARNING (exp))
warn_string_no_nul (EXPR_LOCATION (exp), "stpcpy", src, data.decl); warn_string_no_nul (EXPR_LOCATION (exp), "stpcpy", src, lendata.decl);
lenp1 = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1)); lenp1 = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
ret = expand_builtin_mempcpy_args (dst, src, lenp1, ret = expand_builtin_mempcpy_args (dst, src, lenp1,
...@@ -8567,22 +8567,22 @@ fold_builtin_strlen (location_t loc, tree type, tree arg) ...@@ -8567,22 +8567,22 @@ fold_builtin_strlen (location_t loc, tree type, tree arg)
return NULL_TREE; return NULL_TREE;
else else
{ {
c_strlen_data data = { }; c_strlen_data lendata = { };
tree len = c_strlen (arg, 0, &data); tree len = c_strlen (arg, 0, &lendata);
if (len) if (len)
return fold_convert_loc (loc, type, len); return fold_convert_loc (loc, type, len);
if (!data.decl) if (!lendata.decl)
c_strlen (arg, 1, &data); c_strlen (arg, 1, &lendata);
if (data.decl) if (lendata.decl)
{ {
if (EXPR_HAS_LOCATION (arg)) if (EXPR_HAS_LOCATION (arg))
loc = EXPR_LOCATION (arg); loc = EXPR_LOCATION (arg);
else if (loc == UNKNOWN_LOCATION) else if (loc == UNKNOWN_LOCATION)
loc = input_location; loc = input_location;
warn_string_no_nul (loc, "strlen", arg, data.decl); warn_string_no_nul (loc, "strlen", arg, lendata.decl);
} }
return NULL_TREE; return NULL_TREE;
......
...@@ -1335,16 +1335,16 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type, ...@@ -1335,16 +1335,16 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
} }
else else
{ {
c_strlen_data data = { }; c_strlen_data lendata = { };
val = c_strlen (arg, 1, &data, eltsize); val = c_strlen (arg, 1, &lendata, eltsize);
/* If we potentially had a non-terminated string, then /* If we potentially had a non-terminated string, then
bubble that information up to the caller. */ bubble that information up to the caller. */
if (!val && data.decl) if (!val && lendata.decl)
{ {
*nonstr = data.decl; *nonstr = lendata.decl;
*minlen = data.len; *minlen = lendata.len;
*maxlen = data.len; *maxlen = lendata.len;
return type == 0 ? false : true; return type == 0 ? false : true;
} }
} }
...@@ -1358,20 +1358,21 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type, ...@@ -1358,20 +1358,21 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
if (TREE_CODE (arg) == ARRAY_REF) if (TREE_CODE (arg) == ARRAY_REF)
{ {
tree type = TREE_TYPE (TREE_OPERAND (arg, 0)); tree optype = TREE_TYPE (TREE_OPERAND (arg, 0));
/* Determine the "innermost" array type. */ /* Determine the "innermost" array type. */
while (TREE_CODE (type) == ARRAY_TYPE while (TREE_CODE (optype) == ARRAY_TYPE
&& TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE) && TREE_CODE (TREE_TYPE (optype)) == ARRAY_TYPE)
type = TREE_TYPE (type); optype = TREE_TYPE (optype);
/* Avoid arrays of pointers. */ /* Avoid arrays of pointers. */
tree eltype = TREE_TYPE (type); tree eltype = TREE_TYPE (optype);
if (TREE_CODE (type) != ARRAY_TYPE if (TREE_CODE (optype) != ARRAY_TYPE
|| !INTEGRAL_TYPE_P (eltype)) || !INTEGRAL_TYPE_P (eltype))
return false; return false;
val = TYPE_SIZE_UNIT (type); /* Fail when the array bound is unknown or zero. */
val = TYPE_SIZE_UNIT (optype);
if (!val || integer_zerop (val)) if (!val || integer_zerop (val))
return false; return false;
...@@ -1382,7 +1383,7 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type, ...@@ -1382,7 +1383,7 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
*minlen = ssize_int (0); *minlen = ssize_int (0);
if (TREE_CODE (TREE_OPERAND (arg, 0)) == COMPONENT_REF if (TREE_CODE (TREE_OPERAND (arg, 0)) == COMPONENT_REF
&& type == TREE_TYPE (TREE_OPERAND (arg, 0)) && optype == TREE_TYPE (TREE_OPERAND (arg, 0))
&& array_at_struct_end_p (TREE_OPERAND (arg, 0))) && array_at_struct_end_p (TREE_OPERAND (arg, 0)))
*flexp = true; *flexp = true;
} }
...@@ -1401,16 +1402,17 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type, ...@@ -1401,16 +1402,17 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
if (array_at_struct_end_p (arg)) if (array_at_struct_end_p (arg))
*flexp = true; *flexp = true;
arg = TREE_OPERAND (arg, 1); tree fld = TREE_OPERAND (arg, 1);
tree type = TREE_TYPE (arg); tree optype = TREE_TYPE (fld);
while (TREE_CODE (type) == ARRAY_TYPE /* Determine the "innermost" array type. */
&& TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE) while (TREE_CODE (optype) == ARRAY_TYPE
type = TREE_TYPE (type); && TREE_CODE (TREE_TYPE (optype)) == ARRAY_TYPE)
optype = TREE_TYPE (optype);
/* Fail when the array bound is unknown or zero. */ /* Fail when the array bound is unknown or zero. */
val = TYPE_SIZE_UNIT (type); val = TYPE_SIZE_UNIT (optype);
if (!val || integer_zerop (val)) if (!val || integer_zerop (val))
return false; return false;
val = fold_build2 (MINUS_EXPR, TREE_TYPE (val), val, val = fold_build2 (MINUS_EXPR, TREE_TYPE (val), val,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment