aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2024-10-28 12:49:28 -0700
committerJan Svoboda <jan_svoboda@apple.com>2024-10-28 12:50:53 -0700
commit19131c7f36e047898ea954ee5a187ac62f2ab09b (patch)
tree55191ed8893f1c496afa585461e73d6c55217a9e
parentad5b9441f949716570e89fcb27b76e9bfb4b7f70 (diff)
downloadllvm-19131c7f36e047898ea954ee5a187ac62f2ab09b.zip
llvm-19131c7f36e047898ea954ee5a187ac62f2ab09b.tar.gz
llvm-19131c7f36e047898ea954ee5a187ac62f2ab09b.tar.bz2
[clang][modules][lldb] Fix build after #113391
Instead of changing the return type of `ModuleMap::findOrCreateModule`, this patch adds a counterpart that only returns `Module *` and thus has the same signature as `createModule()`, which is important in `ASTReader`.
-rw-r--r--clang/include/clang/Lex/ModuleMap.h14
-rw-r--r--clang/lib/Lex/ModuleMap.cpp23
-rw-r--r--clang/lib/Serialization/ASTReader.cpp5
3 files changed, 27 insertions, 15 deletions
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 5ee152e4..53e9e0e 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -541,9 +541,17 @@ public:
///
/// \param IsExplicit Whether this is an explicit submodule.
///
- /// \returns The found or newly-created module.
- Module *findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
- bool IsExplicit);
+ /// \returns The found or newly-created module, along with a boolean value
+ /// that will be true if the module is newly-created.
+ std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
+ bool IsFramework,
+ bool IsExplicit);
+ /// Call \c ModuleMap::findOrCreateModule and throw away the information
+ /// whether the module was found or created.
+ Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
+ bool IsFramework, bool IsExplicit) {
+ return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;
+ }
/// Create new submodule, assuming it does not exist. This function can only
/// be called when it is guaranteed that this submodule does not exist yet.
/// The parameters have same semantics as \c ModuleMap::findOrCreateModule.
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 1077442..dc9d2bf 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -655,8 +655,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
SmallString<32> NameBuf;
StringRef Name = sanitizeFilenameAsIdentifier(
llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
- Result =
- findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
+ Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
+ Explicit);
setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
// Associate the module and the directory.
@@ -672,8 +672,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
SmallString<32> NameBuf;
StringRef Name = sanitizeFilenameAsIdentifier(
llvm::sys::path::stem(File.getName()), NameBuf);
- Result =
- findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
+ Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
+ Explicit);
setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
Result->addTopHeader(File);
@@ -857,14 +857,17 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
return Context->findSubmodule(Name);
}
-Module *ModuleMap::findOrCreateModule(StringRef Name, Module *Parent,
- bool IsFramework, bool IsExplicit) {
+std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
+ Module *Parent,
+ bool IsFramework,
+ bool IsExplicit) {
// Try to find an existing module with this name.
if (Module *Sub = lookupModuleQualified(Name, Parent))
- return Sub;
+ return std::make_pair(Sub, false);
// Create a new module with this name.
- return createModule(Name, Parent, IsFramework, IsExplicit);
+ Module *M = createModule(Name, Parent, IsFramework, IsExplicit);
+ return std::make_pair(M, true);
}
Module *ModuleMap::createModule(StringRef Name, Module *Parent,
@@ -2129,8 +2132,8 @@ void ModuleMapParser::parseModuleDecl() {
ActiveModule =
Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
} else {
- ActiveModule =
- Map.findOrCreateModule(ModuleName, ActiveModule, Framework, Explicit);
+ ActiveModule = Map.findOrCreateModuleFirst(ModuleName, ActiveModule,
+ Framework, Explicit);
}
ActiveModule->DefinitionLoc = ModuleNameLoc;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 74a79ac..8d8f937 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5760,8 +5760,9 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
// If we don't know the top-level module, there's no point in doing qualified
// lookup of its submodules; it won't find anything anywhere within this tree.
// Let's skip that and avoid some string lookups.
- auto CreateModule = !KnowsTopLevelModule ? &ModuleMap::createModule
- : &ModuleMap::findOrCreateModule;
+ auto CreateModule = !KnowsTopLevelModule
+ ? &ModuleMap::createModule
+ : &ModuleMap::findOrCreateModuleFirst;
bool First = true;
Module *CurrentModule = nullptr;