Commit f79520bb by David Malcolm Committed by David Malcolm

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
parent 4f6788a1
2015-12-07 David Malcolm <dmalcolm@redhat.com>
* 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.
2015-12-07 Nathan Sidwell <nathan@acm.org> 2015-12-07 Nathan Sidwell <nathan@acm.org>
* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Look inside * config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Look inside
2015-12-07 David Malcolm <dmalcolm@redhat.com>
* c-common.c (c_cpp_error): Update for change to
rich_location::set_range.
2015-12-04 Paolo Bonzini <bonzini@gnu.org> 2015-12-04 Paolo Bonzini <bonzini@gnu.org>
* c-common.c (maybe_warn_shift_overflow): Warn on all overflows if * c-common.c (maybe_warn_shift_overflow): Warn on all overflows if
......
...@@ -10161,9 +10161,7 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, ...@@ -10161,9 +10161,7 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
gcc_unreachable (); gcc_unreachable ();
} }
if (done_lexing) if (done_lexing)
richloc->set_range (0, richloc->set_range (line_table, 0, input_location, true);
source_range::from_location (input_location),
true, true);
diagnostic_set_info_translated (&diagnostic, msg, ap, diagnostic_set_info_translated (&diagnostic, msg, ap,
richloc, dlevel); richloc, dlevel);
diagnostic_override_option_index (&diagnostic, diagnostic_override_option_index (&diagnostic,
......
2015-12-07 David Malcolm <dmalcolm@redhat.com>
* error.c (gfc_format_decoder): Update for change of
text_info::set_range to text_info::set_location.
2015-12-05 Paul Thomas <pault@gcc.gnu.org> 2015-12-05 Paul Thomas <pault@gcc.gnu.org>
PR fortran/68676 PR fortran/68676
......
...@@ -939,12 +939,11 @@ gfc_format_decoder (pretty_printer *pp, ...@@ -939,12 +939,11 @@ gfc_format_decoder (pretty_printer *pp,
/* If location[0] != UNKNOWN_LOCATION means that we already /* If location[0] != UNKNOWN_LOCATION means that we already
processed one of %C/%L. */ processed one of %C/%L. */
int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1; int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1;
source_range range location_t src_loc
= source_range::from_location ( = linemap_position_for_loc_and_offset (line_table,
linemap_position_for_loc_and_offset (line_table, loc->lb->location,
loc->lb->location, offset);
offset)); text->set_location (loc_num, src_loc, true);
text->set_range (loc_num, range, true);
pp_string (pp, result[loc_num]); pp_string (pp, result[loc_num]);
return true; return true;
} }
......
...@@ -31,14 +31,14 @@ along with GCC; see the file COPYING3. If not see ...@@ -31,14 +31,14 @@ along with GCC; see the file COPYING3. If not see
#include <iconv.h> #include <iconv.h>
#endif #endif
/* Overwrite the range within this text_info's rich_location. /* Overwrite the given location/range within this text_info's rich_location.
For use e.g. when implementing "+" in client format decoders. */ For use e.g. when implementing "+" in client format decoders. */
void void
text_info::set_range (unsigned int idx, source_range range, bool caret_p) text_info::set_location (unsigned int idx, location_t loc, bool show_caret_p)
{ {
gcc_checking_assert (m_richloc); gcc_checking_assert (m_richloc);
m_richloc->set_range (idx, range, caret_p, true); m_richloc->set_range (line_table, idx, loc, show_caret_p);
} }
location_t location_t
......
...@@ -37,14 +37,7 @@ struct text_info ...@@ -37,14 +37,7 @@ struct text_info
void **x_data; void **x_data;
rich_location *m_richloc; rich_location *m_richloc;
inline void set_location (unsigned int idx, location_t loc, bool caret_p) void set_location (unsigned int idx, location_t loc, bool caret_p);
{
source_range src_range;
src_range.m_start = loc;
src_range.m_finish = loc;
set_range (idx, src_range, caret_p);
}
void set_range (unsigned int idx, source_range range, bool caret_p);
location_t get_location (unsigned int index_of_location) const; location_t get_location (unsigned int index_of_location) const;
}; };
......
2015-12-07 David Malcolm <dmalcolm@redhat.com>
* 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.
2015-12-07 Martin Liska <mliska@suse.cz> 2015-12-07 Martin Liska <mliska@suse.cz>
* g++.dg/ipa/pr66896.C: New test. * g++.dg/ipa/pr66896.C: New test.
......
/* { dg-do compile } */
/* { dg-options "-fdiagnostics-show-caret -Wall" } */
void test_range_of_unused_variable (void)
{
int redundant; /* { dg-warning "unused variable" } */
/* { dg-begin-multiline-output "" }
int redundant;
^~~~~~~~~
{ dg-end-multiline-output "" } */
}
...@@ -190,3 +190,15 @@ void test_fixit_replace (void) ...@@ -190,3 +190,15 @@ void test_fixit_replace (void)
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
#endif #endif
} }
/* Test of "%q+D" format code. */
int test_percent_q_plus_d (void)
{
int local = 0; /* { dg-warning "example of plus in format code" } */
/* { dg-begin-multiline-output "" }
int local = 0;
^~~~~
{ dg-end-multiline-output "" } */
return local;
}
...@@ -224,9 +224,11 @@ test_show_locus (function *fun) ...@@ -224,9 +224,11 @@ test_show_locus (function *fun)
source_range src_range; source_range src_range;
src_range.m_start = get_loc (line, 12); src_range.m_start = get_loc (line, 12);
src_range.m_finish = get_loc (line, 20); src_range.m_finish = get_loc (line, 20);
rich_location richloc (line_table, caret); location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
richloc.set_range (0, src_range, true, false); caret,
warning_at_rich_loc (&richloc, 0, "test"); src_range,
NULL);
warning_at (combined_loc, 0, "test");
} }
/* Example of a very wide line, where the information of interest /* Example of a very wide line, where the information of interest
...@@ -238,9 +240,11 @@ test_show_locus (function *fun) ...@@ -238,9 +240,11 @@ test_show_locus (function *fun)
source_range src_range; source_range src_range;
src_range.m_start = get_loc (line, 90); src_range.m_start = get_loc (line, 90);
src_range.m_finish = get_loc (line, 98); src_range.m_finish = get_loc (line, 98);
rich_location richloc (line_table, caret); location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
richloc.set_range (0, src_range, true, false); caret,
warning_at_rich_loc (&richloc, 0, "test"); src_range,
NULL);
warning_at (combined_loc, 0, "test");
} }
/* Example of multiple carets. */ /* Example of multiple carets. */
...@@ -313,6 +317,17 @@ test_show_locus (function *fun) ...@@ -313,6 +317,17 @@ test_show_locus (function *fun)
global_dc->caret_chars[0] = '^'; global_dc->caret_chars[0] = '^';
global_dc->caret_chars[1] = '^'; global_dc->caret_chars[1] = '^';
} }
/* Example of using the "%q+D" format code, which as well as printing
a quoted decl, overrides the given location to use the location of
the decl. */
if (0 == strcmp (fnname, "test_percent_q_plus_d"))
{
const int line = fnstart_line + 3;
tree local = (*fun->local_decls)[0];
warning_at (input_location, 0,
"example of plus in format code for %q+D", local);
}
} }
unsigned int unsigned int
......
2015-12-07 David Malcolm <dmalcolm@redhat.com>
* 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 <dmalcolm@redhat.com> 2015-11-20 David Malcolm <dmalcolm@redhat.com>
PR 62314 PR 62314
......
...@@ -1376,8 +1376,8 @@ class rich_location ...@@ -1376,8 +1376,8 @@ class rich_location
add_range (location_range *src_range); add_range (location_range *src_range);
void void
set_range (unsigned int idx, source_range src_range, set_range (line_maps *set, unsigned int idx, source_location loc,
bool show_caret_p, bool overwrite_loc_p); bool show_caret_p);
unsigned int get_num_locations () const { return m_num_ranges; } unsigned int get_num_locations () const { return m_num_ranges; }
......
...@@ -2064,23 +2064,22 @@ rich_location::add_range (location_range *src_range) ...@@ -2064,23 +2064,22 @@ rich_location::add_range (location_range *src_range)
m_ranges[m_num_ranges++] = *src_range; m_ranges[m_num_ranges++] = *src_range;
} }
/* Add or overwrite the range given by IDX. It must either /* Add or overwrite the location given by IDX, setting its location to LOC,
overwrite an existing range, or add one *exactly* on the end of and setting its "should my caret be printed" flag to SHOW_CARET_P.
the array.
This is primarily for use by gcc when implementing diagnostic It must either overwrite an existing location, or add one *exactly* on
format decoders e.g. the "+" in the C/C++ frontends, for handling the end of the array.
format codes like "%q+D" (which writes the source location of a
tree back into range 0 of the rich_location).
If SHOW_CARET_P is true, then the range should be rendered with This is primarily for use by gcc when implementing diagnostic format
a caret at its starting location. This decoders e.g.
is for use by the Fortran frontend, for implementing the - the "+" in the C/C++ frontends, for handling format codes like "%q+D"
"%C" and "%L" format codes. */ (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 void
rich_location::set_range (unsigned int idx, source_range src_range, rich_location::set_range (line_maps *set, unsigned int idx,
bool show_caret_p, bool overwrite_loc_p) source_location loc, bool show_caret_p)
{ {
linemap_assert (idx < MAX_RANGES); linemap_assert (idx < MAX_RANGES);
...@@ -2088,6 +2087,8 @@ rich_location::set_range (unsigned int idx, source_range src_range, ...@@ -2088,6 +2087,8 @@ rich_location::set_range (unsigned int idx, source_range src_range,
on the end of the array. */ on the end of the array. */
linemap_assert (idx <= m_num_ranges); linemap_assert (idx <= m_num_ranges);
source_range src_range = get_range_from_loc (set, loc);
location_range *locrange = &m_ranges[idx]; location_range *locrange = &m_ranges[idx];
locrange->m_start locrange->m_start
= linemap_client_expand_location_to_spelling_point (src_range.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, ...@@ -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); = linemap_client_expand_location_to_spelling_point (src_range.m_finish);
locrange->m_show_caret_p = show_caret_p; locrange->m_show_caret_p = show_caret_p;
if (overwrite_loc_p) locrange->m_caret
locrange->m_caret = locrange->m_start; = linemap_client_expand_location_to_spelling_point (loc);
/* Are we adding a range onto the end? */ /* Are we adding a range onto the end? */
if (idx == m_num_ranges) if (idx == m_num_ranges)
m_num_ranges = idx + 1; 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. */ /* Mark any cached value here as dirty. */
m_have_expanded_location = false; m_have_expanded_location = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment