diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-03-09 18:14:43 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-03-09 18:14:43 +0000 |
commit | 40499f81a6a65d903a8b6469797c58c52eaf8008 (patch) | |
tree | ba81cb8d930007773d9d7556e938bf62e095d82e /gcc | |
parent | c9e336624a5f3d3845b9b4a070f29d074418bd73 (diff) | |
download | gcc-40499f81a6a65d903a8b6469797c58c52eaf8008.zip gcc-40499f81a6a65d903a8b6469797c58c52eaf8008.tar.gz gcc-40499f81a6a65d903a8b6469797c58c52eaf8008.tar.bz2 |
PR c++/70105: Defer location expansion until diagnostic_show_locus
gcc/ChangeLog:
PR c/68473
PR c++/70105
* diagnostic-show-locus.c (layout_range::layout_range): Replace
location_range param with three const expanded_locations * and a
bool.
(layout::layout): Replace call to
rich_location::lazily_expand_location with get_expanded_location.
Extract the range and perform location expansion here, passing
the results to the layout_range ctor.
* diagnostic.c (source_range::debug): Delete.
* diagnostic.h (diagnostic_expand_location): Reimplement in terms
of rich_location::get_expanded_location.
* gcc-rich-location.c (get_range_for_expr): Delete.
(gcc_rich_location::add_expr): Reimplement to avoid the
rich_location::add_range overload that took a location_range,
passing a location_t instead.
gcc/testsuite/ChangeLog:
PR c/68473
PR c++/70105
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree):
Drop range information from call to inform_at_rich_loc.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range):
New.
(test_show_locus): Replace calls to rich_location::add_range with
calls to add_range. Rewrite the tests that used the now-defunct
rich_location ctor taking a source_range. Simplify other tests
by replacing calls to COMBINE_LOCATION_DATA with calls to
make_location.
libcpp/ChangeLog:
PR c/68473
PR c++/70105
* include/line-map.h (source_range::debug): Delete.
(struct location_range): Update comment. Replace
expanded_location fields "m_start", "m_finish", and "m_caret" with
a source_location field: "m_loc".
(class rich_location): Reword comment.
(rich_location::get_loc): Reimplement in terms of a new overloaded
variant which takes an unsigned int.
(rich_location::get_loc_addr): Delete.
(rich_location::add_range): Drop params "start" and "finish" in
favor of param "loc". Drop overloaded variants taking a
source_range or location_range *.
(rich_location::lazily_expand_location): Delete in favor of...
(rich_location::get_expanded_location): New decl.
(rich_location::m_loc): Delete field.
(rich_location::m_column_override): New field.
* line-map.c (rich_location::rich_location): Drop name of
line_maps * param. Update initializations for deletion of field
"m_loc" and addition of field "m_column_override". Reimplement
body as a call to add_range. Delete overloaded variant taking a
source_range.
(rich_location::get_loc): New function.
(rich_location::lazily_expand_location): Delete in favor of...
(rich_location::get_expanded_location): New function.
(rich_location::override_column): Reimplement.
(rich_location::add_range): Drop params "start" and "finish" in
favor of param "loc". Eliminate location expansion in favor of
simply storing loc. Drop overloaded variants taking a
source_range or location_range *.
(rich_location::set_range): Eliminate location expansion.
From-SVN: r234087
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 19 | ||||
-rw-r--r-- | gcc/diagnostic-show-locus.c | 41 | ||||
-rw-r--r-- | gcc/diagnostic.c | 14 | ||||
-rw-r--r-- | gcc/diagnostic.h | 2 | ||||
-rw-r--r-- | gcc/gcc-rich-location.c | 28 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c | 97 |
8 files changed, 112 insertions, 111 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e0e9ad1..ee8e208 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,22 @@ +2016-03-09 David Malcolm <dmalcolm@redhat.com> + + PR c/68473 + PR c++/70105 + * diagnostic-show-locus.c (layout_range::layout_range): Replace + location_range param with three const expanded_locations * and a + bool. + (layout::layout): Replace call to + rich_location::lazily_expand_location with get_expanded_location. + Extract the range and perform location expansion here, passing + the results to the layout_range ctor. + * diagnostic.c (source_range::debug): Delete. + * diagnostic.h (diagnostic_expand_location): Reimplement in terms + of rich_location::get_expanded_location. + * gcc-rich-location.c (get_range_for_expr): Delete. + (gcc_rich_location::add_expr): Reimplement to avoid the + rich_location::add_range overload that took a location_range, + passing a location_t instead. + 2016-03-09 Richard Biener <rguenther@suse.de> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index 3acdb32..a940f24 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -117,7 +117,10 @@ class layout_point class layout_range { public: - layout_range (const location_range *loc_range); + layout_range (const expanded_location *start_exploc, + const expanded_location *finish_exploc, + bool show_caret_p, + const expanded_location *caret_exploc); bool contains_point (int row, int column) const; @@ -328,11 +331,14 @@ colorizer::finish_state (int state) Initialize various layout_point fields from expanded_location equivalents; we've already filtered on file. */ -layout_range::layout_range (const location_range *loc_range) -: m_start (loc_range->m_start), - m_finish (loc_range->m_finish), - m_show_caret_p (loc_range->m_show_caret_p), - m_caret (loc_range->m_caret) +layout_range::layout_range (const expanded_location *start_exploc, + const expanded_location *finish_exploc, + bool show_caret_p, + const expanded_location *caret_exploc) +: m_start (*start_exploc), + m_finish (*finish_exploc), + m_show_caret_p (show_caret_p), + m_caret (*caret_exploc) { } @@ -473,7 +479,7 @@ layout::layout (diagnostic_context * context, : m_context (context), m_pp (context->printer), m_diagnostic_kind (diagnostic->kind), - m_exploc (diagnostic->richloc->lazily_expand_location ()), + m_exploc (diagnostic->richloc->get_expanded_location (0)), m_colorizer (context, diagnostic), m_colorize_source_p (context->colorize_source_p), m_layout_ranges (rich_location::MAX_RANGES), @@ -487,25 +493,36 @@ layout::layout (diagnostic_context * context, Ignore any ranges that are awkward to handle. */ const location_range *loc_range = richloc->get_range (idx); + /* Split the "range" into caret and range information. */ + source_range src_range = get_range_from_loc (line_table, loc_range->m_loc); + + /* Expand the various locations. */ + expanded_location start + = linemap_client_expand_location_to_spelling_point (src_range.m_start); + expanded_location finish + = linemap_client_expand_location_to_spelling_point (src_range.m_finish); + expanded_location caret + = linemap_client_expand_location_to_spelling_point (loc_range->m_loc); + /* If any part of the range isn't in the same file as the primary location of this diagnostic, ignore the range. */ - if (loc_range->m_start.file != m_exploc.file) + if (start.file != m_exploc.file) continue; - if (loc_range->m_finish.file != m_exploc.file) + if (finish.file != m_exploc.file) continue; if (loc_range->m_show_caret_p) - if (loc_range->m_caret.file != m_exploc.file) + if (caret.file != m_exploc.file) continue; /* Everything is now known to be in the correct source file, but it may require further sanitization. */ - layout_range ri (loc_range); + layout_range ri (&start, &finish, loc_range->m_show_caret_p, &caret); /* If we have a range that finishes before it starts (perhaps from something built via macro expansion), printing the range is likely to be nonsensical. Also, attempting to do so breaks assumptions within the printing code (PR c/68473). */ - if (loc_range->m_start.line > loc_range->m_finish.line) + if (start.line > finish.line) { /* Is this the primary location? */ if (m_layout_ranges.length () == 0) diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 322f2d9..6a679cb 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -1338,17 +1338,3 @@ real_abort (void) { abort (); } - -/* Display the given source_range instance, with MSG as a descriptive - comment. This issues a "note" diagnostic at the range. - - This is declared within libcpp, but implemented here, since it - makes use of the diagnostic-printing machinery. */ - -DEBUG_FUNCTION void -source_range::debug (const char *msg) const -{ - rich_location richloc (line_table, m_start); - richloc.add_range (m_start, m_finish, false); - inform_at_rich_loc (&richloc, "%s", msg); -} diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 017ddca..ff57357 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -339,7 +339,7 @@ diagnostic_num_locations (const diagnostic_info * diagnostic) static inline expanded_location diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0) { - return diagnostic->richloc->get_range (which)->m_caret; + return diagnostic->richloc->get_expanded_location (which); } /* This is somehow the right-side margin of a caret line, that is, we diff --git a/gcc/gcc-rich-location.c b/gcc/gcc-rich-location.c index 9ab4314..a03ce0e 100644 --- a/gcc/gcc-rich-location.c +++ b/gcc/gcc-rich-location.c @@ -41,28 +41,6 @@ along with GCC; see the file COPYING3. If not see #include "cpplib.h" #include "diagnostic.h" -/* Extract any source range information from EXPR and write it - to *R. */ - -static bool -get_range_for_expr (tree expr, location_range *r) -{ - if (EXPR_HAS_RANGE (expr)) - { - source_range sr = EXPR_LOCATION_RANGE (expr); - - /* Do we have meaningful data? */ - if (sr.m_start && sr.m_finish) - { - r->m_start = expand_location (sr.m_start); - r->m_finish = expand_location (sr.m_finish); - return true; - } - } - - return false; -} - /* Add a range to the rich_location, covering expression EXPR. */ void @@ -70,10 +48,8 @@ gcc_rich_location::add_expr (tree expr) { gcc_assert (expr); - location_range r; - r.m_show_caret_p = false; - if (get_range_for_expr (expr, &r)) - add_range (&r); + if (CAN_HAVE_RANGE_P (expr)) + add_range (EXPR_LOCATION (expr), false); } /* If T is an expression, add a range for it to the rich_location. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b95a863..014ee42 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2016-03-09 David Malcolm <dmalcolm@redhat.com> + + PR c/68473 + PR c++/70105 + * gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): + Drop range information from call to inform_at_rich_loc. + * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range): + New. + (test_show_locus): Replace calls to rich_location::add_range with + calls to add_range. Rewrite the tests that used the now-defunct + rich_location ctor taking a source_range. Simplify other tests + by replacing calls to COMBINE_LOCATION_DATA with calls to + make_location. + 2016-03-09 Richard Biener <rguenther@suse.de> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c index c98034f..f025f96 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c @@ -52,13 +52,7 @@ show_tree (tree node) enum tree_code code = TREE_CODE (node); location_range *range = richloc.get_range (1); - inform_at_rich_loc (&richloc, - "%s at range %i:%i-%i:%i", - get_tree_code_name (code), - range->m_start.line, - range->m_start.column, - range->m_finish.line, - range->m_finish.column); + inform_at_rich_loc (&richloc, "%s", get_tree_code_name (code)); /* Recurse. */ int min_idx = 0; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c index b4f12ba..95078ce 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @@ -140,6 +140,15 @@ custom_diagnostic_finalizer (diagnostic_context *context, pp_flush (context->printer); } +/* Add a location to RICHLOC with caret==start at START, ranging to FINISH. */ + +static void +add_range (rich_location *richloc, location_t start, location_t finish, + bool show_caret_p) +{ + richloc->add_range (make_location (start, start, finish), show_caret_p); +} + /* Exercise the diagnostic machinery to emit various warnings, for use by diagnostic-test-show-locus-*.c. @@ -165,8 +174,8 @@ test_show_locus (function *fun) { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line, 15)); - richloc.add_range (get_loc (line, 10), get_loc (line, 14), false); - richloc.add_range (get_loc (line, 16), get_loc (line, 16), false); + add_range (&richloc, get_loc (line, 10), get_loc (line, 14), false); + add_range (&richloc, get_loc (line, 16), get_loc (line, 16), false); warning_at_rich_loc (&richloc, 0, "test"); } @@ -174,10 +183,8 @@ test_show_locus (function *fun) { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line, 24)); - richloc.add_range (get_loc (line, 6), - get_loc (line, 22), false); - richloc.add_range (get_loc (line, 26), - get_loc (line, 43), false); + add_range (&richloc, get_loc (line, 6), get_loc (line, 22), false); + add_range (&richloc, get_loc (line, 26), get_loc (line, 43), false); warning_at_rich_loc (&richloc, 0, "test"); } @@ -185,10 +192,9 @@ test_show_locus (function *fun) { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line + 1, 7)); - richloc.add_range (get_loc (line, 7), - get_loc (line, 23), false); - richloc.add_range (get_loc (line + 1, 9), - get_loc (line + 1, 26), false); + add_range (&richloc, get_loc (line, 7), get_loc (line, 23), false); + add_range (&richloc, get_loc (line + 1, 9), get_loc (line + 1, 26), + false); warning_at_rich_loc (&richloc, 0, "test"); } @@ -196,22 +202,20 @@ test_show_locus (function *fun) { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line + 5, 7)); - richloc.add_range (get_loc (line, 7), - get_loc (line + 4, 65), false); - richloc.add_range (get_loc (line + 5, 9), - get_loc (line + 10, 61), false); + add_range (&richloc, get_loc (line, 7), get_loc (line + 4, 65), false); + add_range (&richloc, get_loc (line + 5, 9), get_loc (line + 10, 61), + false); warning_at_rich_loc (&richloc, 0, "test"); } - /* Example of a rich_location constructed directly from a - source_range where the range is larger than one character. */ + /* Example of a rich_location where the range is larger than + one character. */ if (0 == strcmp (fnname, "test_richloc_from_proper_range")) { const int line = fnstart_line + 2; - source_range src_range; - src_range.m_start = get_loc (line, 12); - src_range.m_finish = get_loc (line, 16); - rich_location richloc (src_range); + location_t start = get_loc (line, 12); + location_t finish = get_loc (line, 16); + rich_location richloc (line_table, make_location (start, start, finish)); warning_at_rich_loc (&richloc, 0, "test"); } @@ -220,15 +224,9 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_caret_within_proper_range")) { const int line = fnstart_line + 2; - location_t caret = get_loc (line, 16); - source_range src_range; - src_range.m_start = get_loc (line, 12); - src_range.m_finish = get_loc (line, 20); - location_t combined_loc = COMBINE_LOCATION_DATA (line_table, - caret, - src_range, - NULL); - warning_at (combined_loc, 0, "test"); + warning_at (make_location (get_loc (line, 16), get_loc (line, 12), + get_loc (line, 20)), + 0, "test"); } /* Example of a very wide line, where the information of interest @@ -236,15 +234,9 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; - location_t caret = get_loc (line, 94); - source_range src_range; - src_range.m_start = get_loc (line, 90); - src_range.m_finish = get_loc (line, 98); - location_t combined_loc = COMBINE_LOCATION_DATA (line_table, - caret, - src_range, - NULL); - warning_at (combined_loc, 0, "test"); + warning_at (make_location (get_loc (line, 94), get_loc (line, 90), + get_loc (line, 98)), + 0, "test"); } /* Example of multiple carets. */ @@ -254,7 +246,7 @@ test_show_locus (function *fun) location_t caret_a = get_loc (line, 7); location_t caret_b = get_loc (line, 11); rich_location richloc (line_table, caret_a); - richloc.add_range (caret_b, caret_b, true); + add_range (&richloc, caret_b, caret_b, true); global_dc->caret_chars[0] = 'A'; global_dc->caret_chars[1] = 'B'; warning_at_rich_loc (&richloc, 0, "test"); @@ -266,11 +258,10 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_fixit_insert")) { const int line = fnstart_line + 2; - source_range src_range; - src_range.m_start = get_loc (line, 19); - src_range.m_finish = get_loc (line, 22); - rich_location richloc (src_range); - richloc.add_fixit_insert (src_range.m_start, "{"); + location_t start = get_loc (line, 19); + location_t finish = get_loc (line, 22); + rich_location richloc (line_table, make_location (start, start, finish)); + richloc.add_fixit_insert (start, "{"); richloc.add_fixit_insert (get_loc (line, 23), "}"); warning_at_rich_loc (&richloc, 0, "example of insertion hints"); } @@ -278,10 +269,12 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_fixit_remove")) { const int line = fnstart_line + 2; + location_t start = get_loc (line, 8); + location_t finish = get_loc (line, 8); + rich_location richloc (line_table, make_location (start, start, finish)); source_range src_range; - src_range.m_start = get_loc (line, 8); - src_range.m_finish = get_loc (line, 8); - rich_location richloc (src_range); + src_range.m_start = start; + src_range.m_finish = finish; richloc.add_fixit_remove (src_range); warning_at_rich_loc (&richloc, 0, "example of a removal hint"); } @@ -289,10 +282,12 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_fixit_replace")) { const int line = fnstart_line + 2; + location_t start = get_loc (line, 2); + location_t finish = get_loc (line, 19); + rich_location richloc (line_table, make_location (start, start, finish)); source_range src_range; - src_range.m_start = get_loc (line, 2); - src_range.m_finish = get_loc (line, 19); - rich_location richloc (src_range); + src_range.m_start = start; + src_range.m_finish = finish; richloc.add_fixit_replace (src_range, "gtk_widget_show_all"); warning_at_rich_loc (&richloc, 0, "example of a replacement hint"); } @@ -310,7 +305,7 @@ test_show_locus (function *fun) location_t caret_a = get_loc (line, 5); location_t caret_b = get_loc (line - 1, 19); rich_location richloc (line_table, caret_a); - richloc.add_range (caret_b, caret_b, true); + richloc.add_range (caret_b, true); global_dc->caret_chars[0] = '1'; global_dc->caret_chars[1] = '2'; warning_at_rich_loc (&richloc, 0, "test"); |