]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: Fix incorrect line numbers in large files [PR108900]
authorJeremy Bettis <jbettis@google.com>
Fri, 28 Mar 2025 07:54:27 +0000 (00:54 -0700)
committerJason Merrill <jason@redhat.com>
Fri, 28 Mar 2025 22:19:41 +0000 (18:19 -0400)
This patch addresses an issue in the C preprocessor where incorrect
line number information is generated when processing files with a
large number of lines. The problem arises from improper handling
of location intervals in the line map, particularly when locations
exceed LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES.

By ensuring that the highest location is not decremented if it
would move to a different ordinary map, this fix resolves
the line number discrepancies observed in certain test cases.
This change improves the accuracy of line number reporting, benefiting
users relying on precise code coverage and debugging information.

libcpp/ChangeLog:

PR preprocessor/108900
* files.cc (_cpp_stack_file): Do not decrement highest_location
across distinct maps.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
libcpp/files.cc

index 1ed19c5555a16d60bd934751f945f42d29d3ae3b..c1abde6639fe7a5ef3486987775d6c06c8f9fc37 100644 (file)
@@ -1046,6 +1046,15 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
                    && type < IT_DIRECTIVE_HWM
                    && (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--;