[llvm] 9ff6c35 - [DenseMap] clear: don't access TombstoneKey if is_trivially_destructible

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 09:18:25 PDT 2024


Author: Fangrui Song
Date: 2024-07-26T09:18:20-07:00
New Revision: 9ff6c35a7e50c906537f085c0d2488ea4836dcc5

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

LOG: [DenseMap] clear: don't access TombstoneKey if is_trivially_destructible

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 67d474d8e4aa6..f71cd5b4771b7 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -118,12 +118,13 @@ class DenseMapBase : public DebugEpochBase {
       return;
     }
 
-    const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
+    const KeyT EmptyKey = getEmptyKey();
     if (std::is_trivially_destructible<ValueT>::value) {
       // Use a simpler loop when values don't need destruction.
       for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P)
         P->getFirst() = EmptyKey;
     } else {
+      const KeyT TombstoneKey = getTombstoneKey();
       unsigned NumEntries = getNumEntries();
       for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
         if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {


        


More information about the llvm-commits mailing list