https://github.com/Xazax-hun updated https://github.com/llvm/llvm-project/pull/244626
From 06f4b8deacfb0c2aff7e6afcb1e9e72ca5fb996b Mon Sep 17 00:00:00 2001 From: Gabor Horvath <[email protected]> Date: Fri, 20 Nov 2026 15:38:41 +0000 Subject: [PATCH 1/3] [ADT] Thread the ImutAVLFactory free list through the nodes Freed nodes are kept in a vector that grows with the number of freed nodes. Link them through their now unused left pointers instead, removing the vector's allocation and growth. Based on #196534 by Christoph Cullmann. Co-authored-by: Christoph Cullmann <[email protected]> Assisted-by: Claude Opus 5.5 --- llvm/include/llvm/ADT/ImmutableSet.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/ADT/ImmutableSet.h b/llvm/include/llvm/ADT/ImmutableSet.h index ad80150fc2e52..9ff0fc835b32c 100644 --- a/llvm/include/llvm/ADT/ImmutableSet.h +++ b/llvm/include/llvm/ADT/ImmutableSet.h @@ -374,7 +374,10 @@ class ImutAVLTree // We need to clear the mutability bit in case we are // destroying the node as part of a sweep in ImutAVLFactory::recoverNodes(). IsMutable = false; - factory->freeNodes.push_back(this); + // The children were released above, so reuse the left pointer to link + // this node into the factory's free list. + left = factory->freeNodes; + factory->freeNodes = this; } }; @@ -405,7 +408,8 @@ class ImutAVLFactory uintptr_t Allocator; std::vector<TreeTy*> createdNodes; - std::vector<TreeTy*> freeNodes; + // Destroyed nodes, linked through their left pointers. + TreeTy *freeNodes = nullptr; bool ownsAllocator() const { return (Allocator & 0x1) == 0; @@ -513,9 +517,9 @@ class ImutAVLFactory TreeTy* createNode(TreeTy* L, value_type_ref V, TreeTy* R) { BumpPtrAllocator& A = getAllocator(); TreeTy* T; - if (!freeNodes.empty()) { - T = freeNodes.back(); - freeNodes.pop_back(); + if (freeNodes) { + T = freeNodes; + freeNodes = T->getLeft(); assert(T != L); assert(T != R); } else { From 35d7da90296711ee01bab95aa641622d7ddb9628 Mon Sep 17 00:00:00 2001 From: Gabor Horvath <[email protected]> Date: Fri, 20 Nov 2026 16:31:11 +0000 Subject: [PATCH 2/3] Assert that reused nodes were destroyed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Balázs Benics <[email protected]> --- llvm/include/llvm/ADT/ImmutableSet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/ADT/ImmutableSet.h b/llvm/include/llvm/ADT/ImmutableSet.h index 9ff0fc835b32c..d57034b790174 100644 --- a/llvm/include/llvm/ADT/ImmutableSet.h +++ b/llvm/include/llvm/ADT/ImmutableSet.h @@ -520,6 +520,7 @@ class ImutAVLFactory if (freeNodes) { T = freeNodes; freeNodes = T->getLeft(); + assert(!T->isMutable() && "free-list node must have been destroyed"); assert(T != L); assert(T != R); } else { From 4fd494e2ae841d55b32bde030a66b43acea0058a Mon Sep 17 00:00:00 2001 From: Gabor Horvath <[email protected]> Date: Sat, 21 Nov 2026 09:50:15 +0000 Subject: [PATCH 3/3] [analyzer][NFC] Keep the stores alive in StoreTest The test kept raw Store pointers taken from temporary StoreRefs, so the bindings were freed right away. Reading them back retained and released the freed root again, which destroyed it a second time. The intrusive free list turns this into a refCount assertion. Keep the StoreRefs alive instead. Assisted-by: Claude Opus 5.5 --- clang/unittests/StaticAnalyzer/StoreTest.cpp | 49 +++++++++++--------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/clang/unittests/StaticAnalyzer/StoreTest.cpp b/clang/unittests/StaticAnalyzer/StoreTest.cpp index d4c743c6d5a52..5b400522d0dff 100644 --- a/clang/unittests/StaticAnalyzer/StoreTest.cpp +++ b/clang/unittests/StaticAnalyzer/StoreTest.cpp @@ -63,39 +63,46 @@ class VariableBindConsumer : public StoreTestConsumer { Loc LX1 = loc::MemRegionVal(MRManager.getVarRegion(VDX1, SF)); Loc LY1 = loc::MemRegionVal(MRManager.getVarRegion(VDY1, SF)); - Store StInit = SManager.getInitialStore(SF).getStore(); + // Keep the StoreRefs alive, a raw Store does not keep its bindings alive. + StoreRef StInit = SManager.getInitialStore(SF); SVal Zero = Builder.makeZeroVal(ASTCtxt.IntTy); SVal One = Builder.makeIntVal(1, ASTCtxt.IntTy); SVal NarrowZero = Builder.makeZeroVal(ASTCtxt.CharTy); // Bind(Zero) - Store StX0 = SManager.Bind(StInit, LX0, Zero).ResultingStore.getStore(); - EXPECT_EQ(Zero, SManager.getBinding(StX0, LX0, ASTCtxt.IntTy)); + StoreRef StX0 = SManager.Bind(StInit.getStore(), LX0, Zero).ResultingStore; + EXPECT_EQ(Zero, SManager.getBinding(StX0.getStore(), LX0, ASTCtxt.IntTy)); // BindDefaultInitial(Zero) - Store StY0 = SManager.BindDefaultInitial(StInit, LY0.getAsRegion(), Zero) - .ResultingStore.getStore(); - EXPECT_EQ(Zero, SManager.getBinding(StY0, LY0, ASTCtxt.IntTy)); - EXPECT_EQ(Zero, *SManager.getDefaultBinding(StY0, LY0.getAsRegion())); + StoreRef StY0 = + SManager.BindDefaultInitial(StInit.getStore(), LY0.getAsRegion(), Zero) + .ResultingStore; + EXPECT_EQ(Zero, SManager.getBinding(StY0.getStore(), LY0, ASTCtxt.IntTy)); + EXPECT_EQ(Zero, + *SManager.getDefaultBinding(StY0.getStore(), LY0.getAsRegion())); // BindDefaultZero() - Store StZ0 = SManager.BindDefaultZero(StInit, LZ0.getAsRegion()) - .ResultingStore.getStore(); + StoreRef StZ0 = + SManager.BindDefaultZero(StInit.getStore(), LZ0.getAsRegion()) + .ResultingStore; // BindDefaultZero wipes the region with '0 S8b', not with out Zero. // Direct load, however, does give us back the object of the type // that we specify for loading. - EXPECT_EQ(Zero, SManager.getBinding(StZ0, LZ0, ASTCtxt.IntTy)); - EXPECT_EQ(NarrowZero, *SManager.getDefaultBinding(StZ0, LZ0.getAsRegion())); + EXPECT_EQ(Zero, SManager.getBinding(StZ0.getStore(), LZ0, ASTCtxt.IntTy)); + EXPECT_EQ(NarrowZero, + *SManager.getDefaultBinding(StZ0.getStore(), LZ0.getAsRegion())); // Bind(One) - Store StX1 = SManager.Bind(StInit, LX1, One).ResultingStore.getStore(); - EXPECT_EQ(One, SManager.getBinding(StX1, LX1, ASTCtxt.IntTy)); + StoreRef StX1 = SManager.Bind(StInit.getStore(), LX1, One).ResultingStore; + EXPECT_EQ(One, SManager.getBinding(StX1.getStore(), LX1, ASTCtxt.IntTy)); // BindDefaultInitial(One) - Store StY1 = SManager.BindDefaultInitial(StInit, LY1.getAsRegion(), One) - .ResultingStore.getStore(); - EXPECT_EQ(One, SManager.getBinding(StY1, LY1, ASTCtxt.IntTy)); - EXPECT_EQ(One, *SManager.getDefaultBinding(StY1, LY1.getAsRegion())); + StoreRef StY1 = + SManager.BindDefaultInitial(StInit.getStore(), LY1.getAsRegion(), One) + .ResultingStore; + EXPECT_EQ(One, SManager.getBinding(StY1.getStore(), LY1, ASTCtxt.IntTy)); + EXPECT_EQ(One, + *SManager.getDefaultBinding(StY1.getStore(), LY1.getAsRegion())); } public: @@ -132,14 +139,14 @@ class LiteralCompoundConsumer : public StoreTestConsumer { loc::MemRegionVal ZeroElement( MRManager.getElementRegion(ASTCtxt.IntTy, Zero, CLRegion, ASTCtxt)); - Store StInit = SManager.getInitialStore(SF).getStore(); + StoreRef StInit = SManager.getInitialStore(SF); // Let's bind constant 1 to 'test[0]' SVal One = Builder.makeIntVal(1, Int); - Store StX = - SManager.Bind(StInit, ZeroElement, One).ResultingStore.getStore(); + StoreRef StX = + SManager.Bind(StInit.getStore(), ZeroElement, One).ResultingStore; // And make sure that we can read this binding back as it was - EXPECT_EQ(One, SManager.getBinding(StX, ZeroElement, Int)); + EXPECT_EQ(One, SManager.getBinding(StX.getStore(), ZeroElement, Int)); } public: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
