Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / unittests / AST / UnresolvedSetTest.cpp
blob0d01eebe07e2f5076adabafaef1209c8b79fd09a
1 #include "clang/AST/UnresolvedSet.h"
2 #include "clang/AST/Decl.h"
3 #include "gtest/gtest.h"
5 using namespace clang;
7 class UnresolvedSetTest : public ::testing::Test {
8 protected:
9 // For this test we don't care about the contents of the NamedDecl,
10 // so just use a dummy struct of appropriate size and alignment.
11 struct alignas(NamedDecl) DummyDecl {
12 char contents[sizeof(NamedDecl)];
14 DummyDecl d0, d1, d2, d3;
15 NamedDecl *n0, *n1, *n2, *n3;
16 UnresolvedSet<2> set;
18 void SetUp() override {
19 n0 = reinterpret_cast<NamedDecl*>(&d0);
20 n1 = reinterpret_cast<NamedDecl*>(&d1);
21 n2 = reinterpret_cast<NamedDecl*>(&d2);
22 n3 = reinterpret_cast<NamedDecl*>(&d3);
23 set.addDecl(n0);
24 set.addDecl(n1);
25 set.addDecl(n2);
26 set.addDecl(n3);
30 TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
32 TEST_F(UnresolvedSetTest, ArrayOperator) {
33 EXPECT_EQ(set[0].getDecl(), n0);
34 EXPECT_EQ(set[1].getDecl(), n1);
35 EXPECT_EQ(set[2].getDecl(), n2);
36 EXPECT_EQ(set[3].getDecl(), n3);
39 TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
40 set.erase(0);
41 EXPECT_EQ(set.size(), 3u);
42 EXPECT_EQ(set[0].getDecl(), n3);
43 EXPECT_EQ(set[1].getDecl(), n1);
44 EXPECT_EQ(set[2].getDecl(), n2);
46 set.erase(0);
47 EXPECT_EQ(set.size(), 2u);
48 EXPECT_EQ(set[0].getDecl(), n2);
49 EXPECT_EQ(set[1].getDecl(), n1);
51 set.erase(0);
52 EXPECT_EQ(set.size(), 1u);
53 EXPECT_EQ(set[0].getDecl(), n1);
55 set.erase(0);
56 EXPECT_EQ(set.size(), 0u);
59 TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
60 set.erase(3);
61 EXPECT_EQ(set.size(), 3u);
62 EXPECT_EQ(set[0].getDecl(), n0);
63 EXPECT_EQ(set[1].getDecl(), n1);
64 EXPECT_EQ(set[2].getDecl(), n2);
66 set.erase(2);
67 EXPECT_EQ(set.size(), 2u);
68 EXPECT_EQ(set[0].getDecl(), n0);
69 EXPECT_EQ(set[1].getDecl(), n1);
71 set.erase(1);
72 EXPECT_EQ(set.size(), 1u);
73 EXPECT_EQ(set[0].getDecl(), n0);
75 set.erase(0);
76 EXPECT_EQ(set.size(), 0u);
79 TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
80 set.erase(set.begin());
81 EXPECT_EQ(set.size(), 3u);
82 EXPECT_EQ(set[0].getDecl(), n3);
83 EXPECT_EQ(set[1].getDecl(), n1);
84 EXPECT_EQ(set[2].getDecl(), n2);
86 set.erase(set.begin());
87 EXPECT_EQ(set.size(), 2u);
88 EXPECT_EQ(set[0].getDecl(), n2);
89 EXPECT_EQ(set[1].getDecl(), n1);
91 set.erase(set.begin());
92 EXPECT_EQ(set.size(), 1u);
93 EXPECT_EQ(set[0].getDecl(), n1);
95 set.erase(set.begin());
96 EXPECT_EQ(set.size(), 0u);
99 TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
100 set.erase(--set.end());
101 EXPECT_EQ(set.size(), 3u);
102 EXPECT_EQ(set[0].getDecl(), n0);
103 EXPECT_EQ(set[1].getDecl(), n1);
104 EXPECT_EQ(set[2].getDecl(), n2);
106 set.erase(--set.end());
107 EXPECT_EQ(set.size(), 2u);
108 EXPECT_EQ(set[0].getDecl(), n0);
109 EXPECT_EQ(set[1].getDecl(), n1);
111 set.erase(--set.end());
112 EXPECT_EQ(set.size(), 1u);
113 EXPECT_EQ(set[0].getDecl(), n0);
115 set.erase(--set.end());
116 EXPECT_EQ(set.size(), 0u);