https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105443
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>: https://gcc.gnu.org/g:48ef485eabc8fd3e16d184860ce693816f3919eb commit r15-4943-g48ef485eabc8fd3e16d184860ce693816f3919eb Author: Nathaniel Shead <nathanielosh...@gmail.com> Date: Tue Nov 5 03:08:54 2024 +1100 c++/modules: Handle location exhaustion in write_location [PR105443] The 'location_t' type currently only stores a limited number of distinct locations. In some cases, if many modules are imported that sum up to a large number of locations, we may run out of room to represent new locations for these imported declarations. In such a case, any new declarations from the affected modules simply get given a location of "the module interface as a whole". 'write_location' sometimes gets confused when this happens: it finds that the location is a location we've noted to get streamed out, but it's inconsistent whether it's an ordinary location from the current module or an imported location from a different module. This causes random-looking locations to be associated with these declarations, and occasionally (checking-only) ICEs. This patch fixes the issue by first checking whether an ordinary location represents a module (rather than a location inside a module); if so, we instead write the location of the point that we imported this module. This will continue recursively in case the importing location also was not able to be stored. We only need to handle this in the IS_ORDINARY_LOC case: even for locations originally within macro expansions, the remapping logic for location exhaustion will make them look like ordinary locs again. This is a relatively expensive addition, so this new check only occurs if we've noted resource exhaustion has occurred while preparing imported line maps, or in checking builds. PR c++/105443 gcc/cp/ChangeLog: * module.cc (loc_spans::locs_exhausted_p): New field. (loc_spans::loc_spans): Initialise it. (loc_spans::locations_exhausted_p): New function. (module_state::read_prepare_maps): Move inform into... (loc_spans::report_location_exhaustion): ...this new function. (module_state::write_location): Check for writing module locations stored due to resource exhaustion. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>