[clang-tools-extra] 5207f19 - ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 8 17:33:35 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-12-08T17:33:19-08:00
New Revision: 5207f19d103dc3e0ec974fa64d2c031d84d497a8
URL: https://github.com/llvm/llvm-project/commit/5207f19d103dc3e0ec974fa64d2c031d84d497a8
DIFF: https://github.com/llvm/llvm-project/commit/5207f19d103dc3e0ec974fa64d2c031d84d497a8.diff
LOG: 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
Added:
Modified:
clang-tools-extra/clangd/support/ThreadsafeFS.cpp
clang/lib/Tooling/AllTUsExecution.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index cadda8efa095..ae9450f17411 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 7707c99c21d0..5565da9b548a 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
diff erent
// concurrent working directories.
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
- llvm::vfs::createPhysicalFileSystem().release();
+ llvm::vfs::createPhysicalFileSystem();
ClangTool Tool(Compilations, {Path},
std::make_shared<PCHContainerOperations>(), FS);
Tool.appendArgumentsAdjuster(Action.second);
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index f10b60252715..63264b0dda2d 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<PCHContainerOperations>();
- RealFS = llvm::vfs::createPhysicalFileSystem().release();
+ RealFS = llvm::vfs::createPhysicalFileSystem();
if (Service.canSkipExcludedPPRanges())
PPSkipMappings =
std::make_unique<ExcludedPreprocessorDirectiveSkipMapping>();
diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
index 173fad3aeafa..dcd35253c5f2 100644
--- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -58,6 +58,7 @@
#include <atomic>
#include <cassert>
#include <cstddef>
+#include <memory>
namespace llvm {
@@ -175,6 +176,11 @@ template <typename T> class IntrusiveRefCntPtr {
S.Obj = nullptr;
}
+ template <class X>
+ IntrusiveRefCntPtr(std::unique_ptr<X> S) : Obj(S.release()) {
+ retain();
+ }
+
template <class X>
IntrusiveRefCntPtr(const IntrusiveRefCntPtr<X> &S) : Obj(S.get()) {
retain();
diff --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp
index 3d8041fcbf48..f69239162e3a 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<TypeParam>();
+ IntrusiveRefCntPtr<TypeParam> R1 = std::move(S1);
+ EXPECT_EQ(1, NumInstances);
+ EXPECT_EQ(S1, nullptr);
+ }
+ EXPECT_EQ(0, NumInstances);
+}
+
struct InterceptRefCounted : public RefCountedBase<InterceptRefCounted> {
InterceptRefCounted(bool *Released, bool *Retained)
: Released(Released), Retained(Retained) {}
More information about the cfe-commits
mailing list