aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2024-10-28 11:24:27 -0700
committerGitHub <noreply@github.com>2024-10-28 11:24:27 -0700
commitda1a16ae10177494c7cae929bec987e90a160403 (patch)
tree1f7a954c5a3726604404b5dcd2b209b2133cac16 /clang/lib/Lex/ModuleMap.cpp
parent19c0a74ad6baa9eb38dbe0a20af7c67999c41821 (diff)
downloadllvm-da1a16ae10177494c7cae929bec987e90a160403.zip
llvm-da1a16ae10177494c7cae929bec987e90a160403.tar.gz
llvm-da1a16ae10177494c7cae929bec987e90a160403.tar.bz2
[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`.
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp11
1 files changed, 4 insertions, 7 deletions
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;
}