summaryrefslogtreecommitdiff
path: root/gcc/calls.c
diff options
context:
space:
mode:
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-03 22:52:53 +0000
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-03 22:52:53 +0000
commit625c5395ad08a21792335a77dd895c9611cad539 (patch)
tree9280aa5f66193767d229621d884a9c4551d8b7c4 /gcc/calls.c
parent33fe23796c0cc31ee121eb8aebdcefc4032866de (diff)
downloadgcc-625c5395ad08a21792335a77dd895c9611cad539.tar.gz
PR tree-optimization/83603 - ICE in builtin_memref at gcc/gimple-ssa-warn-restrict.c:238
gcc/ChangeLog: PR tree-optimization/83603 * calls.c (maybe_warn_nonstring_arg): Avoid accessing function arguments past the endof the argument list in functions declared without a prototype. * gimple-ssa-warn-restrict.c (wrestrict_dom_walker::check_call): Avoid checking when arguments are null. gcc/testsuite/ChangeLog: PR tree-optimization/83603 * gcc.dg/Wrestrict-4.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256217 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/calls.c')
-rw-r--r--gcc/calls.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/gcc/calls.c b/gcc/calls.c
index bdd49914fb2..54fea158631 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1607,6 +1607,8 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
bool with_bounds = CALL_WITH_BOUNDS_P (exp);
+ unsigned nargs = call_expr_nargs (exp);
+
/* The bound argument to a bounded string function like strncpy. */
tree bound = NULL_TREE;
@@ -1621,12 +1623,20 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
case BUILT_IN_STRNCASECMP:
case BUILT_IN_STRNCPY:
case BUILT_IN_STRNCPY_CHK:
- bound = CALL_EXPR_ARG (exp, with_bounds ? 4 : 2);
- break;
+ {
+ unsigned argno = with_bounds ? 4 : 2;
+ if (argno < nargs)
+ bound = CALL_EXPR_ARG (exp, argno);
+ break;
+ }
case BUILT_IN_STRNDUP:
- bound = CALL_EXPR_ARG (exp, with_bounds ? 2 : 1);
- break;
+ {
+ unsigned argno = with_bounds ? 2 : 1;
+ if (argno < nargs)
+ bound = CALL_EXPR_ARG (exp, argno);
+ break;
+ }
default:
break;
@@ -1646,6 +1656,11 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
for (unsigned argno = 0; ; ++argno, function_args_iter_next (&it))
{
+ /* Avoid iterating past the declared argument in a call
+ to function declared without a prototype. */
+ if (argno >= nargs)
+ break;
+
tree argtype = function_args_iter_cond (&it);
if (!argtype)
break;