aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorBernd Schmidt <bernds@redhat.com>2016-01-13 20:03:26 +0000
committerBernd Schmidt <bernds@gcc.gnu.org>2016-01-13 20:03:26 +0000
commit3342fd71e0465ab4a702480a35043b295fc6fa21 (patch)
treec35775b90eda0d70234de508315954e7ece5b4b0 /gcc/c-family
parent2ad3adf102641812fe09742f545f8565bebd74ac (diff)
downloadgcc-3342fd71e0465ab4a702480a35043b295fc6fa21.zip
gcc-3342fd71e0465ab4a702480a35043b295fc6fa21.tar.gz
gcc-3342fd71e0465ab4a702480a35043b295fc6fa21.tar.bz2
Improve warning locations (PR66208)
PR c/66208 * c-common.c (check_function_nonnull): Remove unnecessary declaration. Add new arg loc and pass it down as context. (check_nonnull_arg): Don't mark ctx arg as unused. Use it as a pointer to the location to use for the warning. (check_function_arguments): New arg loc. All callers changed. Pass it to check_function_nonnull. * c-common.h (check_function_arguments): Adjust declaration. testsuite/ PR c/66208 * c-c++-common/pr66208.c: New file. From-SVN: r232345
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/c-common.c27
-rw-r--r--gcc/c-family/c-common.h2
2 files changed, 15 insertions, 14 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 0fd37b5c6..0bfa1f6 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -394,7 +394,6 @@ static tree handle_bnd_variable_size_attribute (tree *, tree, tree, int, bool *)
static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
-static void check_function_nonnull (tree, int, tree *);
static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *);
@@ -9097,11 +9096,10 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
/* Check the argument list of a function call for null in argument slots
that are marked as requiring a non-null pointer argument. The NARGS
- arguments are passed in the array ARGARRAY.
-*/
+ arguments are passed in the array ARGARRAY. */
static void
-check_function_nonnull (tree attrs, int nargs, tree *argarray)
+check_function_nonnull (location_t loc, tree attrs, int nargs, tree *argarray)
{
tree a;
int i;
@@ -9121,7 +9119,7 @@ check_function_nonnull (tree attrs, int nargs, tree *argarray)
if (a != NULL_TREE)
for (i = 0; i < nargs; i++)
- check_function_arguments_recurse (check_nonnull_arg, NULL, argarray[i],
+ check_function_arguments_recurse (check_nonnull_arg, &loc, argarray[i],
i + 1);
else
{
@@ -9137,7 +9135,7 @@ check_function_nonnull (tree attrs, int nargs, tree *argarray)
}
if (a != NULL_TREE)
- check_function_arguments_recurse (check_nonnull_arg, NULL,
+ check_function_arguments_recurse (check_nonnull_arg, &loc,
argarray[i], i + 1);
}
}
@@ -9223,9 +9221,10 @@ nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
via check_function_arguments_recurse. */
static void
-check_nonnull_arg (void * ARG_UNUSED (ctx), tree param,
- unsigned HOST_WIDE_INT param_num)
+check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
{
+ location_t *ploc = (location_t *) ctx;
+
/* Just skip checking the argument if it's not a pointer. This can
happen if the "nonnull" attribute was given without an operand
list (which means to check every pointer argument). */
@@ -9234,8 +9233,8 @@ check_nonnull_arg (void * ARG_UNUSED (ctx), tree param,
return;
if (integer_zerop (param))
- warning (OPT_Wnonnull, "null argument where non-null required "
- "(argument %lu)", (unsigned long) param_num);
+ warning_at (*ploc, OPT_Wnonnull, "null argument where non-null required "
+ "(argument %lu)", (unsigned long) param_num);
}
/* Helper for nonnull attribute handling; fetch the operand number
@@ -9678,15 +9677,17 @@ handle_designated_init_attribute (tree *node, tree name, tree, int,
/* Check for valid arguments being passed to a function with FNTYPE.
- There are NARGS arguments in the array ARGARRAY. */
+ There are NARGS arguments in the array ARGARRAY. LOC should be used for
+ diagnostics. */
void
-check_function_arguments (const_tree fntype, int nargs, tree *argarray)
+check_function_arguments (location_t loc, const_tree fntype, int nargs,
+ tree *argarray)
{
/* Check for null being passed in a pointer argument that must be
non-null. We also need to do this if format checking is enabled. */
if (warn_nonnull)
- check_function_nonnull (TYPE_ATTRIBUTES (fntype), nargs, argarray);
+ check_function_nonnull (loc, TYPE_ATTRIBUTES (fntype), nargs, argarray);
/* Check for errors in format strings. */
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 5c84c0d..93e605b 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -782,7 +782,7 @@ extern const char *fname_as_string (int);
extern tree fname_decl (location_t, unsigned, tree);
extern int check_user_alignment (const_tree, bool);
-extern void check_function_arguments (const_tree, int, tree *);
+extern void check_function_arguments (location_t loc, const_tree, int, tree *);
extern void check_function_arguments_recurse (void (*)
(void *, tree,
unsigned HOST_WIDE_INT),