From: https://gcc.gnu.org/ml/gcc-help/2015-05/msg00082.html void foox (char*, ...) __attribute__ ((nonnull (1))); #define foo(p) foox (p, "p is null") #define bar(p) _Static_assert (p, "p is null") void baz (void) { foox (0, "p is null"); foo (0); bar (0); } This should print: test.c:2:16: warning: null argument where non-null required (argument 1) [-Wnonnull] #define foo(p) foox (p, "p is null") ^ test.c:7:3: note: in expansion of macro ‘foo’ foo (0); ^ but for some reason, the input_location at the time of warning is not a virtual location coming from a macro map. It seems that input_location is not adjusted correctly before giving this warning test.c:6:3: warning: null argument where non-null required (argument 1) [-Wnonnull] (foox (0, "p is null")); ^ test.c:7:3: warning: null argument where non-null required (argument 1) [-Wnonnull] (foo (0)); ^ and it always points to the first location given in the line, which was never updated to be a macro location.
We should pass the location from build_function_call_vec all the way down to check_nonnull_arg.
Working on it.
Author: bernds Date: Wed Jan 13 20:03:26 2016 New Revision: 232345 URL: https://gcc.gnu.org/viewcvs?rev=232345&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/c-c++-common/pr66208.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-family/c-common.c trunk/gcc/c-family/c-common.h trunk/gcc/c/c-typeck.c trunk/gcc/cp/call.c trunk/gcc/cp/typeck.c trunk/gcc/testsuite/ChangeLog
Fixed.