From da1a16ae10177494c7cae929bec987e90a160403 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 28 Oct 2024 11:24:27 -0700 Subject: [clang][modules] Preserve the module map that allowed inferring (#113389) With inferred modules, the dependency scanner takes care to replace the fake "__inferred_module.map" path with the file that allowed the module to be inferred. However, this only worked when such a module was imported directly in the TU. Whenever such module got loaded transitively, the scanner would fail to perform the replacement. This is caused by the fact that PCM files are lossy and drop this information. This patch makes sure that PCMs include this file for each submodule (in the `SUBMODULE_DEFINITION` record), fixes one existing test with an incorrect assertion, and does a little drive-by refactoring of `ModuleMap`. --- clang/lib/Lex/ModuleMap.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'clang/lib/Lex/ModuleMap.cpp') diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index bc76a54..201ab91 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -657,8 +657,7 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) { llvm::sys::path::stem(SkippedDir.getName()), NameBuf); Result = findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit).first; - InferredModuleAllowedBy[Result] = UmbrellaModuleMap; - Result->IsInferred = true; + setInferredModuleAllowedBy(Result, UmbrellaModuleMap); // Associate the module and the directory. UmbrellaDirs[SkippedDir] = Result; @@ -675,8 +674,7 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) { llvm::sys::path::stem(File.getName()), NameBuf); Result = findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit).first; - InferredModuleAllowedBy[Result] = UmbrellaModuleMap; - Result->IsInferred = true; + setInferredModuleAllowedBy(Result, UmbrellaModuleMap); Result->addTopHeader(File); // If inferred submodules export everything they import, add a @@ -1097,8 +1095,7 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir, Module *Result = new (ModulesAlloc.Allocate()) Module(ModuleConstructorTag{}, ModuleName, SourceLocation(), Parent, /*IsFramework=*/true, /*IsExplicit=*/false, NumCreatedModules++); - InferredModuleAllowedBy[Result] = ModuleMapFID; - Result->IsInferred = true; + setInferredModuleAllowedBy(Result, ModuleMapFID); if (!Parent) { if (LangOpts.CurrentModule == ModuleName) SourceModule = Result; @@ -1346,7 +1343,7 @@ ModuleMap::getModuleMapFileForUniquing(const Module *M) const { } void ModuleMap::setInferredModuleAllowedBy(Module *M, FileID ModMapFID) { - assert(M->IsInferred && "module not inferred"); + M->IsInferred = true; InferredModuleAllowedBy[M] = ModMapFID; } -- cgit v1.1