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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 20:51:36 PDT 2026


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

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


>From a3f27e721956d805f7ff752c45ef4b46a57910df Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 28 Sep 2026 13:11:30 -0700
Subject: [PATCH] [ADT] Tighten member visibility in DenseMapBase (NFC)

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
---
 llvm/include/llvm/ADT/DenseMap.h | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

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.



More information about the llvm-commits mailing list