Skip to content

Commit 397c2ee

Browse files
committed
[clang][modules][lldb] Fix build after llvm#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`. (cherry picked from commit 19131c7)
1 parent eedbf7c commit 397c2ee

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

clang/include/clang/Lex/ModuleMap.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,17 @@ class ModuleMap {
552552
///
553553
/// \param IsExplicit Whether this is an explicit submodule.
554554
///
555-
/// \returns The found or newly-created module.
556-
Module *findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
557-
bool IsExplicit);
555+
/// \returns The found or newly-created module, along with a boolean value
556+
/// that will be true if the module is newly-created.
557+
std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
558+
bool IsFramework,
559+
bool IsExplicit);
560+
/// Call \c ModuleMap::findOrCreateModule and throw away the information
561+
/// whether the module was found or created.
562+
Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
563+
bool IsFramework, bool IsExplicit) {
564+
return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;
565+
}
558566
/// Create new submodule, assuming it does not exist. This function can only
559567
/// be called when it is guaranteed that this submodule does not exist yet.
560568
/// The parameters have same semantics as \c ModuleMap::findOrCreateModule.

clang/lib/Lex/ModuleMap.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
655655
SmallString<32> NameBuf;
656656
StringRef Name = sanitizeFilenameAsIdentifier(
657657
llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
658-
Result =
659-
findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
658+
Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
659+
Explicit);
660660
setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
661661

662662
// Associate the module and the directory.
@@ -672,8 +672,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
672672
SmallString<32> NameBuf;
673673
StringRef Name = sanitizeFilenameAsIdentifier(
674674
llvm::sys::path::stem(File.getName()), NameBuf);
675-
Result =
676-
findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
675+
Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
676+
Explicit);
677677
setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
678678
Result->addTopHeader(File);
679679

@@ -866,14 +866,17 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
866866
return Context->findSubmodule(Name);
867867
}
868868

869-
Module *ModuleMap::findOrCreateModule(StringRef Name, Module *Parent,
870-
bool IsFramework, bool IsExplicit) {
869+
std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
870+
Module *Parent,
871+
bool IsFramework,
872+
bool IsExplicit) {
871873
// Try to find an existing module with this name.
872874
if (Module *Sub = lookupModuleQualified(Name, Parent))
873-
return Sub;
875+
return std::make_pair(Sub, false);
874876

875877
// Create a new module with this name.
876-
return createModule(Name, Parent, IsFramework, IsExplicit);
878+
Module *M = createModule(Name, Parent, IsFramework, IsExplicit);
879+
return std::make_pair(M, true);
877880
}
878881

879882
Module *ModuleMap::createModule(StringRef Name, Module *Parent,
@@ -2140,8 +2143,8 @@ void ModuleMapParser::parseModuleDecl() {
21402143
ActiveModule =
21412144
Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
21422145
} else {
2143-
ActiveModule =
2144-
Map.findOrCreateModule(ModuleName, ActiveModule, Framework, Explicit);
2146+
ActiveModule = Map.findOrCreateModuleFirst(ModuleName, ActiveModule,
2147+
Framework, Explicit);
21452148
}
21462149

21472150
ActiveModule->DefinitionLoc = ModuleNameLoc;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5760,8 +5760,9 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
57605760
// If we don't know the top-level module, there's no point in doing qualified
57615761
// lookup of its submodules; it won't find anything anywhere within this tree.
57625762
// Let's skip that and avoid some string lookups.
5763-
auto CreateModule = !KnowsTopLevelModule ? &ModuleMap::createModule
5764-
: &ModuleMap::findOrCreateModule;
5763+
auto CreateModule = !KnowsTopLevelModule
5764+
? &ModuleMap::createModule
5765+
: &ModuleMap::findOrCreateModuleFirst;
57655766

57665767
bool First = true;
57675768
Module *CurrentModule = nullptr;

0 commit comments

Comments
 (0)