aboutsummaryrefslogtreecommitdiff
path: root/gcc/input.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-07-06 14:17:24 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-07-06 14:17:24 +0000
commitc471c6edcbe945b8925f72fd7683caef884e5835 (patch)
tree3ff3a35cba1a15d75b13502857d21a4e5d17cb92 /gcc/input.c
parent32aaf6ef10bf77d8300c0774dcc9bfcc8ed595c2 (diff)
downloadgcc-c471c6edcbe945b8925f72fd7683caef884e5835.zip
gcc-c471c6edcbe945b8925f72fd7683caef884e5835.tar.gz
gcc-c471c6edcbe945b8925f72fd7683caef884e5835.tar.bz2
diagnostics: fix end-points of ranges within macros (PR c++/79300)
gcc/ChangeLog: PR c++/79300 * diagnostic-show-locus.c (layout::layout): Use start and finish spelling location for the start and finish of each range. * genmatch.c (linemap_client_expand_location_to_spelling_point): Add unused aspect param. * input.c (expand_location_1): Add "aspect" param, and use it to access the correct part of the location. (expand_location): Pass LOCATION_ASPECT_CARET to new param of expand_location_1. (expand_location_to_spelling_point): Likewise. (linemap_client_expand_location_to_spelling_point): Add "aspect" param, and pass it to expand_location_1. gcc/testsuite/ChangeLog: PR c++/79300 * c-c++-common/Wmisleading-indentation-3.c (fn_14): Update expected underlining within macro expansion. * c-c++-common/pr70264.c: Likewise. * g++.dg/plugin/diagnostic-test-expressions-1.C (test_within_macro_1): New test. (test_within_macro_2): Likewise. (test_within_macro_3): Likewise. (test_within_macro_4): Likewise. * gcc.dg/format/diagnostic-ranges.c (test_macro_3): Update expected underlining within macro expansion. (test_macro_4): Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_within_macro_1): New test. (test_within_macro_2): Likewise. (test_within_macro_3): Likewise. (test_within_macro_4): Likewise. * gcc.dg/spellcheck-fields-2.c (test_macro): Update expected underlining within macro expansion. libcpp/ChangeLog: PR c++/79300 * include/line-map.h (enum location_aspect): New enum. (linemap_client_expand_location_to_spelling_point): Add enum location_aspect param. * line-map.c (rich_location::get_expanded_location): Update for new param of linemap_client_expand_location_to_spelling_point. (rich_location::maybe_add_fixit): Likewise. (fixit_hint::affects_line_p): Likewise. From-SVN: r250022
Diffstat (limited to 'gcc/input.c')
-rw-r--r--gcc/input.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/gcc/input.c b/gcc/input.c
index 8071810..0480eb2 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -147,11 +147,14 @@ static const size_t fcache_line_record_size = 100;
associated line/column) in the context of a macro expansion, the
returned location is the first one (while unwinding the macro
location towards its expansion point) that is in real source
- code. */
+ code.
+
+ ASPECT controls which part of the location to use. */
static expanded_location
expand_location_1 (source_location loc,
- bool expansion_point_p)
+ bool expansion_point_p,
+ enum location_aspect aspect)
{
expanded_location xloc;
const line_map_ordinary *map;
@@ -181,8 +184,36 @@ expand_location_1 (source_location loc,
loc, NULL);
lrk = LRK_SPELLING_LOCATION;
}
- loc = linemap_resolve_location (line_table, loc,
- lrk, &map);
+ loc = linemap_resolve_location (line_table, loc, lrk, &map);
+
+ /* loc is now either in an ordinary map, or is a reserved location.
+ If it is a compound location, the caret is in a spelling location,
+ but the start/finish might still be a virtual location.
+ Depending of what the caller asked for, we may need to recurse
+ one level in order to resolve any virtual locations in the
+ end-points. */
+ switch (aspect)
+ {
+ default:
+ gcc_unreachable ();
+ /* Fall through. */
+ case LOCATION_ASPECT_CARET:
+ break;
+ case LOCATION_ASPECT_START:
+ {
+ source_location start = get_start (loc);
+ if (start != loc)
+ return expand_location_1 (start, expansion_point_p, aspect);
+ }
+ break;
+ case LOCATION_ASPECT_FINISH:
+ {
+ source_location finish = get_finish (loc);
+ if (finish != loc)
+ return expand_location_1 (finish, expansion_point_p, aspect);
+ }
+ break;
+ }
xloc = linemap_expand_location (line_table, map, loc);
}
@@ -773,7 +804,8 @@ is_location_from_builtin_token (source_location loc)
expanded_location
expand_location (source_location loc)
{
- return expand_location_1 (loc, /*expansion_point_p=*/true);
+ return expand_location_1 (loc, /*expansion_point_p=*/true,
+ LOCATION_ASPECT_CARET);
}
/* Expand the source location LOC into a human readable location. If
@@ -785,7 +817,8 @@ expand_location (source_location loc)
expanded_location
expand_location_to_spelling_point (source_location loc)
{
- return expand_location_1 (loc, /*expansion_point_p=*/false);
+ return expand_location_1 (loc, /*expansion_point_p=*/false,
+ LOCATION_ASPECT_CARET);
}
/* The rich_location class within libcpp requires a way to expand
@@ -795,12 +828,13 @@ expand_location_to_spelling_point (source_location loc)
to do this.
This is the implementation for libcommon.a (all host binaries),
- which simply calls into expand_location_to_spelling_point. */
+ which simply calls into expand_location_1. */
expanded_location
-linemap_client_expand_location_to_spelling_point (source_location loc)
+linemap_client_expand_location_to_spelling_point (source_location loc,
+ enum location_aspect aspect)
{
- return expand_location_to_spelling_point (loc);
+ return expand_location_1 (loc, /*expansion_point_p=*/false, aspect);
}