diff options
author | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-30 11:42:38 +0000 |
---|---|---|
committer | dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-30 11:42:38 +0000 |
commit | db30b35189c3090d0739f86df53e954125cf90b9 (patch) | |
tree | c28481505ac75c540fcd6de15af56c57a92ccb41 /gcc/input.c | |
parent | 18f0e0e551a995687e1822aabb9b7d7ee8f11492 (diff) | |
download | gcc-db30b35189c3090d0739f86df53e954125cf90b9.tar.gz |
Make conversion warnings work on NULL with -ftrack-macro-expansion
There are various conversion related warnings that trigger on
potentially dangerous uses of NULL (or __null). NULL is defined as a
macro in a system header, so calling warning or warning_at on a
virtual location of NULL yields no diagnostic. So the test
accompanying this patch (as well as others), was failling when run
with -ftrack-macro-expansion.
I think it's necessary to use the location of NULL that is in the main
source code (instead of, e.g, the spelling location that is in the
system header where the macro is defined) in those cases. Note that
for __null, we don't have the issue.
I have augmented the test of this patch to check that we don't regress
when handling __null.
Tested on x86_64-unknown-linux-gnu against trunk.
Note that the bootstrap with -ftrack-macro-expansion exhibits other
separate issues that are addressed in subsequent patches. This patch
just fixes one class of problems.
The patch does pass bootstrap with -ftrack-macro-expansion turned off,
though.
gcc/
* input.h (expansion_point_location_if_in_system_header): Declare
new function.
* input.c (expansion_point_location_if_in_system_header): Define it.
gcc/cp/
* call.c (conversion_null_warnings): Use the new
expansion_point_location_if_in_system_header.
* cvt.c (build_expr_type_conversion): Likewise.
* typeck.c (cp_build_binary_op): Likewise.
gcc/testsuite/
* g++.dg/warn/Wconversion-null-2.C: Add testing for __null,
alongside the previous testing for NULL.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186972 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/input.c')
-rw-r--r-- | gcc/input.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/input.c b/gcc/input.c index 260be7e7d55..5f14489753f 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -162,6 +162,26 @@ expand_location_to_spelling_point (source_location loc) return expand_location_1 (loc, /*expansion_piont_p=*/false); } +/* If LOCATION is in a sytem header and if it's a virtual location for + a token coming from the expansion of a macro M, unwind it to the + location of the expansion point of M. Otherwise, just return + LOCATION. + + This is used for instance when we want to emit diagnostics about a + token that is located in a macro that is itself defined in a system + header -- e.g for the NULL macro. In that case, if LOCATION is + passed to diagnostics emitting functions like warning_at as is, no + diagnostic won't be emitted. */ + +source_location +expansion_point_location_if_in_system_header (source_location location) +{ + if (in_system_header_at (location)) + location = linemap_resolve_location (line_table, location, + LRK_MACRO_EXPANSION_POINT, + NULL); + return location; +} #define ONE_K 1024 #define ONE_M (ONE_K * ONE_K) |