aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-01-10 21:54:09 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-01-10 21:54:09 +0000
commitb9f4757f8eb94d4b145613ee5047f3f95452f9d2 (patch)
tree4f329935d56c10c19a73497a7006a9a709292f4f /gcc/cp
parent6fcb740ac456e4703b337584b26305a77a5c5038 (diff)
downloadgcc-b9f4757f8eb94d4b145613ee5047f3f95452f9d2.zip
gcc-b9f4757f8eb94d4b145613ee5047f3f95452f9d2.tar.gz
gcc-b9f4757f8eb94d4b145613ee5047f3f95452f9d2.tar.bz2
Fix issues with unrepresentable column numbers (PR c++/77949)
PR c++/77949 identifies an ICE when the C++ frontend attempts to emit a fix-it hint inserting a missing semicolon at column 4097 of a source file. This column value exceeds LINE_MAP_MAX_COLUMN_NUMBER and hence isn't representable using a location_t. Attempting to do so leads to these problems, which this patch fixes: (a) when encountering a column number > LINE_MAP_MAX_COLUMN_NUMBER we create a new linemap with m_column_and_range_bits == 0, but linemap_position_for_column doesn't check for this, and hence can emit a bogus location_t value that's calculated relative to the previous linemap start, but which will be decoded relative to the new linemap, leading to very large incorrect line values. (b) when encountering a column number that can't be represented, and for which the linemap was pre-existing, the code would hit this assertion: if (linemap_assert_fails (column < (1u << map->m_column_and_range_bits))) around a bail-out condition. The patch replaces this assertion with a simple conditional, to stop the ICE when this occurs, and fixes the bit count (effective column bits, vs column+range bits) (c) the C++ frontend wasn't checking for failure of linemap_position_for_loc_and_offset when considering emitting the fix-it hint. The patch adds a conditional, so that no fix-it hint is emitted if the location is bogus. gcc/cp/ChangeLog: PR c++/77949 * parser.c (cp_parser_class_specifier_1): Only suggest inserting a missing semicolon if we have a valid insertion location for the fix-it hint. gcc/ChangeLog: PR c++/77949 * input.c (selftest::test_accessing_ordinary_linemaps): Verify that we correctly handle column numbers greater than LINE_MAP_MAX_COLUMN_NUMBER. gcc/testsuite/ChangeLog: PR c++/77949 * g++.dg/diagnostic/pr77949.C: New test case. libcpp/ChangeLog: PR c++/77949 * line-map.c (linemap_position_for_column): When calling linemap_start_line, detect if a new linemap was created with 0 column bits, and bail out early if this is the case. (linemap_position_for_loc_and_offset): Replace overzealous linemap_assert_fails with a simple conditional; use correct bit count. From-SVN: r244292
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c5
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 25f5a85..892651a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2017-01-10 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/77949
+ * parser.c (cp_parser_class_specifier_1): Only suggest inserting
+ a missing semicolon if we have a valid insertion location for
+ the fix-it hint.
+
2017-01-10 Jason Merrill <jason@redhat.com>
FI 20, decomposition declaration with parenthesized initializer.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4517313..7b3ee30 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -22164,7 +22164,10 @@ cp_parser_class_specifier_1 (cp_parser* parser)
next_loc = linemap_position_for_loc_and_offset (line_table, loc, 1);
rich_location richloc (line_table, next_loc);
- richloc.add_fixit_insert_before (next_loc, ";");
+
+ /* If we successfully offset the location, suggest the fix-it. */
+ if (next_loc != loc)
+ richloc.add_fixit_insert_before (next_loc, ";");
if (CLASSTYPE_DECLARED_CLASS (type))
error_at_rich_loc (&richloc,