diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-17 00:39:38 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-17 00:39:38 +0000 |
| commit | 9b92875bbdde7c1e01b9e739da66aa876022eadd (patch) | |
| tree | 4d60c78a58634b47ae01f367ac070d20c63017c5 /llvm/unittests/ADT/PointerUnionTest.cpp | |
| parent | f0a0e8bb3652eb457f8656a88b50e04ce3a32f21 (diff) | |
| download | bcm5719-llvm-9b92875bbdde7c1e01b9e739da66aa876022eadd.tar.gz bcm5719-llvm-9b92875bbdde7c1e01b9e739da66aa876022eadd.zip | |
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
Diffstat (limited to 'llvm/unittests/ADT/PointerUnionTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/PointerUnionTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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 *>(), (int *)nullptr); } +template<int I> struct alignas(8) Aligned {}; + +typedef PointerUnion<Aligned<0> *, 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<Aligned<0>*>()); + EXPECT_FALSE(a.is<Aligned<1>*>()); + EXPECT_FALSE(a.is<Aligned<2>*>()); + EXPECT_FALSE(a.is<Aligned<3>*>()); + EXPECT_FALSE(a.is<Aligned<4>*>()); + EXPECT_FALSE(a.is<Aligned<5>*>()); + EXPECT_FALSE(a.is<Aligned<6>*>()); + EXPECT_FALSE(a.is<Aligned<7>*>()); + EXPECT_EQ(a.dyn_cast<Aligned<0>*>() == &a0); + EXPECT_EQ(*a.getAddrOfPtr1() == &a0); + + a = &a7; + EXPECT_FALSE(a.is<Aligned<0>*>()); + EXPECT_FALSE(a.is<Aligned<1>*>()); + EXPECT_FALSE(a.is<Aligned<2>*>()); + EXPECT_FALSE(a.is<Aligned<3>*>()); + EXPECT_FALSE(a.is<Aligned<4>*>()); + EXPECT_FALSE(a.is<Aligned<5>*>()); + EXPECT_FALSE(a.is<Aligned<6>*>()); + EXPECT_TRUE(a.is<Aligned<7>*>()); + EXPECT_EQ(a.dyn_cast<Aligned<7>*>() == &a7); + + EXPECT_TRUE(a == PU8(&a7)); + EXPECT_TRUE(a != PU8(&a0)); +} + } // end anonymous namespace |

