diff options
author | Martin Sebor <msebor@redhat.com> | 2018-01-03 22:52:53 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-01-03 15:52:53 -0700 |
commit | 2438cb6a1dd5f983314b21988b915699c01a2e28 (patch) | |
tree | 9280aa5f66193767d229621d884a9c4551d8b7c4 /gcc/calls.c | |
parent | c3a8f964ab330d8e64bb4d33c462c64f4fa35aeb (diff) | |
download | gcc-2438cb6a1dd5f983314b21988b915699c01a2e28.zip gcc-2438cb6a1dd5f983314b21988b915699c01a2e28.tar.gz gcc-2438cb6a1dd5f983314b21988b915699c01a2e28.tar.bz2 |
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.
From-SVN: r256217
Diffstat (limited to 'gcc/calls.c')
-rw-r--r-- | gcc/calls.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/gcc/calls.c b/gcc/calls.c index bdd4991..54fea15 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; |