diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -85,6 +85,21 @@ assert(Module && !Module->IsFromModuleFile && "trying to re-write a module?"); + // Here we would ideally use a P1184 server to find the module name. + // However, in the short-term we are going to (ab-)use the name/file pairs + // that can be specified with -fmodule-file=Name=Path. If there is no + // entry there, then we fall back to the default CMI name, based on the + // source file name. + HeaderSearch &HS = PP.getHeaderSearchInfo(); + const HeaderSearchOptions &HSOpts = HS.getHeaderSearchOpts(); + std::string ModuleFilename; + if (!HSOpts.PrebuiltModuleFiles.empty() || + !HSOpts.PrebuiltModulePaths.empty()) + ModuleFilename = HS.getPrebuiltModuleFileName(Module->Name); + + if (!ModuleFilename.empty()) + OutputFile = ModuleFilename; + // So now attach that name to the buffer we are about to create. Buffer->PresumedFileName = OutputFile; } diff --git a/clang/lib/Serialization/PCHContainerOperations.cpp b/clang/lib/Serialization/PCHContainerOperations.cpp --- a/clang/lib/Serialization/PCHContainerOperations.cpp +++ b/clang/lib/Serialization/PCHContainerOperations.cpp @@ -77,6 +77,7 @@ OS.reset(new llvm::raw_fd_ostream(FD, /*shouldClose=*/true)); *OS << Buffer->Data; OS->flush(); // Make sure it hits disk now. + // Here we would notify P1184 servers that the module is created } else llvm::dbgs() << " Problem creating : " << Buffer->PresumedFileName << "\n";