From 9b92875bbdde7c1e01b9e739da66aa876022eadd Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 17 May 2019 00:39:38 +0000 Subject: Convert PointerUnion to a variadic template. Summary: Rather than duplicating code between PointerUnion, PointerUnion3, and PointerUnion4 (and missing things from the latter cases, such as some of the DenseMap support and operator==), convert PointerUnion to a variadic template that can be used as a union of any number of pointers. (This doesn't support PointerUnion<> right now. Adding a special case for that would be possible, and perhaps even useful in some situations, but it doesn't seem worthwhile until we have a concrete use case.) Reviewers: dblaikie Subscribers: dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62027 llvm-svn: 360962 --- llvm/unittests/ADT/PointerUnionTest.cpp | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'llvm/unittests/ADT/PointerUnionTest.cpp') diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp index 657767a240e..cf961d711d4 100644 --- a/llvm/unittests/ADT/PointerUnionTest.cpp +++ b/llvm/unittests/ADT/PointerUnionTest.cpp @@ -68,4 +68,41 @@ TEST_F(PointerUnionTest, Get) { EXPECT_EQ(n.get(), (int *)nullptr); } +template struct alignas(8) Aligned {}; + +typedef PointerUnion *, Aligned<1> *, Aligned<2> *, Aligned<3> *, + Aligned<4> *, Aligned<5> *, Aligned<6> *, Aligned<7> *> + PU8; + +TEST_F(PointerUnionTest, ManyElements) { + Aligned<0> a0; + Aligned<7> a7; + + PU8 a = &a0; + EXPECT_TRUE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_EQ(a.dyn_cast*>() == &a0); + EXPECT_EQ(*a.getAddrOfPtr1() == &a0); + + a = &a7; + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_FALSE(a.is*>()); + EXPECT_TRUE(a.is*>()); + EXPECT_EQ(a.dyn_cast*>() == &a7); + + EXPECT_TRUE(a == PU8(&a7)); + EXPECT_TRUE(a != PU8(&a0)); +} + } // end anonymous namespace -- cgit v1.2.3