Bug 66208 - macro location not detected
Summary: macro location not detected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Bernd Schmidt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-19 15:59 UTC by Manuel López-Ibáñez
Modified: 2016-01-13 20:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-05-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel López-Ibáñez 2015-05-19 15:59:16 UTC
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.
Comment 1 Marek Polacek 2015-05-26 14:11:36 UTC
We should pass the location from build_function_call_vec all the way down to check_nonnull_arg.
Comment 2 Bernd Schmidt 2015-12-16 16:54:04 UTC
Working on it.
Comment 3 Bernd Schmidt 2016-01-13 20:03:58 UTC
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
Comment 4 Bernd Schmidt 2016-01-13 20:12:55 UTC
Fixed.