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.cpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index de4cd3d..d1ded6c 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -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;
}
@@ -150,7 +150,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
};
// Check whether we already loaded this module, before
- if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
+ if (ModuleFile *ModuleEntry = Modules.lookup(*Entry)) {
if (implicitModuleNamesMatch(Type, ModuleEntry, *Entry)) {
// Check the stored signature.
if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
@@ -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;