aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2019-03-11 10:37:41 +0100
committerMartin Liska <marxin@gcc.gnu.org>2019-03-11 09:37:41 +0000
commitbfda391bdbd38d916e9007d35ed27abdaf7e39af (patch)
tree14c5ced9d3b28a77676674d6f739823ffed29b21
parentb9ce7ea14f9d5482b2a46b921649956563606a44 (diff)
downloadgcc-bfda391bdbd38d916e9007d35ed27abdaf7e39af.zip
gcc-bfda391bdbd38d916e9007d35ed27abdaf7e39af.tar.gz
gcc-bfda391bdbd38d916e9007d35ed27abdaf7e39af.tar.bz2
Backport r268789
2019-03-11 Martin Liska <mliska@suse.cz> Backport from mainline 2019-02-11 David Malcolm <dmalcolm@redhat.com> PR lto/88147 * input.c (selftest::test_line_offset_overflow): New selftest. (selftest::input_c_tests): Call it. 2019-03-11 Martin Liska <mliska@suse.cz> Backport from mainline 2019-02-11 Martin Liska <mliska@suse.cz> PR lto/88147 * line-map.c (linemap_line_start): Don't reuse the existing line map if the line offset is sufficiently large to cause overflow when computing location_t values. From-SVN: r269570
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/input.c30
-rw-r--r--libcpp/ChangeLog10
-rw-r--r--libcpp/line-map.c4
4 files changed, 53 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7b4f7c0..eae2c4f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2019-03-11 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
+ 2019-02-11 David Malcolm <dmalcolm@redhat.com>
+
+ PR lto/88147
+ * input.c (selftest::test_line_offset_overflow): New selftest.
+ (selftest::input_c_tests): Call it.
+
2019-03-08 Martin Jambor <mjambor@suse.cz>
Backport from mainline
diff --git a/gcc/input.c b/gcc/input.c
index b667576..26c2bf2 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -3538,6 +3538,34 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
ASSERT_EQ (num_cases_tested, 2 * 12);
}
+/* Verify that when presented with a consecutive pair of locations with
+ a very large line offset, we don't attempt to consolidate them into
+ a single ordinary linemap where the line offsets within the line map
+ would lead to overflow (PR lto/88147). */
+
+static void
+test_line_offset_overflow ()
+{
+ line_table_test ltt (line_table_case (5, 0));
+
+ linemap_add (line_table, LC_ENTER, false, "foo.c", 0);
+ linemap_line_start (line_table, 1, 100);
+ location_t loc_a = linemap_line_start (line_table, 2578, 255);
+ assert_loceq ("foo.c", 2578, 0, loc_a);
+
+ const line_map_ordinary *ordmap_a = LINEMAPS_LAST_ORDINARY_MAP (line_table);
+ ASSERT_EQ (ordmap_a->m_column_and_range_bits, 13);
+ ASSERT_EQ (ordmap_a->m_range_bits, 5);
+
+ location_t loc_b = linemap_line_start (line_table, 404198, 512);
+ assert_loceq ("foo.c", 404198, 0, loc_b);
+
+ /* We should have started a new linemap, rather than attempting to store
+ a very large line offset. */
+ const line_map_ordinary *ordmap_b = LINEMAPS_LAST_ORDINARY_MAP (line_table);
+ ASSERT_NE (ordmap_a, ordmap_b);
+}
+
/* Run all of the selftests within this file. */
void
@@ -3577,6 +3605,8 @@ input_c_tests ()
for_each_line_table_case (test_lexer_char_constants);
test_reading_source_line ();
+
+ test_line_offset_overflow ();
}
} // namespace selftest
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index afc70cf..e29f66d 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,13 @@
+2019-03-11 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
+ 2019-02-11 Martin Liska <mliska@suse.cz>
+
+ PR lto/88147
+ * line-map.c (linemap_line_start): Don't reuse the existing line
+ map if the line offset is sufficiently large to cause overflow
+ when computing location_t values.
+
2019-02-22 Release Manager
* GCC 8.3.0 released.
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index a84084c..42aecd6 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -755,6 +755,10 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
if (line_delta < 0
|| last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
|| SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits))
+ || ( /* We can't reuse the map if the line offset is sufficiently
+ large to cause overflow when computing location_t values. */
+ (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
+ >= (1U << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
|| range_bits < map->m_range_bits)
map = linemap_check_ordinary
(const_cast <line_map *>