VFS: Return new file systems as uniquely owned when possible, almost NFC

Uniformly return uniquely-owned filesystems from VFS creation APIs. The
one exception is `getRealFileSystem`, which has a single instance and
needs to be shared.

This is almost NFC, except that it fixes a memory leak in
`vfs::collectVFSFromYAML()`.

Depends on https://reviews.llvm.org/D92888

Differential Revision: https://reviews.llvm.org/D92890
This commit is contained in:
Duncan P. N. Exon Smith committed 2020-12-08 17:33:46 -08:00
1 parent 5207f19d10
commit a22eda548b
3 files changed
+8 -8

No files matched your search

+4 -4
View File
@@ -1639,7 +1639,7 @@ public:
}
};
RedirectingFileSystem *
std::unique_ptr<RedirectingFileSystem>
RedirectingFileSystem::create(std::unique_ptr<MemoryBuffer> Buffer,
SourceMgr::DiagHandlerTy DiagHandler,
StringRef YAMLFilePath, void *DiagContext,
@@ -1679,7 +1679,7 @@ RedirectingFileSystem::create(std::unique_ptr<MemoryBuffer> Buffer,
if (!P.parse(Root, FS.get()))
return nullptr;
return FS.release();
return FS;
}
ErrorOr<RedirectingFileSystem::Entry *>
@@ -1861,7 +1861,7 @@ RedirectingFileSystem::getRealPath(const Twine &Path,
: llvm::errc::invalid_argument;
}
IntrusiveRefCntPtr<FileSystem>
std::unique_ptr<FileSystem>
vfs::getVFSFromYAML(std::unique_ptr<MemoryBuffer> Buffer,
SourceMgr::DiagHandlerTy DiagHandler,
StringRef YAMLFilePath, void *DiagContext,
@@ -1902,7 +1902,7 @@ void vfs::collectVFSFromYAML(std::unique_ptr<MemoryBuffer> Buffer,
SmallVectorImpl<YAMLVFSEntry> &CollectedEntries,
void *DiagContext,
IntrusiveRefCntPtr<FileSystem> ExternalFS) {
RedirectingFileSystem *VFS = RedirectingFileSystem::create(
std::unique_ptr<RedirectingFileSystem> VFS = RedirectingFileSystem::create(
std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext,
std::move(ExternalFS));
ErrorOr<RedirectingFileSystem::Entry *> RootE = VFS->lookupPath("/");