From a22eda548b8e1f9362018dec194af0ca91b35da0 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 8 Dec 2020 14:58:46 -0800 Subject: 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 --- llvm/lib/Support/VirtualFileSystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Support/VirtualFileSystem.cpp') diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 697383d55d88..de2499295daa 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -1639,7 +1639,7 @@ public: } }; -RedirectingFileSystem * +std::unique_ptr RedirectingFileSystem::create(std::unique_ptr Buffer, SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext, @@ -1679,7 +1679,7 @@ RedirectingFileSystem::create(std::unique_ptr Buffer, if (!P.parse(Root, FS.get())) return nullptr; - return FS.release(); + return FS; } ErrorOr @@ -1861,7 +1861,7 @@ RedirectingFileSystem::getRealPath(const Twine &Path, : llvm::errc::invalid_argument; } -IntrusiveRefCntPtr +std::unique_ptr vfs::getVFSFromYAML(std::unique_ptr Buffer, SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext, @@ -1902,7 +1902,7 @@ void vfs::collectVFSFromYAML(std::unique_ptr Buffer, SmallVectorImpl &CollectedEntries, void *DiagContext, IntrusiveRefCntPtr ExternalFS) { - RedirectingFileSystem *VFS = RedirectingFileSystem::create( + std::unique_ptr VFS = RedirectingFileSystem::create( std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext, std::move(ExternalFS)); ErrorOr RootE = VFS->lookupPath("/"); -- cgit v1.2.3