]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Fix include translation for already-seen headers [PR99243]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 22 Aug 2024 10:41:54 +0000 (20:41 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 27 Aug 2024 01:03:14 +0000 (11:03 +1000)
commit215ff991a8681f968823b913e1c79a32d339c097
tree3b876afa736d9ff4199992a5b2f454509d26ef74
parent98608342932e8951a4c8db3e9df79f9187424d53
c++/modules: Fix include translation for already-seen headers [PR99243]

After importing a header unit we learn about and setup any header
modules that we transitively depend on.  However, this causes
'set_filename' to fail an assertion if we then come across this header
as an #include and attempt to translate it into a module.  We still need
to do this translation so that libcpp learns that this is a header unit,
but we shouldn't error just because we've already seen it as an import.

Instead this patch merely checks and errors to handle the case of a
broken mapper implementation which supplies a different CMI path from
the one we already got.

As a drive-by fix, also make failing to find the CMI for a module be a
fatal error: any further errors in the TU are unlikely to be helpful.

PR c++/99243

gcc/cp/ChangeLog:

* module.cc (module_state::set_filename): Handle repeated calls
to 'set_filename' as long as the CMI path matches.
(maybe_translate_include): Adjust comment.

gcc/testsuite/ChangeLog:

* g++.dg/modules/map-2.C: Prune additional fatal error message.
* g++.dg/modules/inc-xlate-4_a.H: New test.
* g++.dg/modules/inc-xlate-4_b.H: New test.
* g++.dg/modules/inc-xlate-4_c.H: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/inc-xlate-4_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/inc-xlate-4_b.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/inc-xlate-4_c.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/map-2.C