aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-10-29 23:44:10 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-10-29 23:44:10 +0000
commitb2bf438c02e885ddcd89e3f372fe88d9c3a58fd9 (patch)
tree0dcee2d28ee9534b49dcdd465bd13dd78d31a832 /gcc
parentebdb73c0b0950509eab6a5fa7f0f5b360c6e5cca (diff)
downloadgcc-b2bf438c02e885ddcd89e3f372fe88d9c3a58fd9.zip
gcc-b2bf438c02e885ddcd89e3f372fe88d9c3a58fd9.tar.gz
gcc-b2bf438c02e885ddcd89e3f372fe88d9c3a58fd9.tar.bz2
Folding and check_function_arguments
This patch eliminates the arglocs array I introduced to build_over_call in r264887, and eliminates the call to maybe_constant_value when building "fargs" (thus retaining location wrapper nodes). Instead, this patch requires that any checks within check_function_arguments that need folded arguments do their own folding. Of the various checks: (a) check_function_nonnull already calls fold_for_warn, (b) check_function_format doesn't need folding (c) check_function_sentinel needs fold_for_warn in one place, which the patch adds, and (d) check_function_restrict needs per-argument folding, which the patch adds. Given that it scans before and after resetting TREE_VISITED on each argument, it seemed best to make a copy of the array, folding each argument from the outset, rather than repeatedly calling fold_for_warn; gcc/c-family/ChangeLog: PR c++/56856 * c-common.c (check_function_sentinel): Call fold_for_warn on the argument. (check_function_restrict): Rename param "argarray" to "unfolded_argarray", and make a copy named "argarray", calling fold_for_warn on each argument. (check_function_arguments): Add note about responsibility for folding the arguments. gcc/cp/ChangeLog: PR c++/56856 * call.c (build_over_call): Eliminate the "arglocs" array, and the call to maybe_constant_value when building "fargs". From-SVN: r265609
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog11
-rw-r--r--gcc/c-family/c-common.c17
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c6
4 files changed, 32 insertions, 8 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 5b334f3..6199db7 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,14 @@
+2018-10-29 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/56856
+ * c-common.c (check_function_sentinel): Call fold_for_warn on the
+ argument.
+ (check_function_restrict): Rename param "argarray" to
+ "unfolded_argarray", and make a copy named "argarray", calling
+ fold_for_warn on each argument.
+ (check_function_arguments): Add note about responsibility for
+ folding the arguments.
+
2018-10-17 Joseph Myers <joseph@codesourcery.com>
* c-common.c (flag_isoc2x): New variable.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f10cf89..534d928 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5301,7 +5301,7 @@ check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
}
/* Validate the sentinel. */
- sentinel = argarray[nargs - 1 - pos];
+ sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
|| !integer_zerop (sentinel))
/* Although __null (in C++) is only an integer we allow it
@@ -5320,11 +5320,16 @@ check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
static bool
check_function_restrict (const_tree fndecl, const_tree fntype,
- int nargs, tree *argarray)
+ int nargs, tree *unfolded_argarray)
{
int i;
tree parms = TYPE_ARG_TYPES (fntype);
+ /* Call fold_for_warn on all of the arguments. */
+ auto_vec<tree> argarray (nargs);
+ for (i = 0; i < nargs; i++)
+ argarray.quick_push (fold_for_warn (unfolded_argarray[i]));
+
if (fndecl
&& TREE_CODE (fndecl) == FUNCTION_DECL)
{
@@ -5361,7 +5366,7 @@ check_function_restrict (const_tree fndecl, const_tree fntype,
if (POINTER_TYPE_P (type)
&& TYPE_RESTRICT (type)
&& !TYPE_READONLY (TREE_TYPE (type)))
- warned |= warn_for_restrict (i, argarray, nargs);
+ warned |= warn_for_restrict (i, argarray.address (), nargs);
}
for (i = 0; i < nargs; i++)
@@ -5608,7 +5613,11 @@ attribute_fallthrough_p (tree attr)
/* Check for valid arguments being passed to a function with FNTYPE.
There are NARGS arguments in the array ARGARRAY. LOC should be used
for diagnostics. Return true if either -Wnonnull or -Wrestrict has
- been issued. */
+ been issued.
+
+ The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
+ to preserve location wrappers); checks that require folded arguments
+ should call fold_for_warn on them. */
bool
check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b1e7f23..78d2b5b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-10-29 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/56856
+ * call.c (build_over_call): Eliminate the "arglocs" array, and the
+ call to maybe_constant_value when building "fargs".
+
2018-10-29 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (create_array_type_for_decl): Add location_t parameter
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index cd0c0f6..a7dce2e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8198,7 +8198,6 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
{
tree *fargs = (!nargs ? argarray
: (tree *) alloca (nargs * sizeof (tree)));
- auto_vec<location_t> arglocs (nargs);
for (j = 0; j < nargs; j++)
{
/* For -Wformat undo the implicit passing by hidden reference
@@ -8207,12 +8206,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
&& TYPE_REF_P (TREE_TYPE (argarray[j])))
fargs[j] = TREE_OPERAND (argarray[j], 0);
else
- fargs[j] = maybe_constant_value (argarray[j]);
- arglocs.quick_push (EXPR_LOC_OR_LOC (argarray[j], input_location));
+ fargs[j] = argarray[j];
}
warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
- nargs, fargs, &arglocs);
+ nargs, fargs, NULL);
}
if (DECL_INHERITED_CTOR (fn))