aboutsummaryrefslogtreecommitdiff
path: root/gcc/calls.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-08-28 13:13:04 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-08-28 13:13:04 +0200
commit2c8861b7505cdc04377cd125565bb5ccadb29529 (patch)
tree117cac799728b144f9d3de96b7c75faa7fc88a7a /gcc/calls.c
parent4ec4324d0f2425ad64540d4c4d8d29f8e8077c3d (diff)
downloadgcc-2c8861b7505cdc04377cd125565bb5ccadb29529.zip
gcc-2c8861b7505cdc04377cd125565bb5ccadb29529.tar.gz
gcc-2c8861b7505cdc04377cd125565bb5ccadb29529.tar.bz2
re PR middle-end/87099 (internal compiler error: segmentation fault)
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. From-SVN: r263915
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 f57ecf9..87e3f00 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);