aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-12-07 16:07:00 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-12-07 16:07:00 +0000
commitf79520bb110d31c9d2e06d463e7d8a3eb437225e (patch)
tree4276629584cb83bab17864b868f5ecbcc2a63e89 /gcc
parent4f6788a1717390202936322b1d2377bab6c45c39 (diff)
downloadgcc-f79520bb110d31c9d2e06d463e7d8a3eb437225e.zip
gcc-f79520bb110d31c9d2e06d463e7d8a3eb437225e.tar.gz
gcc-f79520bb110d31c9d2e06d463e7d8a3eb437225e.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-common.c4
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/error.c11
-rw-r--r--gcc/pretty-print.c6
-rw-r--r--gcc/pretty-print.h9
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.dg/diagnostic-ranges-1.c11
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c12
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c27
11 files changed, 83 insertions, 26 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 62a601c..80e8481 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+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>
* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Look inside
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 4668ce6..03a66eb 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+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>
* c-common.c (maybe_warn_shift_overflow): Warn on all overflows if
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f89deb3..9bc02fc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -10161,9 +10161,7 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
gcc_unreachable ();
}
if (done_lexing)
- richloc->set_range (0,
- source_range::from_location (input_location),
- true, true);
+ richloc->set_range (line_table, 0, input_location, true);
diagnostic_set_info_translated (&diagnostic, msg, ap,
richloc, dlevel);
diagnostic_override_option_index (&diagnostic,
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index ba176a1..8e74bec 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+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>
PR fortran/68676
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index b4f7020..8f57aff 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -939,12 +939,11 @@ gfc_format_decoder (pretty_printer *pp,
/* If location[0] != UNKNOWN_LOCATION means that we already
processed one of %C/%L. */
int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1;
- source_range range
- = source_range::from_location (
- linemap_position_for_loc_and_offset (line_table,
- loc->lb->location,
- offset));
- text->set_range (loc_num, range, true);
+ location_t src_loc
+ = linemap_position_for_loc_and_offset (line_table,
+ loc->lb->location,
+ offset);
+ text->set_location (loc_num, src_loc, true);
pp_string (pp, result[loc_num]);
return true;
}
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 4a28d3c..3365074 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -31,14 +31,14 @@ along with GCC; see the file COPYING3. If not see
#include <iconv.h>
#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. */
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);
- m_richloc->set_range (idx, range, caret_p, true);
+ m_richloc->set_range (line_table, idx, loc, show_caret_p);
}
location_t
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index cdee253..3dc1f6b 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -37,14 +37,7 @@ struct text_info
void **x_data;
rich_location *m_richloc;
- inline 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);
+ void set_location (unsigned int idx, location_t loc, bool caret_p);
location_t get_location (unsigned int index_of_location) const;
};
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 46b79e0..93f3af2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+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>
* g++.dg/ipa/pr66896.C: New test.
diff --git a/gcc/testsuite/gcc.dg/diagnostic-ranges-1.c b/gcc/testsuite/gcc.dg/diagnostic-ranges-1.c
new file mode 100644
index 0000000..369c0b3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/diagnostic-ranges-1.c
@@ -0,0 +1,11 @@
+/* { 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 "" } */
+}
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
index 44b47e0..8d44078 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
@@ -190,3 +190,15 @@ void test_fixit_replace (void)
{ dg-end-multiline-output "" } */
#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;
+}
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 7ff2cff..02a2aef 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
@@ -224,9 +224,11 @@ test_show_locus (function *fun)
source_range src_range;
src_range.m_start = get_loc (line, 12);
src_range.m_finish = get_loc (line, 20);
- rich_location richloc (line_table, caret);
- richloc.set_range (0, src_range, true, false);
- warning_at_rich_loc (&richloc, 0, "test");
+ location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
+ caret,
+ src_range,
+ NULL);
+ warning_at (combined_loc, 0, "test");
}
/* Example of a very wide line, where the information of interest
@@ -238,9 +240,11 @@ test_show_locus (function *fun)
source_range src_range;
src_range.m_start = get_loc (line, 90);
src_range.m_finish = get_loc (line, 98);
- rich_location richloc (line_table, caret);
- richloc.set_range (0, src_range, true, false);
- warning_at_rich_loc (&richloc, 0, "test");
+ location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
+ caret,
+ src_range,
+ NULL);
+ warning_at (combined_loc, 0, "test");
}
/* Example of multiple carets. */
@@ -313,6 +317,17 @@ test_show_locus (function *fun)
global_dc->caret_chars[0] = '^';
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