Skip to content

Commit 19131c7

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`.
1 parent ad5b944 commit 19131c7

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
@@ -541,9 +541,17 @@ class ModuleMap {
541541
///
542542
/// \param IsExplicit Whether this is an explicit submodule.
543543
///
544-
/// \returns The found or newly-created module.
545-
Module *findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
546-
bool IsExplicit);
544+
/// \returns The found or newly-created module, along with a boolean value
545+
/// that will be true if the module is newly-created.
546+
std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
547+
bool IsFramework,
548+
bool IsExplicit);
549+
/// Call \c ModuleMap::findOrCreateModule and throw away the information
550+
/// whether the module was found or created.
551+
Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
552+
bool IsFramework, bool IsExplicit) {
553+
return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;
554+
}
547555
/// Create new submodule, assuming it does not exist. This function can only
548556
/// be called when it is guaranteed that this submodule does not exist yet.
549557
/// 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

@@ -857,14 +857,17 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
857857
return Context->findSubmodule(Name);
858858
}
859859

860-
Module *ModuleMap::findOrCreateModule(StringRef Name, Module *Parent,
861-
bool IsFramework, bool IsExplicit) {
860+
std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
861+
Module *Parent,
862+
bool IsFramework,
863+
bool IsExplicit) {
862864
// Try to find an existing module with this name.
863865
if (Module *Sub = lookupModuleQualified(Name, Parent))
864-
return Sub;
866+
return std::make_pair(Sub, false);
865867

866868
// Create a new module with this name.
867-
return createModule(Name, Parent, IsFramework, IsExplicit);
869+
Module *M = createModule(Name, Parent, IsFramework, IsExplicit);
870+
return std::make_pair(M, true);
868871
}
869872

870873
Module *ModuleMap::createModule(StringRef Name, Module *Parent,
@@ -2129,8 +2132,8 @@ void ModuleMapParser::parseModuleDecl() {
21292132
ActiveModule =
21302133
Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
21312134
} else {
2132-
ActiveModule =
2133-
Map.findOrCreateModule(ModuleName, ActiveModule, Framework, Explicit);
2135+
ActiveModule = Map.findOrCreateModuleFirst(ModuleName, ActiveModule,
2136+
Framework, Explicit);
21342137
}
21352138

21362139
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)