Skip to content

Commit 02004c9

Browse files
Adam Baloghtstellar
authored andcommitted
[ADT] Fix for ImmutableMapRef
The `Root` member of `ImmutableMapRef` was changed recently from a plain pointer to `IntrusiveRefCntPtr`. However, the `Profile` member function was not adjusted. This results in comilation error whenever the `Profile` method is used on an `ImmutableMapRef`. This patch fixes this issue and also adds unit tests for `ImmutableMapRef`. Differential Revision: https://reviews.llvm.org/D89486 (cherry picked from commit 184eb4f)
1 parent 85ce339 commit 02004c9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/include/llvm/ADT/ImmutableMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class ImmutableMapRef {
355355
unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
356356

357357
static inline void Profile(FoldingSetNodeID &ID, const ImmutableMapRef &M) {
358-
ID.AddPointer(M.Root);
358+
ID.AddPointer(M.Root.get());
359359
}
360360

361361
inline void Profile(FoldingSetNodeID &ID) const { return Profile(ID, *this); }

llvm/unittests/ADT/ImmutableMapTest.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,45 @@ TEST(ImmutableMapTest, MultiElemIntMapTest) {
4646
EXPECT_EQ(3U, S2.getHeight());
4747
}
4848

49+
TEST(ImmutableMapTest, EmptyIntMapRefTest) {
50+
using int_int_map = ImmutableMapRef<int, int>;
51+
ImmutableMapRef<int, int>::FactoryTy f;
52+
53+
EXPECT_TRUE(int_int_map::getEmptyMap(&f) == int_int_map::getEmptyMap(&f));
54+
EXPECT_FALSE(int_int_map::getEmptyMap(&f) != int_int_map::getEmptyMap(&f));
55+
EXPECT_TRUE(int_int_map::getEmptyMap(&f).isEmpty());
56+
57+
int_int_map S = int_int_map::getEmptyMap(&f);
58+
EXPECT_EQ(0u, S.getHeight());
59+
EXPECT_TRUE(S.begin() == S.end());
60+
EXPECT_FALSE(S.begin() != S.end());
61+
}
62+
63+
TEST(ImmutableMapTest, MultiElemIntMapRefTest) {
64+
ImmutableMapRef<int, int>::FactoryTy f;
65+
66+
ImmutableMapRef<int, int> S = ImmutableMapRef<int, int>::getEmptyMap(&f);
67+
68+
ImmutableMapRef<int, int> S2 = S.add(3, 10).add(4, 11).add(5, 12);
69+
70+
EXPECT_TRUE(S.isEmpty());
71+
EXPECT_FALSE(S2.isEmpty());
72+
73+
EXPECT_EQ(nullptr, S.lookup(3));
74+
EXPECT_EQ(nullptr, S.lookup(9));
75+
76+
EXPECT_EQ(10, *S2.lookup(3));
77+
EXPECT_EQ(11, *S2.lookup(4));
78+
EXPECT_EQ(12, *S2.lookup(5));
79+
80+
EXPECT_EQ(5, S2.getMaxElement()->first);
81+
EXPECT_EQ(3U, S2.getHeight());
82+
}
83+
84+
TEST(ImmutableMapTest, MapOfMapRefsTest) {
85+
ImmutableMap<int, ImmutableMapRef<int, int>>::Factory f;
86+
87+
EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap());
88+
}
89+
4990
}

0 commit comments

Comments
 (0)