From f79520bb110d31c9d2e06d463e7d8a3eb437225e Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 7 Dec 2015 16:07:00 +0000 Subject: Fix missing range information for "%q+D" format code gcc/c-family/ChangeLog: * c-common.c (c_cpp_error): Update for change to rich_location::set_range. gcc/fortran/ChangeLog: * error.c (gfc_format_decoder): Update for change of text_info::set_range to text_info::set_location. gcc/ChangeLog: * pretty-print.c (text_info::set_range): Rename to... (text_info::set_location): ...this, converting 2nd param from source_range to a location_t. * pretty-print.h (text_info::set_location): Convert from inline function to external definition. (text_info::set_range): Delete. gcc/testsuite/ChangeLog: * gcc.dg/diagnostic-ranges-1.c: New test file. * gcc.dg/plugin/diagnostic-test-show-locus-bw.c (test_percent_q_plus_d): New test function. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Rewrite test code using rich_location::set_range. Add code to unit-test the "%q+D" format code. libcpp/ChangeLog: * include/line-map.h (rich_location::set_range): Add line_maps * param; convert param from source_range to source_location. Drop "overwrite_loc_p" param. * line-map.c (rich_location::set_range): Likewise, acting as if "overwrite_loc_p" were true, and getting range from the location. From-SVN: r231367 --- libcpp/ChangeLog | 8 ++++++++ libcpp/include/line-map.h | 4 ++-- libcpp/line-map.c | 35 ++++++++++++++++++----------------- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 78a0d7c..9b296fd 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2015-12-07 David Malcolm + + * include/line-map.h (rich_location::set_range): Add line_maps * + param; convert param from source_range to source_location. Drop + "overwrite_loc_p" param. + * line-map.c (rich_location::set_range): Likewise, acting as if + "overwrite_loc_p" were true, and getting range from the location. + 2015-11-20 David Malcolm PR 62314 diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 4f440fa..73c583e 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1376,8 +1376,8 @@ class rich_location add_range (location_range *src_range); void - set_range (unsigned int idx, source_range src_range, - bool show_caret_p, bool overwrite_loc_p); + set_range (line_maps *set, unsigned int idx, source_location loc, + bool show_caret_p); unsigned int get_num_locations () const { return m_num_ranges; } diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 4284303..209d0fb 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -2064,23 +2064,22 @@ rich_location::add_range (location_range *src_range) m_ranges[m_num_ranges++] = *src_range; } -/* Add or overwrite the range given by IDX. It must either - overwrite an existing range, or add one *exactly* on the end of - the array. +/* Add or overwrite the location given by IDX, setting its location to LOC, + and setting its "should my caret be printed" flag to SHOW_CARET_P. - This is primarily for use by gcc when implementing diagnostic - format decoders e.g. the "+" in the C/C++ frontends, for handling - format codes like "%q+D" (which writes the source location of a - tree back into range 0 of the rich_location). + It must either overwrite an existing location, or add one *exactly* on + the end of the array. - If SHOW_CARET_P is true, then the range should be rendered with - a caret at its starting location. This - is for use by the Fortran frontend, for implementing the - "%C" and "%L" format codes. */ + This is primarily for use by gcc when implementing diagnostic format + decoders e.g. + - the "+" in the C/C++ frontends, for handling format codes like "%q+D" + (which writes the source location of a tree back into location 0 of + the rich_location), and + - the "%C" and "%L" format codes in the Fortran frontend. */ void -rich_location::set_range (unsigned int idx, source_range src_range, - bool show_caret_p, bool overwrite_loc_p) +rich_location::set_range (line_maps *set, unsigned int idx, + source_location loc, bool show_caret_p) { linemap_assert (idx < MAX_RANGES); @@ -2088,6 +2087,8 @@ rich_location::set_range (unsigned int idx, source_range src_range, on the end of the array. */ linemap_assert (idx <= m_num_ranges); + source_range src_range = get_range_from_loc (set, loc); + location_range *locrange = &m_ranges[idx]; locrange->m_start = linemap_client_expand_location_to_spelling_point (src_range.m_start); @@ -2095,16 +2096,16 @@ rich_location::set_range (unsigned int idx, source_range src_range, = linemap_client_expand_location_to_spelling_point (src_range.m_finish); locrange->m_show_caret_p = show_caret_p; - if (overwrite_loc_p) - locrange->m_caret = locrange->m_start; + locrange->m_caret + = linemap_client_expand_location_to_spelling_point (loc); /* Are we adding a range onto the end? */ if (idx == m_num_ranges) m_num_ranges = idx + 1; - if (idx == 0 && overwrite_loc_p) + if (idx == 0) { - m_loc = src_range.m_start; + m_loc = loc; /* Mark any cached value here as dirty. */ m_have_expanded_location = false; } -- cgit v1.1