From b84a97ca6c2d047b4da98a7be933b1c878c61947 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 20 Aug 2025 22:12:26 -0700 Subject: [PATCH 1/2] [ADT] Use SmallPtrSet or SmallSet flexibly (NFC) I'm trying to remove the redirection in SmallSet.h: template class SmallSet : public SmallPtrSet {}; to make it clear that we are using SmallPtrSet. There are only handful places that rely on this redirection. Now, this unit test is unique in that supply multiple key types via TYPED_TESTS. This patch adds UniversalSmallSet to work around the problem. --- llvm/unittests/ADT/DenseMapTest.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index fdecfb7bb5b0b..2f78e32ca81a4 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -387,9 +387,13 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) { EXPECT_TRUE(cit == cit2); } +template +using UniversalSmallSet = + std::conditional_t, SmallPtrSet, SmallSet>; + TYPED_TEST(DenseMapTest, KeysValuesIterator) { - SmallSet Keys; - SmallSet Values; + UniversalSmallSet Keys; + UniversalSmallSet Values; for (int I = 0; I < 10; ++I) { auto K = this->getKey(I); auto V = this->getValue(I); @@ -398,8 +402,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) { this->Map[K] = V; } - SmallSet ActualKeys; - SmallSet ActualValues; + UniversalSmallSet ActualKeys; + UniversalSmallSet ActualValues; for (auto K : this->Map.keys()) ActualKeys.insert(K); for (auto V : this->Map.values()) @@ -410,8 +414,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) { } TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) { - SmallSet Keys; - SmallSet Values; + UniversalSmallSet Keys; + UniversalSmallSet Values; for (int I = 0; I < 10; ++I) { auto K = this->getKey(I); auto V = this->getValue(I); @@ -421,8 +425,8 @@ TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) { } const TypeParam &ConstMap = this->Map; - SmallSet ActualKeys; - SmallSet ActualValues; + UniversalSmallSet ActualKeys; + UniversalSmallSet ActualValues; for (auto K : ConstMap.keys()) ActualKeys.insert(K); for (auto V : ConstMap.values()) From 3d764e7b1c84272489796a9ac513a87f8a846104 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 21 Aug 2025 09:02:29 -0700 Subject: [PATCH 2/2] Add a comment. --- llvm/unittests/ADT/DenseMapTest.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index 2f78e32ca81a4..785ab16271d93 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -387,6 +387,9 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) { EXPECT_TRUE(cit == cit2); } +// TYPED_TEST below cycles through different types. We define UniversalSmallSet +// here so that we'll use SmallSet or SmallPtrSet depending on whether the +// element type is a pointer. template using UniversalSmallSet = std::conditional_t, SmallPtrSet, SmallSet>;