[llvm] [ADT] Tighten member visibility in DenseMapBase (NFC) (PR #228651)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 20:52:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch cleans up access specifiers in DenseMapBase:

- It changes the protected section to private now that neither
  DenseMap nor SmallDenseMap accesses those members after #<!-- -->227063.
  With this change, DenseMap.h no longer has any protected members.

- It moves getMemorySize into the main public section and removes the
  trailing public section, leaving DenseMapBase with a single public
  section followed by a single private section.

Assisted-by: Antigravity


---
Full diff: https://github.com/llvm/llvm-project/pull/228651.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/DenseMap.h (+9-11) 


``````````diff
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 126a588fdcfaa..dc77237f75d93 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -1043,7 +1043,15 @@ class DenseMapBase : public DebugEpochBase {
     return *this;
   }
 
-protected:
+  /// Return the approximate size (in bytes) of the actual map.
+  /// This is just the raw memory used by DenseMap.
+  /// If entries are pointers to objects, the size of the referenced objects
+  /// are not included.
+  [[nodiscard]] size_t getMemorySize() const {
+    return llvm::densemap::detail::allocBytes<BucketT>(getNumBuckets());
+  }
+
+private:
   StorageT Storage;
 
   struct ExactBucketCount {};
@@ -1158,7 +1166,6 @@ class DenseMapBase : public DebugEpochBase {
     }
   }
 
-private:
   /// Erase the entry at \p TheBucket and close the resulting hole via Knuth
   /// TAOCP 6.4 Algorithm R.
   LLVM_ATTRIBUTE_NOINLINE void eraseFromFilledBucket(BucketT *TheBucket) {
@@ -1342,15 +1349,6 @@ class DenseMapBase : public DebugEpochBase {
       BucketNo = (BucketNo + 1) & Mask;
     }
   }
-
-public:
-  /// Return the approximate size (in bytes) of the actual map.
-  /// This is just the raw memory used by DenseMap.
-  /// If entries are pointers to objects, the size of the referenced objects
-  /// are not included.
-  [[nodiscard]] size_t getMemorySize() const {
-    return llvm::densemap::detail::allocBytes<BucketT>(getNumBuckets());
-  }
 };
 
 /// Equality comparison for DenseMap.

``````````

</details>


https://github.com/llvm/llvm-project/pull/228651


More information about the llvm-commits mailing list