Hi! Here is the 14 branch version of the PR120061 fix I've just posted for 16/15. The differences from the earlier patch are all caused by the 32-bit location_t on the branch instead of 64-bit location_t that 16/15 has. So, it needs 1 << whatever instead of loc_one << whatever in the sources, and more importantly, in the testcases deal with different cut off values.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for 14 branch? Also tested with pre- r14-11679 14 branch, where I get FAIL: gcc.dg/plugin/location-overflow-test-pr116047.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*6[^\n\r]*== 6 and with vanilla 14 branch I get FAIL: gcc.dg/plugin/location-overflow-test-pr120061.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*5[^\n\r]*== 5 and with the patch on 14 branch I get all PASSes. 2025-05-06 Jakub Jelinek <ja...@redhat.com> PR preprocessor/108900 PR preprocessor/116047 PR preprocessor/120061 * files.cc (_cpp_stack_file): Revert 2025-03-28 change. * line-map.cc (linemap_add): Use SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; instead of SOURCE_LINE (from, from[1].start_location); to compute to_line for LC_LEAVE if from[1].reason is LC_RENAME. For LC_ENTER included_from computation, look at map[-2] or even lower if map[-1] has the same start_location as map[0]. * gcc.dg/plugin/plugin.exp: Add location-overflow-test-pr116047.c and location-overflow-test-pr120061.c. * gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Don't error on unknown values, instead just break. * gcc.dg/plugin/location-overflow-test-pr116047.c: New test. * gcc.dg/plugin/location-overflow-test-pr116047-1.h: New test. * gcc.dg/plugin/location-overflow-test-pr116047-2.h: New test. * gcc.dg/plugin/location-overflow-test-pr120061.c: New test. * gcc.dg/plugin/location-overflow-test-pr120061-1.h: New test. * gcc.dg/plugin/location-overflow-test-pr120061-2.h: New test. --- 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-06 00:57:23.488499702 +0200 @@ -627,7 +627,10 @@ linemap_add (line_maps *set, enum lc_rea if (to_file == NULL) { to_file = ORDINARY_MAP_FILE_NAME (from); - to_line = SOURCE_LINE (from, from[1].start_location); + if (from[1].reason == LC_RENAME) + to_line = SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; + else + to_line = SOURCE_LINE (from, from[1].start_location); sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from); } else @@ -657,11 +660,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); --- gcc/testsuite/gcc.dg/plugin/plugin.exp.jj 2024-04-26 11:46:58.650218626 +0200 +++ gcc/testsuite/gcc.dg/plugin/plugin.exp 2025-05-06 10:01:10.543208267 +0200 @@ -126,7 +126,9 @@ set plugin_test_list [list \ { location_overflow_plugin.c \ location-overflow-test-1.c \ location-overflow-test-2.c \ - location-overflow-test-pr83173.c } \ + location-overflow-test-pr83173.c \ + location-overflow-test-pr116047.c \ + location-overflow-test-pr120061.c } \ { must_tail_call_plugin.c \ must-tail-call-1.c \ must-tail-call-2.c } \ --- gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c.jj 2024-04-26 11:46:58.650218626 +0200 +++ gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c 2025-05-06 10:01:23.602029841 +0200 @@ -101,7 +101,7 @@ plugin_init (struct plugin_name_args *pl break; default: - error_at (UNKNOWN_LOCATION, "unrecognized value for plugin argument"); + break; } return 0; --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047.c.jj 2025-05-06 08:56:14.311445940 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047.c 2025-05-06 09:52:37.909212363 +0200 @@ -0,0 +1,5 @@ +/* PR preprocessor/116047 */ +/* { dg-do preprocess } */ +/* { dg-options "-nostdinc -std=c23 -fplugin-arg-location_overflow_plugin-value=0x4fff8080" } */ +#include "location-overflow-test-pr116047-1.h" +/* { dg-final { scan-file location-overflow-test-pr116047.i "static_assert\[^\n\r]\*6\[^\n\r]\*== 6" } } */ --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047-1.h.jj 2025-05-06 08:57:39.624279475 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047-1.h 2025-05-06 09:47:57.586042403 +0200 @@ -0,0 +1,6 @@ + + + + +#include "location-overflow-test-pr116047-2.h" +static_assert (__LINE__ == 6, ""); --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047-2.h.jj 2025-05-06 08:57:52.869098384 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr116047-2.h 2025-05-05 12:27:34.907854863 +0200 @@ -0,0 +1 @@ +int i; --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061.c.jj 2025-05-06 09:49:58.153395094 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061.c 2025-05-06 09:55:41.382705568 +0200 @@ -0,0 +1,6 @@ +/* PR preprocessor/120061 */ +/* { dg-do preprocess } */ +/* { dg-options "-nostdinc -std=c23 -fplugin-arg-location_overflow_plugin-value=0x61000000" } */ +#include "location-overflow-test-pr120061-1.h" +static_assert (__LINE__ == 5, ""); +/* { dg-final { scan-file location-overflow-test-pr120061.i "static_assert\[^\n\r]\*5\[^\n\r]\*== 5" } } */ --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061-1.h.jj 2025-05-06 08:57:39.624279475 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061-1.h 2025-05-06 09:55:48.417609451 +0200 @@ -0,0 +1,6 @@ + + + + +#include "location-overflow-test-pr120061-2.h" + --- gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061-2.h.jj 2025-05-06 08:57:52.869098384 +0200 +++ gcc/testsuite/gcc.dg/plugin/location-overflow-test-pr120061-2.h 2025-05-05 12:27:34.907854863 +0200 @@ -0,0 +1 @@ +int i; Jakub