aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/ModuleManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r--clang/lib/Serialization/ModuleManager.cpp64
1 files changed, 27 insertions, 37 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index 5b099b740e1d..51b642941296 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -52,8 +52,8 @@ ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const {
ModuleFile *ModuleManager::lookupByModuleName(StringRef Name) const {
if (const Module *Mod = HeaderSearchInfo.getModuleMap().findModule(Name))
- if (const FileEntry *File = Mod->getASTFile())
- return lookup(File);
+ if (OptionalFileEntryRef File = Mod->getASTFile())
+ return lookup(*File);
return nullptr;
}
@@ -108,7 +108,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
// Look for the file entry. This only fails if the expected size or
// modification time differ.
- OptionalFileEntryRefDegradesToFileEntryPtr Entry;
+ OptionalFileEntryRef Entry;
if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
// If we're not expecting to pull this file out of the module cache, it
// might have a different mtime due to being moved across filesystems in
@@ -123,7 +123,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
return OutOfDate;
}
- if (!Entry && FileName != "-") {
+ if (!Entry) {
ErrorStr = "module file not found";
return Missing;
}
@@ -143,15 +143,15 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
// being consistent across operating systems and across subsequent accesses
// to the Modules map.
auto implicitModuleNamesMatch = [](ModuleKind Kind, const ModuleFile *MF,
- const FileEntry *Entry) -> bool {
+ FileEntryRef Entry) -> bool {
if (Kind != MK_ImplicitModule)
return true;
- return Entry->getName() == MF->FileName;
+ return Entry.getName() == MF->FileName;
};
// Check whether we already loaded this module, before
- if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
- if (implicitModuleNamesMatch(Type, ModuleEntry, Entry)) {
+ if (ModuleFile *ModuleEntry = Modules.lookup(*Entry)) {
+ if (implicitModuleNamesMatch(Type, ModuleEntry, *Entry)) {
// Check the stored signature.
if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
return OutOfDate;
@@ -163,10 +163,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
}
// Allocate a new module.
- auto NewModule = std::make_unique<ModuleFile>(Type, Generation);
+ auto NewModule = std::make_unique<ModuleFile>(Type, *Entry, Generation);
NewModule->Index = Chain.size();
NewModule->FileName = FileName.str();
- NewModule->File = Entry;
NewModule->ImportLoc = ImportLoc;
NewModule->InputFilesValidationTimestamp = 0;
@@ -198,21 +197,15 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
Entry->closeFile();
return OutOfDate;
} else {
- // Open the AST file.
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code()));
- if (FileName == "-") {
- Buf = llvm::MemoryBuffer::getSTDIN();
- } else {
- // Get a buffer of the file and close the file descriptor when done.
- // The file is volatile because in a parallel build we expect multiple
- // compiler processes to use the same module file rebuilding it if needed.
- //
- // RequiresNullTerminator is false because module files don't need it, and
- // this allows the file to still be mmapped.
- Buf = FileMgr.getBufferForFile(NewModule->File,
- /*IsVolatile=*/true,
- /*RequiresNullTerminator=*/false);
- }
+ // Get a buffer of the file and close the file descriptor when done.
+ // The file is volatile because in a parallel build we expect multiple
+ // compiler processes to use the same module file rebuilding it if needed.
+ //
+ // RequiresNullTerminator is false because module files don't need it, and
+ // this allows the file to still be mmapped.
+ auto Buf = FileMgr.getBufferForFile(NewModule->File,
+ /*IsVolatile=*/true,
+ /*RequiresNullTerminator=*/false);
if (!Buf) {
ErrorStr = Buf.getError().message();
@@ -232,7 +225,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
return OutOfDate;
// We're keeping this module. Store it everywhere.
- Module = Modules[Entry] = NewModule.get();
+ Module = Modules[*Entry] = NewModule.get();
updateModuleImports(*NewModule, ImportedBy, ImportLoc);
@@ -441,22 +434,19 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
time_t ExpectedModTime,
OptionalFileEntryRef &File) {
- File = std::nullopt;
- if (FileName == "-")
+ if (FileName == "-") {
+ File = expectedToOptional(FileMgr.getSTDIN());
return false;
+ }
// Open the file immediately to ensure there is no race between stat'ing and
// opening the file.
- OptionalFileEntryRef FileOrErr =
- expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
- /*CacheFailure=*/false));
- if (!FileOrErr)
- return false;
-
- File = *FileOrErr;
+ File = FileMgr.getOptionalFileRef(FileName, /*OpenFile=*/true,
+ /*CacheFailure=*/false);
- if ((ExpectedSize && ExpectedSize != File->getSize()) ||
- (ExpectedModTime && ExpectedModTime != File->getModificationTime()))
+ if (File &&
+ ((ExpectedSize && ExpectedSize != File->getSize()) ||
+ (ExpectedModTime && ExpectedModTime != File->getModificationTime())))
// Do not destroy File, as it may be referenced. If we need to rebuild it,
// it will be destroyed by removeModules.
return true;