aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2021-04-13 05:03:19 -0700
committerNathan Sidwell <nathan@acm.org>2021-04-13 05:07:23 -0700
commit4acb3af3669db4ca79ffc97cd615fcea205bcccb (patch)
tree195554064da12db8edf29a3979c14006d5503afe /libcpp
parentf6ba5d039f988babdd99b5cdfb4557c380e57d69 (diff)
downloadgcc-4acb3af3669db4ca79ffc97cd615fcea205bcccb.zip
gcc-4acb3af3669db4ca79ffc97cd615fcea205bcccb.tar.gz
gcc-4acb3af3669db4ca79ffc97cd615fcea205bcccb.tar.bz2
preprocessor: Fix column adjustment [PR 99446]
This ICE was because when adjusting a column offset we could advance into a linemap for a different file. We only checked the next line map was not for a line further advanced in any file, forgetting that it could be for an earlier line in a different file. The testcase needed adjusting as column 512 was unrepresentable, once that was taken into consideration. PR preprocessor/99446 libcpp/ * line-map.c (line-map.c): Do not advance to linemaps for different files. gcc/testsuite/ * g++.dg/diagnostic/pr72803.C: Adjust expected column.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/line-map.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 1bf0e82..2f5e444 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -981,16 +981,15 @@ linemap_position_for_loc_and_offset (line_maps *set,
(loc + offset) should be less than the first location encoded by
the next line map of the set. Otherwise, we try to encode the
location in the next map. */
- while (map != LINEMAPS_LAST_ORDINARY_MAP (set)
- && (loc + (column_offset << map->m_range_bits)
- >= MAP_START_LOCATION (&map[1])))
- {
- map = &map[1];
- /* If the next map starts in a higher line, we cannot encode the
- location there. */
- if (line < ORDINARY_MAP_STARTING_LINE_NUMBER (map))
- return loc;
- }
+ for (; map != LINEMAPS_LAST_ORDINARY_MAP (set)
+ && (loc + (column << map->m_range_bits)
+ >= MAP_START_LOCATION (map + 1)); map++)
+ /* If the next map is a different file, or starts in a higher line, we
+ cannot encode the location there. */
+ if ((map + 1)->reason != LC_RENAME
+ || line < ORDINARY_MAP_STARTING_LINE_NUMBER (map + 1)
+ || 0 != strcmp (LINEMAP_FILE (map + 1), LINEMAP_FILE (map)))
+ return loc;
column += column_offset;