]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Handle location exhaustion in write_location [PR105443]
authorNathaniel Shead <nathanieloshead@gmail.com>
Mon, 4 Nov 2024 16:08:54 +0000 (03:08 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 5 Nov 2024 00:28:19 +0000 (11:28 +1100)
commit48ef485eabc8fd3e16d184860ce693816f3919eb
tree344060211eaa76d247b82df8a917c3812e2a3181
parentad1f112980040ba7bb8b8d0b9273268d4d710c9e
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 <nathanieloshead@gmail.com>
gcc/cp/module.cc