]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
preprocessor: Fix column adjustment [PR 99446]
authorNathan Sidwell <nathan@acm.org>
Tue, 13 Apr 2021 12:03:19 +0000 (05:03 -0700)
committerNathan Sidwell <nathan@acm.org>
Tue, 13 Apr 2021 12:07:23 +0000 (05:07 -0700)
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.

gcc/testsuite/g++.dg/diagnostic/pr72803.C
libcpp/line-map.c

index 0a9a390b9c33d523d49777b31b1dfaf98299c3e3..ca522b74bad243241a41b428b3e0f6356a91b531 100644 (file)
@@ -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 }
index 1bf0e8211f20f8a4928bc812bcee3cfd9cba3ee2..2f5e44447d24e9cc3fd2f314d5825d0fa16ad028 100644 (file)
@@ -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;