https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061

--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Unfortunately
--- libcpp/files.cc.jj  2025-05-03 11:02:02.502647404 +0200
+++ libcpp/files.cc     2025-05-05 21:09:18.042680877 +0200
@@ -1006,14 +1006,6 @@ _cpp_stack_file (cpp_reader *pfile, _cpp
                    && (pfile->line_table->highest_location
                        != LINE_MAP_MAX_LOCATION - 1));

-  if (decrement && LINEMAPS_ORDINARY_USED (pfile->line_table))
-    {
-      const line_map_ordinary *map
-       = LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table);
-      if (map && map->start_location == pfile->line_table->highest_location)
-       decrement = false;
-    }
-
   if (decrement)
     pfile->line_table->highest_location--;

--- libcpp/line-map.cc.jj       2024-04-26 11:47:02.244168816 +0200
+++ libcpp/line-map.cc  2025-05-05 21:12:23.480193513 +0200
@@ -657,11 +657,16 @@ linemap_add (line_maps *set, enum lc_rea
       if (set->depth == 0)
        map->included_from = 0;
       else
-       /* The location of the end of the just-closed map.  */
-       map->included_from
-         = (((map[0].start_location - 1 - map[-1].start_location)
-             & ~((1 << map[-1].m_column_and_range_bits) - 1))
-            + map[-1].start_location);
+       {
+         /* The location of the end of the just-closed map.  */
+         int i = -1;
+         while (map[i].start_location == map[0].start_location)
+           --i;
+         map->included_from
+           = (((map[0].start_location - 1 - map[i].start_location)
+               & ~((1 << map[i].m_column_and_range_bits) - 1))
+              + map[i].start_location);
+       }
       set->depth++;
       if (set->trace_includes)
        trace_include (set, map);
doesn't help for #c11 (#c12 and #c13 still pass like with just the files.cc
hunk aka reversion).
While it computes smaller map->included_from (with just files.cc hunk
0x50000320,
with this added one 0x50000080):
(gdb) p expand_location (0x50000320)
$108 = {file = 0x4343150 "pr116047-1.h", line = 327677, column = 21, data =
0x0, sysp = false}
(gdb) p expand_location (0x50000080)
$109 = {file = 0x4343150 "pr116047-1.h", line = 327677, column = 0, data = 0x0,
sysp = false}
so the patched one looks more correct because it maps to the start of the line
with #include, the later
          to_line = SOURCE_LINE (from, from[1].start_location);
still doesn't work, as 0x500003a0 is still not 1 << 12 higher than 0x50000080,
that is
0x50001080, but linemap_line_start doesn't bother to increase uselessly
highest_location and highest_line when it is creating a new map.

Though, I wonder why we do that
          to_line = SOURCE_LINE (from, from[1].start_location);
and not e.g.
          to_line = SOURCE_LINE (from, linemap_included_from (map)) + 1;
instead.

Reply via email to