From: Duncan P. N. Exon Smith Date: Tue, 8 Dec 2020 22:54:55 +0000 (-0800) Subject: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC X-Git-Tag: llvmorg-13-init~3963 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5207f19d103dc3e0ec974fa64d2c031d84d497a8;p=platform%2Fupstream%2Fllvm.git ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`, and remove a couple of now-unnecessary `release()` calls. Differential Revision: https://reviews.llvm.org/D92888 --- diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp index cadda8e..ae9450f 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -87,8 +87,7 @@ RealThreadsafeFS::viewImpl() const { // Avoid using memory-mapped files. // FIXME: Try to use a similar approach in Sema instead of relying on // propagation of the 'isVolatile' flag through all layers. - return new VolatileFileSystem( - llvm::vfs::createPhysicalFileSystem().release()); + return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem()); } } // namespace clangd } // namespace clang diff --git a/clang/lib/Tooling/AllTUsExecution.cpp b/clang/lib/Tooling/AllTUsExecution.cpp index 7707c99..5565da9 100644 --- a/clang/lib/Tooling/AllTUsExecution.cpp +++ b/clang/lib/Tooling/AllTUsExecution.cpp @@ -124,7 +124,7 @@ llvm::Error AllTUsToolExecutor::execute( // Each thread gets an indepent copy of a VFS to allow different // concurrent working directories. IntrusiveRefCntPtr FS = - llvm::vfs::createPhysicalFileSystem().release(); + llvm::vfs::createPhysicalFileSystem(); ClangTool Tool(Compilations, {Path}, std::make_shared(), FS); Tool.appendArgumentsAdjuster(Action.second); diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index f10b602..63264b0 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -154,7 +154,7 @@ DependencyScanningWorker::DependencyScanningWorker( : Format(Service.getFormat()) { DiagOpts = new DiagnosticOptions(); PCHContainerOps = std::make_shared(); - RealFS = llvm::vfs::createPhysicalFileSystem().release(); + RealFS = llvm::vfs::createPhysicalFileSystem(); if (Service.canSkipExcludedPPRanges()) PPSkipMappings = std::make_unique(); diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h index 173fad3..dcd3525 100644 --- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -58,6 +58,7 @@ #include #include #include +#include namespace llvm { @@ -176,6 +177,11 @@ public: } template + IntrusiveRefCntPtr(std::unique_ptr S) : Obj(S.release()) { + retain(); + } + + template IntrusiveRefCntPtr(const IntrusiveRefCntPtr &S) : Obj(S.get()) { retain(); } diff --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp index 3d8041f..f692391 100644 --- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp +++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp @@ -42,6 +42,17 @@ TYPED_TEST(IntrusiveRefCntPtrTest, RefCountedBaseCopyDoesNotLeak) { EXPECT_EQ(0, NumInstances); } +TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) { + EXPECT_EQ(0, NumInstances); + { + auto S1 = std::make_unique(); + IntrusiveRefCntPtr R1 = std::move(S1); + EXPECT_EQ(1, NumInstances); + EXPECT_EQ(S1, nullptr); + } + EXPECT_EQ(0, NumInstances); +} + struct InterceptRefCounted : public RefCountedBase { InterceptRefCounted(bool *Released, bool *Retained) : Released(Released), Retained(Retained) {}