public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8150] preprocessor: Fix column adjustment [PR 99446]
@ 2021-04-13 12:07 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2021-04-13 12:07 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4acb3af3669db4ca79ffc97cd615fcea205bcccb
commit r11-8150-g4acb3af3669db4ca79ffc97cd615fcea205bcccb
Author: Nathan Sidwell <nathan@acm.org>
Date: Tue Apr 13 05:03:19 2021 -0700
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.
Diff:
---
gcc/testsuite/g++.dg/diagnostic/pr72803.C | 5 +++--
libcpp/line-map.c | 19 +++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr72803.C b/gcc/testsuite/g++.dg/diagnostic/pr72803.C
index 0a9a390b9c3..ca522b74bad 100644
--- a/gcc/testsuite/g++.dg/diagnostic/pr72803.C
+++ b/gcc/testsuite/g++.dg/diagnostic/pr72803.C
@@ -5,5 +5,6 @@ class test {
// The line directive appears to be necessary to trigger the ICE
// { dg-error "style of line directive is a GCC extension" "" { target *-*-* } .-2 }
-/* Verify that we get the correct line and column for the diagnostic. */
-// { dg-error "512: expected .;. after class definition" "" { target *-*-* } 3 }
+/* Verify that we get the best line and column for the diagnostic.
+ 512 is not representable in the line-maps created for this test. */
+// { dg-error "511: expected .;. after class definition" "" { target *-*-* } 3 }
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 1bf0e8211f2..2f5e44447d2 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-13 12:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 12:07 [gcc r11-8150] preprocessor: Fix column adjustment [PR 99446] Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).