aboutsummaryrefslogtreecommitdiff
path: root/gcc/calls.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2018-08-28 11:13:04 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2018-08-28 11:13:04 +0000
commit13308b3754c6a80912b882e48899040eaa5f99c1 (patch)
tree117cac799728b144f9d3de96b7c75faa7fc88a7a /gcc/calls.c
parent7d368d79d0bc184917c81fb5310c27f29048754a (diff)
PR middle-end/87099
* calls.c (maybe_warn_nonstring_arg): Punt early if warn_stringop_overflow is zero. Don't call get_range_strlen on 3rd argument, keep iterating until lenrng[1] is INTEGER_CST. Swap comparison operands to have constants on rhs. Only use lenrng[1] if non-NULL and INTEGER_CST. Don't uselessly increment lenrng[0]. * gcc.dg/pr87099.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263915 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/calls.c')
-rw-r--r--gcc/calls.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/gcc/calls.c b/gcc/calls.c
index f57ecf91636..87e3f000eff 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1545,7 +1545,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
if (!fndecl || !fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
return;
- if (TREE_NO_WARNING (exp))
+ if (TREE_NO_WARNING (exp) || !warn_stringop_overflow)
return;
unsigned nargs = call_expr_nargs (exp);
@@ -1573,7 +1573,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
the range of their known or possible lengths and use it
conservatively as the bound for the unbounded function,
and to adjust the range of the bound of the bounded ones. */
- for (unsigned argno = 0; argno < nargs && !*lenrng; argno ++)
+ for (unsigned argno = 0;
+ argno < MIN (nargs, 2)
+ && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST); argno++)
{
tree arg = CALL_EXPR_ARG (exp, argno);
if (!get_attr_nonstring_decl (arg))
@@ -1585,12 +1587,12 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
case BUILT_IN_STRNCAT:
case BUILT_IN_STPNCPY:
case BUILT_IN_STRNCPY:
- if (2 < nargs)
+ if (nargs > 2)
bound = CALL_EXPR_ARG (exp, 2);
break;
case BUILT_IN_STRNDUP:
- if (1 < nargs)
+ if (nargs > 1)
bound = CALL_EXPR_ARG (exp, 1);
break;
@@ -1600,7 +1602,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
if (!get_attr_nonstring_decl (arg))
get_range_strlen (arg, lenrng);
- if (1 < nargs)
+ if (nargs > 1)
bound = CALL_EXPR_ARG (exp, 1);
break;
}
@@ -1640,11 +1642,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
}
}
- if (*lenrng)
+ if (lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST)
{
/* Add one for the nul. */
- lenrng[0] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[0]),
- lenrng[0], size_one_node);
lenrng[1] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[1]),
lenrng[1], size_one_node);