diff options
author | David Malcolm <dmalcolm@redhat.com> | 2017-07-06 14:17:24 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2017-07-06 14:17:24 +0000 |
commit | c471c6edcbe945b8925f72fd7683caef884e5835 (patch) | |
tree | 3ff3a35cba1a15d75b13502857d21a4e5d17cb92 /libcpp | |
parent | 32aaf6ef10bf77d8300c0774dcc9bfcc8ed595c2 (diff) | |
download | gcc-c471c6edcbe945b8925f72fd7683caef884e5835.tar.gz |
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 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 11 | ||||
-rw-r--r-- | libcpp/include/line-map.h | 12 | ||||
-rw-r--r-- | libcpp/line-map.c | 18 |
3 files changed, 34 insertions, 7 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 526b8023b38..d080b016876 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,14 @@ +2017-07-06 David Malcolm <dmalcolm@redhat.com> + + 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. + 2017-06-21 Jakub Jelinek <jakub@redhat.com> * line-map.c (location_adhoc_data_update): Perform addition in diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index f5c19e31a94..e6960410c00 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1905,6 +1905,15 @@ void linemap_dump (FILE *, struct line_maps *, unsigned, bool); specifies how many macro maps to dump. */ void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int); +/* An enum for distinguishing the various parts within a source_location. */ + +enum location_aspect +{ + LOCATION_ASPECT_CARET, + LOCATION_ASPECT_START, + LOCATION_ASPECT_FINISH +}; + /* The rich_location class requires a way to expand source_location instances. We would directly use expand_location_to_spelling_point, which is implemented in gcc/input.c, but we also need to use it for rich_location @@ -1912,6 +1921,7 @@ void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int); Hence we require client code of libcpp to implement the following symbol. */ extern expanded_location -linemap_client_expand_location_to_spelling_point (source_location ); +linemap_client_expand_location_to_spelling_point (source_location, + enum location_aspect); #endif /* !LIBCPP_LINE_MAP_H */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 476a465efa0..3b65a464647 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -2066,7 +2066,8 @@ rich_location::get_expanded_location (unsigned int idx) if (!m_have_expanded_location) { m_expanded_location - = linemap_client_expand_location_to_spelling_point (get_loc (0)); + = linemap_client_expand_location_to_spelling_point + (get_loc (0), LOCATION_ASPECT_CARET); if (m_column_override) m_expanded_location.column = m_column_override; m_have_expanded_location = true; @@ -2075,7 +2076,8 @@ rich_location::get_expanded_location (unsigned int idx) return m_expanded_location; } else - return linemap_client_expand_location_to_spelling_point (get_loc (idx)); + return linemap_client_expand_location_to_spelling_point + (get_loc (idx), LOCATION_ASPECT_CARET); } /* Set the column of the primary location, with 0 meaning @@ -2331,9 +2333,11 @@ rich_location::maybe_add_fixit (source_location start, /* Only allow fix-it hints that affect a single line in one file. Compare the end-points. */ expanded_location exploc_start - = linemap_client_expand_location_to_spelling_point (start); + = linemap_client_expand_location_to_spelling_point (start, + LOCATION_ASPECT_START); expanded_location exploc_next_loc - = linemap_client_expand_location_to_spelling_point (next_loc); + = linemap_client_expand_location_to_spelling_point (next_loc, + LOCATION_ASPECT_START); /* They must be within the same file... */ if (exploc_start.file != exploc_next_loc.file) { @@ -2407,13 +2411,15 @@ bool fixit_hint::affects_line_p (const char *file, int line) const { expanded_location exploc_start - = linemap_client_expand_location_to_spelling_point (m_start); + = linemap_client_expand_location_to_spelling_point (m_start, + LOCATION_ASPECT_START); if (file != exploc_start.file) return false; if (line < exploc_start.line) return false; expanded_location exploc_next_loc - = linemap_client_expand_location_to_spelling_point (m_next_loc); + = linemap_client_expand_location_to_spelling_point (m_next_loc, + LOCATION_ASPECT_START); if (file != exploc_next_loc.file) return false; if (line > exploc_next_loc.line) |