From 5ea78c4113f8d2c8be24152f2dd0cadaea352c9d Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Tue, 4 Oct 2022 15:08:08 -0700 Subject: [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef Update SourceManager::ContentCache::OrigEntry to keep the original FileEntryRef, and use that to enable ModuleMap::getModuleMapFile* to return the original FileEntryRef. This change should be NFC for most users of SourceManager::ContentCache, but it could affect behaviour for users of getNameAsRequested such as in compileModuleImpl. I have not found a way to detect that difference without additional functional changes, other than incidental cases like changes from / to \ on Windows so there is no new test. Differential Revision: https://reviews.llvm.org/D135220 --- clang/lib/Lex/ModuleMap.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'clang/lib/Lex/ModuleMap.cpp') diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 174d639..dbb81dc 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -609,7 +609,7 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) { UmbrellaModule = UmbrellaModule->Parent; if (UmbrellaModule->InferSubmodules) { - const FileEntry *UmbrellaModuleMap = + OptionalFileEntryRefDegradesToFileEntryPtr UmbrellaModuleMap = getModuleMapFileForUniquing(UmbrellaModule); // Infer submodules for each of the directories we found between @@ -1023,9 +1023,11 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, // If we're not allowed to infer a framework module, don't. if (!canInfer) return nullptr; - } else - ModuleMapFile = getModuleMapFileForUniquing(Parent); - + } else { + OptionalFileEntryRefDegradesToFileEntryPtr ModuleMapRef = + getModuleMapFileForUniquing(Parent); + ModuleMapFile = ModuleMapRef; + } // Look for an umbrella header. SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName()); @@ -1277,19 +1279,21 @@ void ModuleMap::excludeHeader(Module *Mod, Module::Header Header) { Mod->Headers[Module::HK_Excluded].push_back(std::move(Header)); } -const FileEntry * +Optional ModuleMap::getContainingModuleMapFile(const Module *Module) const { if (Module->DefinitionLoc.isInvalid()) - return nullptr; + return None; - return SourceMgr.getFileEntryForID( - SourceMgr.getFileID(Module->DefinitionLoc)); + return SourceMgr.getFileEntryRefForID( + SourceMgr.getFileID(Module->DefinitionLoc)); } -const FileEntry *ModuleMap::getModuleMapFileForUniquing(const Module *M) const { +Optional +ModuleMap::getModuleMapFileForUniquing(const Module *M) const { if (M->IsInferred) { assert(InferredModuleAllowedBy.count(M) && "missing inferred module map"); - return InferredModuleAllowedBy.find(M)->second; + // FIXME: Update InferredModuleAllowedBy to use FileEntryRef. + return InferredModuleAllowedBy.find(M)->second->getLastRef(); } return getContainingModuleMapFile(M); } -- cgit v1.1