[llvm] ea3a01e - [ADT] Remove zombie-instance handling from SmallDenseMapStorage (NFC) (#228925)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 15:16:44 PDT 2026


Author: Kazu Hirata
Date: 2026-10-04T22:16:36Z
New Revision: ea3a01e0b663ccf258f3ce4af117e16679f67d52

URL: https://github.com/llvm/llvm-project/commit/ea3a01e0b663ccf258f3ce4af117e16679f67d52
DIFF: https://github.com/llvm/llvm-project/commit/ea3a01e0b663ccf258f3ce4af117e16679f67d52.diff

LOG: [ADT] Remove zombie-instance handling from SmallDenseMapStorage (NFC) (#228925)

This patch removes the redundant storage.Large.NumBuckets == 0 check
and the two dead stores to the field from SmallDenseMapStorage, and
simplifies DenseMapStorage::maybeMoveFast to use direct assignment
instead of swap.

SmallDenseMapStorage used to have a zombie state:

    !Small && storage.Large.NumBuckets == 0

in grow() so that ~DenseMapBase(), which calls deallocateBuckets(),
could safely destruct the moved-from temporary DenseMapBase instance.
Likewise, DenseMapStorage::maybeMoveFast used swap(Other) so that the
temporary instance would not deallocate the moved-from buffer upon
destruction.

With #228802, grow() directly uses StorageT for the temporary storage,
which has a trivial destructor, so neither workaround is needed.

Assisted-by: Antigravity

Added: 
    

Modified: 
    llvm/include/llvm/ADT/DenseMap.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 92eae370e0219..6d25ce578a620 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -286,7 +286,7 @@ template <typename BucketT> class DenseMapStorage {
   }
 
   bool maybeMoveFast(DenseMapStorage &&Other) {
-    swap(Other);
+    *this = Other;
     return true;
   }
 };
@@ -462,15 +462,12 @@ class SmallDenseMapStorage {
   }
 
   void deallocateBuckets() {
-    // Fast path in case storage.Large.NumBuckets == 0, just like destroyAll.
-    // This path is used to destruct zombie instances after moves.
-    if (Small || storage.Large.NumBuckets == 0)
+    if (Small)
       return;
 
     deallocate_buffer(storage.Large.Buckets,
                       allocBytes<BucketT>(storage.Large.NumBuckets),
                       allocAlign<BucketT>());
-    storage.Large.NumBuckets = 0;
   }
 
   bool allocateBuckets(unsigned Num) {
@@ -513,7 +510,6 @@ class SmallDenseMapStorage {
     Small = false;
     NumEntries = Other.NumEntries;
     storage.Large = Other.storage.Large;
-    Other.storage.Large.NumBuckets = 0;
     return true;
   }
 };


        


More information about the llvm-commits mailing list