diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -87,8 +87,7 @@ // 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 --- a/clang/lib/Tooling/AllTUsExecution.cpp +++ b/clang/lib/Tooling/AllTUsExecution.cpp @@ -124,7 +124,7 @@ // 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 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -154,7 +154,7 @@ : 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 --- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -58,6 +58,7 @@ #include #include #include +#include namespace llvm { @@ -175,6 +176,11 @@ S.Obj = nullptr; } + 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 --- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp +++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp @@ -42,6 +42,17 @@ 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) {}