Following up the earlier refactoring/cleanup work by fixing up how we manage the virtual files the ASTReader has to handle. Specifically, this occurs when the reader is reading AST files that were created in memory and not written to disk. For example, when a user creates a chained PCH using command line flags. These virtual files are stored in MemoryBuffers in ChainIncludeSource.cpp, and then read back in by the ASTReader. This patch moves the management of these buffers into the ModuleManager, so that it becomes the authority on where these buffers are located.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136697 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 0241b22..1b351a3 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -2764,9 +2764,8 @@
if (CurrentDir.empty()) CurrentDir = ".";
}
- if (!ASTBuffers.empty()) {
- F.Buffer.reset(ASTBuffers.back());
- ASTBuffers.pop_back();
+ if (llvm::MemoryBuffer *Buffer = ModuleMgr.lookupBuffer(FileName)) {
+ F.Buffer.reset(Buffer);
assert(F.Buffer && "Passed null buffer");
} else {
// Open the AST file.
@@ -5586,6 +5585,11 @@
return Modules[Entry];
}
+llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) {
+ const FileEntry *Entry = FileMgr.getFile(Name);
+ return InMemoryBuffers[Entry];
+}
+
/// \brief Creates a new module and adds it to the list of known modules
Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) {
Module *Prev = !size() ? 0 : &getLastModule();
@@ -5605,6 +5609,13 @@
return *Current;
}
+void ModuleManager::addInMemoryBuffer(StringRef FileName,
+ llvm::MemoryBuffer *Buffer) {
+
+ const FileEntry *Entry = FileMgr.getVirtualFile(FileName,
+ Buffer->getBufferSize(), 0);
+ InMemoryBuffers[Entry] = Buffer;
+}
/// \brief Exports the list of loaded modules with their corresponding names
void ModuleManager::exportLookup(SmallVector<ModuleOffset, 16> &Target) {
Target.reserve(size());