[clang] [C++20][Modules] Omit imported PCM file info for explicitly mapped header units (PR #235597)

Michael Park via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 25 23:22:50 PDT 2026


================
@@ -1607,9 +1609,19 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
       AddStringBlob(M.ModuleName, Record, Blob);
       Record.push_back(M.StandardCXXModule);
 
-      // We don't want to hard code the information about imported modules
-      // in the C++20 named modules.
-      if (M.StandardCXXModule) {
+      // We don't want to hard code file information for C++20 Modules
+      // (including explicitly mapped header units).
+      const Module *ImportedModule =
+          PP.getHeaderSearchInfo().getModuleMap().findModule(M.ModuleName);
+      bool IsPrebuiltHeaderUnit =
+          ImportedModule && ImportedModule->isHeaderUnit() &&
+          M.Kind == MK_PrebuiltModule &&
+          HSOpts.PrebuiltModuleFiles.count(M.ModuleName);
+
+      bool HasFileInfo = !M.StandardCXXModule && !IsPrebuiltHeaderUnit;
----------------
mpark wrote:

@ChuanqiXu9 The part that I'm struggling with a bit here is the fact that we can't really implement this behavior for header units in general. Specifically, a header unit that is imported via `-fmodule-file=<pcm>` actually needs the PCM file info embedded. Of course this is kind of weird/awkward as well since IIRC `-fmodule-file=<pcm>` is the official mechanism for header units, but also deprecated? and has eager loading behavior so not really usable in practice (well, at least not for us). I'm trying to understand what your preference is. Would `IsCXX20ModuleOrPrebuiltHeaderUnit` work for you? I don't believe you're asking to remove PCM file info for imported header units in general, right?

https://github.com/llvm/llvm-project/pull/235597


More information about the cfe-commits mailing list