aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/module.cc
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-08-22 20:41:54 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2024-08-27 11:03:14 +1000
commit215ff991a8681f968823b913e1c79a32d339c097 (patch)
tree3b876afa736d9ff4199992a5b2f454509d26ef74 /gcc/cp/module.cc
parent98608342932e8951a4c8db3e9df79f9187424d53 (diff)
downloadgcc-215ff991a8681f968823b913e1c79a32d339c097.zip
gcc-215ff991a8681f968823b913e1c79a32d339c097.tar.gz
gcc-215ff991a8681f968823b913e1c79a32d339c097.tar.bz2
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>
Diffstat (limited to 'gcc/cp/module.cc')
-rw-r--r--gcc/cp/module.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 4cd7e1c..95c2405 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -20086,14 +20086,21 @@ canonicalize_header_name (cpp_reader *reader, location_t loc, bool unquoted,
void module_state::set_filename (const Cody::Packet &packet)
{
- gcc_checking_assert (!filename);
if (packet.GetCode () == Cody::Client::PC_PATHNAME)
- filename = xstrdup (packet.GetString ().c_str ());
+ {
+ /* If we've seen this import before we better have the same CMI. */
+ const std::string &path = packet.GetString ();
+ if (!filename)
+ filename = xstrdup (packet.GetString ().c_str ());
+ else if (filename != path)
+ error_at (loc, "mismatching compiled module interface: "
+ "had %qs, got %qs", filename, path.c_str ());
+ }
else
{
gcc_checking_assert (packet.GetCode () == Cody::Client::PC_ERROR);
- error_at (loc, "unknown Compiled Module Interface: %s",
- packet.GetString ().c_str ());
+ fatal_error (loc, "unknown compiled module interface: %s",
+ packet.GetString ().c_str ());
}
}
@@ -20127,7 +20134,8 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
translate = packet.GetInteger () ? xlate_kind::text : xlate_kind::unknown;
else if (packet.GetCode () == Cody::Client::PC_PATHNAME)
{
- /* Record the CMI name for when we do the import. */
+ /* Record the CMI name for when we do the import.
+ We may already know about this import, but libcpp doesn't yet. */
module_state *import = get_module (build_string (len, path));
import->set_filename (packet);
translate = xlate_kind::import;