aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-09-23 14:14:52 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-09-23 14:14:52 +0000
commitbbd6fcf320460f29c1ef8c3b42d571238b0f86e5 (patch)
tree4c2c701cee2b268d267262bed245ca34c5893ec9 /libcpp
parent30faeb0f99e8618739217ff3efa930cc382d8448 (diff)
downloadgcc-bbd6fcf320460f29c1ef8c3b42d571238b0f86e5.zip
gcc-bbd6fcf320460f29c1ef8c3b42d571238b0f86e5.tar.gz
gcc-bbd6fcf320460f29c1ef8c3b42d571238b0f86e5.tar.bz2
Provide location information for terminator characters (PR preprocessor/77672)
substring_loc::get_location currently fails for the final terminator character in a STRING_CST from the C frontend, so that format_warning_va falls back to using the location of the string as a whole. This patch tweaks things [1] so that we use the final closing quote as the location of the terminator character, as requested in PR preprocessor/77672. [1] specifically, cpp_interpret_string_1. gcc/ChangeLog: PR preprocessor/77672 * input.c (selftest::test_lexer_string_locations_simple): Update test to expect location information of the terminator character at the location of the final closing quote. (selftest::test_lexer_string_locations_hex): Likewise. (selftest::test_lexer_string_locations_oct): Likewise. (selftest::test_lexer_string_locations_letter_escape_1): Likewise. (selftest::test_lexer_string_locations_letter_escape_2): Likewise. (selftest::test_lexer_string_locations_ucn4): Likewise. (selftest::test_lexer_string_locations_ucn8): Likewise. (selftest::test_lexer_string_locations_u8): Likewise. (selftest::test_lexer_string_locations_utf8_source): Likewise. (selftest::test_lexer_string_locations_concatenation_1): Likewise. (selftest::test_lexer_string_locations_concatenation_2): Likewise. (selftest::test_lexer_string_locations_concatenation_3): Likewise. (selftest::test_lexer_string_locations_macro): Likewise. (selftest::test_lexer_string_locations_long_line): Likewise. gcc/testsuite/ChangeLog: PR preprocessor/77672 * gcc.dg/plugin/diagnostic-test-string-literals-1.c (test_terminator_location): New function. libcpp/ChangeLog: PR preprocessor/77672 * charset.c (cpp_interpret_string_1): Add a source_range for the NUL-terminator, using the location of the trailing quote of the final string. From-SVN: r240434
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/charset.c9
2 files changed, 15 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index e039069..61304cb 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-23 David Malcolm <dmalcolm@redhat.com>
+
+ PR preprocessor/77672
+ * charset.c (cpp_interpret_string_1): Add a source_range for the
+ NUL-terminator, using the location of the trailing quote of the
+ final string.
+
2016-09-21 Jason Merrill <jason@redhat.com>
* line-map.c (linemap_location_from_macro_definition_p): New.
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 6a92ade..e77270a 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1538,9 +1538,9 @@ cpp_interpret_string_1 (cpp_reader *pfile, const cpp_string *from, size_t count,
tbuf.len = 0;
}
+ cpp_string_location_reader *loc_reader = NULL;
for (i = 0; i < count; i++)
{
- cpp_string_location_reader *loc_reader = NULL;
if (loc_readers)
loc_reader = &loc_readers[i];
@@ -1652,6 +1652,13 @@ cpp_interpret_string_1 (cpp_reader *pfile, const cpp_string *from, size_t count,
to->text = tbuf.text;
to->len = tbuf.len;
}
+ /* Use the location of the trailing quote as the location of the
+ NUL-terminator. */
+ if (loc_reader)
+ {
+ source_range range = loc_reader->get_next ();
+ out->add_range (range);
+ }
return true;