https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/120555
>From 4f114f21b10d6a2c80d9b2b24a34f18f55ca6611 Mon Sep 17 00:00:00 2001 From: Akshat Oke <akshat....@amd.com> Date: Thu, 19 Dec 2024 06:57:46 +0000 Subject: [PATCH 1/2] [Support] Recycler: Implement move constructor --- llvm/include/llvm/Support/Recycler.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llvm/include/llvm/Support/Recycler.h b/llvm/include/llvm/Support/Recycler.h index 8cc882ea5fa058..f105d80563ba93 100644 --- a/llvm/include/llvm/Support/Recycler.h +++ b/llvm/include/llvm/Support/Recycler.h @@ -60,6 +60,10 @@ class Recycler { // clear() before deleting the Recycler. assert(!FreeList && "Non-empty recycler deleted!"); } + Recycler(const Recycler &) = delete; + Recycler(Recycler &&Other) + : FreeList(std::exchange(Other.FreeList, nullptr)) {} + Recycler() = default; /// clear - Release all the tracked allocations to the allocator. The /// recycler must be free of any tracked allocations before being >From af2bec8e77637013a0a8e01b42e997d5311df7d9 Mon Sep 17 00:00:00 2001 From: Akshat Oke <akshat....@amd.com> Date: Wed, 1 Jan 2025 06:35:09 +0000 Subject: [PATCH 2/2] Add test --- llvm/unittests/Support/RecyclerTest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/llvm/unittests/Support/RecyclerTest.cpp b/llvm/unittests/Support/RecyclerTest.cpp index 8cd763c0b83f8a..0ef9c5aa0ec82b 100644 --- a/llvm/unittests/Support/RecyclerTest.cpp +++ b/llvm/unittests/Support/RecyclerTest.cpp @@ -18,6 +18,10 @@ struct Object1 { char Data[1]; }; +struct Object8 { + char Data[8]; +}; + class DecoratedMallocAllocator : public MallocAllocator { public: int DeallocCount = 0; @@ -43,4 +47,19 @@ TEST(RecyclerTest, RecycleAllocation) { EXPECT_EQ(Allocator.DeallocCount, 2); } +TEST(RecyclerTest, MoveConstructor) { + DecoratedMallocAllocator Allocator; + Recycler<Object8> R; + Object8 *A1 = R.Allocate(Allocator); + Object8 *A2 = R.Allocate(Allocator); + R.Deallocate(Allocator, A1); + R.Deallocate(Allocator, A2); + Recycler<Object8> R2(std::move(R)); + Object8 *A3 = R2.Allocate(Allocator); + R2.Deallocate(Allocator, A3); + R.clear(Allocator); // Should not deallocate anything as it was moved from. + EXPECT_EQ(Allocator.DeallocCount, 0); + R2.clear(Allocator); + EXPECT_EQ(Allocator.DeallocCount, 2); +} } // end anonymous namespace _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits