On 03/03/25 03:05 -0800, yash.shi...@windriver.com wrote:
From: Yash Shinde <yash.shi...@windriver.com>
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.
Thanks for working on this. I don't have any comment on the patch
itself (and I can't approve it anyway) but please format the git
commit message with shorter lines.
https://cbea.ms/git-commit/ is great advice, although we're more
lenient than 50 characters for the summary line (because once you've
added the "libcpp:" component prefix and the "[PR108900]" syffix, 50
chars wouldn't leave you much to describe it!)
We also need a GNU-style ChangeLog in the commit message, which for
this commit would be something like:
libcpp/ChangeLog:
* files.cc (_cpp_stack_file): Do not decrement highest_location
across distinct maps.
Signed-off-by: Jeremy Bettis <jbet...@google.com>
Signed-off-by: Yash Shinde <yash.shi...@windriver.com>
I assume these sign-offs are in-line with the rules at
https://gcc.gnu.org/dco.html (and not just put there because that's
what other patches do :-)
Thanks again!
---
libcpp/files.cc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libcpp/files.cc b/libcpp/files.cc
index 1ed19c5555a..3e6ca119ad5 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1046,6 +1046,14 @@ _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--;
--
2.43.0