Duncan P. N. Exon Smith | 71db642 | 2015-02-02 18:20:15 +0000 | [diff] [blame] | 1 | //===- unittests/IR/MetadataTest.cpp - Metadata unit tests ----------------===// |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Constants.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 12 | #include "llvm/IR/DebugInfoMetadata.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 13 | #include "llvm/IR/Instructions.h" |
| 14 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Metadata.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Module.h" |
| 17 | #include "llvm/IR/Type.h" |
Chandler Carruth | 130cec2 | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 130cec2 | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 19 | #include "gtest/gtest.h" |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
| 23 | |
Duncan P. N. Exon Smith | 2711ca7 | 2015-01-19 19:02:06 +0000 | [diff] [blame] | 24 | TEST(ContextAndReplaceableUsesTest, FromContext) { |
| 25 | LLVMContext Context; |
| 26 | ContextAndReplaceableUses CRU(Context); |
| 27 | EXPECT_EQ(&Context, &CRU.getContext()); |
| 28 | EXPECT_FALSE(CRU.hasReplaceableUses()); |
| 29 | EXPECT_FALSE(CRU.getReplaceableUses()); |
| 30 | } |
| 31 | |
| 32 | TEST(ContextAndReplaceableUsesTest, FromReplaceableUses) { |
| 33 | LLVMContext Context; |
| 34 | ContextAndReplaceableUses CRU(make_unique<ReplaceableMetadataImpl>(Context)); |
| 35 | EXPECT_EQ(&Context, &CRU.getContext()); |
| 36 | EXPECT_TRUE(CRU.hasReplaceableUses()); |
| 37 | EXPECT_TRUE(CRU.getReplaceableUses()); |
| 38 | } |
| 39 | |
| 40 | TEST(ContextAndReplaceableUsesTest, makeReplaceable) { |
| 41 | LLVMContext Context; |
| 42 | ContextAndReplaceableUses CRU(Context); |
| 43 | CRU.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context)); |
| 44 | EXPECT_EQ(&Context, &CRU.getContext()); |
| 45 | EXPECT_TRUE(CRU.hasReplaceableUses()); |
| 46 | EXPECT_TRUE(CRU.getReplaceableUses()); |
| 47 | } |
| 48 | |
| 49 | TEST(ContextAndReplaceableUsesTest, takeReplaceableUses) { |
| 50 | LLVMContext Context; |
| 51 | auto ReplaceableUses = make_unique<ReplaceableMetadataImpl>(Context); |
| 52 | auto *Ptr = ReplaceableUses.get(); |
| 53 | ContextAndReplaceableUses CRU(std::move(ReplaceableUses)); |
| 54 | ReplaceableUses = CRU.takeReplaceableUses(); |
| 55 | EXPECT_EQ(&Context, &CRU.getContext()); |
| 56 | EXPECT_FALSE(CRU.hasReplaceableUses()); |
| 57 | EXPECT_FALSE(CRU.getReplaceableUses()); |
| 58 | EXPECT_EQ(Ptr, ReplaceableUses.get()); |
| 59 | } |
| 60 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 61 | class MetadataTest : public testing::Test { |
| 62 | protected: |
| 63 | LLVMContext Context; |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 64 | MDNode *getNode() { return MDNode::get(Context, None); } |
| 65 | MDNode *getNode(Metadata *MD) { return MDNode::get(Context, MD); } |
| 66 | MDNode *getNode(Metadata *MD1, Metadata *MD2) { |
| 67 | Metadata *MDs[] = {MD1, MD2}; |
| 68 | return MDNode::get(Context, MDs); |
| 69 | } |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 70 | }; |
| 71 | typedef MetadataTest MDStringTest; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 72 | |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 73 | // Test that construction of MDString with different value produces different |
| 74 | // MDString objects, even with the same string pointer and nulls in the string. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 75 | TEST_F(MDStringTest, CreateDifferent) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 76 | char x[3] = { 'f', 0, 'A' }; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 77 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 78 | x[2] = 'B'; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 79 | MDString *s2 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 80 | EXPECT_NE(s1, s2); |
| 81 | } |
| 82 | |
| 83 | // Test that creation of MDStrings with the same string contents produces the |
| 84 | // same MDString object, even with different pointers. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 85 | TEST_F(MDStringTest, CreateSame) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 86 | char x[4] = { 'a', 'b', 'c', 'X' }; |
| 87 | char y[4] = { 'a', 'b', 'c', 'Y' }; |
| 88 | |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 89 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 90 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 91 | EXPECT_EQ(s1, s2); |
| 92 | } |
| 93 | |
| 94 | // Test that MDString prints out the string we fed it. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 95 | TEST_F(MDStringTest, PrintingSimple) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 96 | char *str = new char[13]; |
| 97 | strncpy(str, "testing 1 2 3", 13); |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 98 | MDString *s = MDString::get(Context, StringRef(str, 13)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 99 | strncpy(str, "aaaaaaaaaaaaa", 13); |
| 100 | delete[] str; |
| 101 | |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 102 | std::string Str; |
| 103 | raw_string_ostream oss(Str); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 104 | s->print(oss); |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 105 | EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str()); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | // Test printing of MDString with non-printable characters. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 109 | TEST_F(MDStringTest, PrintingComplex) { |
Jeffrey Yasskin | 065c357 | 2011-08-30 20:53:29 +0000 | [diff] [blame] | 110 | char str[5] = {0, '\n', '"', '\\', (char)-1}; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 111 | MDString *s = MDString::get(Context, StringRef(str+0, 5)); |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 112 | std::string Str; |
| 113 | raw_string_ostream oss(Str); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 114 | s->print(oss); |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 115 | EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str()); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 118 | typedef MetadataTest MDNodeTest; |
| 119 | |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 120 | // Test the two constructors, and containing other Constants. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 121 | TEST_F(MDNodeTest, Simple) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 122 | char x[3] = { 'a', 'b', 'c' }; |
| 123 | char y[3] = { '1', '2', '3' }; |
| 124 | |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 125 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 126 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 127 | ConstantAsMetadata *CI = ConstantAsMetadata::get( |
| 128 | ConstantInt::get(getGlobalContext(), APInt(8, 0))); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 129 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 130 | std::vector<Metadata *> V; |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 131 | V.push_back(s1); |
| 132 | V.push_back(CI); |
| 133 | V.push_back(s2); |
| 134 | |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 135 | MDNode *n1 = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 136 | Metadata *const c1 = n1; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 137 | MDNode *n2 = MDNode::get(Context, c1); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 138 | Metadata *const c2 = n2; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 139 | MDNode *n3 = MDNode::get(Context, V); |
Duncan Sands | 26a80f3 | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 140 | MDNode *n4 = MDNode::getIfExists(Context, V); |
| 141 | MDNode *n5 = MDNode::getIfExists(Context, c1); |
| 142 | MDNode *n6 = MDNode::getIfExists(Context, c2); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 143 | EXPECT_NE(n1, n2); |
Devang Patel | f718832 | 2009-09-03 01:39:20 +0000 | [diff] [blame] | 144 | EXPECT_EQ(n1, n3); |
Duncan Sands | 26a80f3 | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 145 | EXPECT_EQ(n4, n1); |
| 146 | EXPECT_EQ(n5, n2); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 147 | EXPECT_EQ(n6, (Metadata *)nullptr); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 9b49302 | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 149 | EXPECT_EQ(3u, n1->getNumOperands()); |
| 150 | EXPECT_EQ(s1, n1->getOperand(0)); |
| 151 | EXPECT_EQ(CI, n1->getOperand(1)); |
| 152 | EXPECT_EQ(s2, n1->getOperand(2)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 153 | |
Chris Lattner | 9b49302 | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 154 | EXPECT_EQ(1u, n2->getNumOperands()); |
| 155 | EXPECT_EQ(n1, n2->getOperand(0)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 156 | } |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 157 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 158 | TEST_F(MDNodeTest, Delete) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 159 | Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1); |
| 160 | Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext())); |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 161 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 162 | Metadata *const V = LocalAsMetadata::get(I); |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 163 | MDNode *n = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 164 | TrackingMDRef wvh(n); |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 165 | |
| 166 | EXPECT_EQ(n, wvh); |
| 167 | |
| 168 | delete I; |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 169 | } |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 170 | |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 171 | TEST_F(MDNodeTest, SelfReference) { |
Duncan P. N. Exon Smith | 8c66273 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 172 | // !0 = !{!0} |
| 173 | // !1 = !{!0} |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 174 | { |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 175 | auto Temp = MDNode::getTemporary(Context, None); |
| 176 | Metadata *Args[] = {Temp.get()}; |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 177 | MDNode *Self = MDNode::get(Context, Args); |
| 178 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 179 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 180 | |
| 181 | // Self-references should be distinct, so MDNode::get() should grab a |
| 182 | // uniqued node that references Self, not Self. |
| 183 | Args[0] = Self; |
| 184 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 185 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 186 | EXPECT_NE(Self, Ref1); |
| 187 | EXPECT_EQ(Ref1, Ref2); |
| 188 | } |
| 189 | |
Duncan P. N. Exon Smith | 8c66273 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 190 | // !0 = !{!0, !{}} |
| 191 | // !1 = !{!0, !{}} |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 192 | { |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 193 | auto Temp = MDNode::getTemporary(Context, None); |
| 194 | Metadata *Args[] = {Temp.get(), MDNode::get(Context, None)}; |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 195 | MDNode *Self = MDNode::get(Context, Args); |
| 196 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 197 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 198 | |
| 199 | // Self-references should be distinct, so MDNode::get() should grab a |
| 200 | // uniqued node that references Self, not Self itself. |
| 201 | Args[0] = Self; |
| 202 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 203 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 204 | EXPECT_NE(Self, Ref1); |
| 205 | EXPECT_EQ(Ref1, Ref2); |
| 206 | } |
| 207 | } |
| 208 | |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 209 | TEST_F(MDNodeTest, Print) { |
| 210 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7); |
| 211 | MDString *S = MDString::get(Context, "foo"); |
| 212 | MDNode *N0 = getNode(); |
| 213 | MDNode *N1 = getNode(N0); |
| 214 | MDNode *N2 = getNode(N0, N1); |
| 215 | |
| 216 | Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2}; |
| 217 | MDNode *N = MDNode::get(Context, Args); |
| 218 | |
| 219 | std::string Expected; |
| 220 | { |
| 221 | raw_string_ostream OS(Expected); |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 222 | OS << "!{"; |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 223 | C->printAsOperand(OS); |
| 224 | OS << ", "; |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 225 | S->printAsOperand(OS); |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 226 | OS << ", null"; |
| 227 | MDNode *Nodes[] = {N0, N1, N2}; |
| 228 | for (auto *Node : Nodes) |
| 229 | OS << ", <" << (void *)Node << ">"; |
| 230 | OS << "}\n"; |
| 231 | } |
| 232 | |
| 233 | std::string Actual; |
| 234 | { |
| 235 | raw_string_ostream OS(Actual); |
| 236 | N->print(OS); |
| 237 | } |
| 238 | |
| 239 | EXPECT_EQ(Expected, Actual); |
| 240 | } |
| 241 | |
Duncan P. N. Exon Smith | bcd960a | 2015-01-05 23:31:54 +0000 | [diff] [blame] | 242 | TEST_F(MDNodeTest, NullOperand) { |
| 243 | // metadata !{} |
| 244 | MDNode *Empty = MDNode::get(Context, None); |
| 245 | |
| 246 | // metadata !{metadata !{}} |
| 247 | Metadata *Ops[] = {Empty}; |
| 248 | MDNode *N = MDNode::get(Context, Ops); |
| 249 | ASSERT_EQ(Empty, N->getOperand(0)); |
| 250 | |
| 251 | // metadata !{metadata !{}} => metadata !{null} |
| 252 | N->replaceOperandWith(0, nullptr); |
| 253 | ASSERT_EQ(nullptr, N->getOperand(0)); |
| 254 | |
| 255 | // metadata !{null} |
| 256 | Ops[0] = nullptr; |
| 257 | MDNode *NullOp = MDNode::get(Context, Ops); |
| 258 | ASSERT_EQ(nullptr, NullOp->getOperand(0)); |
| 259 | EXPECT_EQ(N, NullOp); |
| 260 | } |
| 261 | |
Duncan P. N. Exon Smith | 136ea3f | 2015-01-07 21:35:38 +0000 | [diff] [blame] | 262 | TEST_F(MDNodeTest, DistinctOnUniquingCollision) { |
| 263 | // !{} |
| 264 | MDNode *Empty = MDNode::get(Context, None); |
| 265 | ASSERT_TRUE(Empty->isResolved()); |
| 266 | EXPECT_FALSE(Empty->isDistinct()); |
| 267 | |
| 268 | // !{!{}} |
| 269 | Metadata *Wrapped1Ops[] = {Empty}; |
| 270 | MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops); |
| 271 | ASSERT_EQ(Empty, Wrapped1->getOperand(0)); |
| 272 | ASSERT_TRUE(Wrapped1->isResolved()); |
| 273 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 274 | |
| 275 | // !{!{!{}}} |
| 276 | Metadata *Wrapped2Ops[] = {Wrapped1}; |
| 277 | MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops); |
| 278 | ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0)); |
| 279 | ASSERT_TRUE(Wrapped2->isResolved()); |
| 280 | EXPECT_FALSE(Wrapped2->isDistinct()); |
| 281 | |
| 282 | // !{!{!{}}} => !{!{}} |
| 283 | Wrapped2->replaceOperandWith(0, Empty); |
| 284 | ASSERT_EQ(Empty, Wrapped2->getOperand(0)); |
| 285 | EXPECT_TRUE(Wrapped2->isDistinct()); |
| 286 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 287 | } |
| 288 | |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 289 | TEST_F(MDNodeTest, getDistinct) { |
| 290 | // !{} |
| 291 | MDNode *Empty = MDNode::get(Context, None); |
| 292 | ASSERT_TRUE(Empty->isResolved()); |
| 293 | ASSERT_FALSE(Empty->isDistinct()); |
| 294 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 295 | |
| 296 | // distinct !{} |
| 297 | MDNode *Distinct1 = MDNode::getDistinct(Context, None); |
| 298 | MDNode *Distinct2 = MDNode::getDistinct(Context, None); |
| 299 | EXPECT_TRUE(Distinct1->isResolved()); |
| 300 | EXPECT_TRUE(Distinct2->isDistinct()); |
| 301 | EXPECT_NE(Empty, Distinct1); |
| 302 | EXPECT_NE(Empty, Distinct2); |
| 303 | EXPECT_NE(Distinct1, Distinct2); |
| 304 | |
| 305 | // !{} |
| 306 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 307 | } |
| 308 | |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 309 | TEST_F(MDNodeTest, isUniqued) { |
| 310 | MDNode *U = MDTuple::get(Context, None); |
| 311 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 312 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 313 | EXPECT_TRUE(U->isUniqued()); |
| 314 | EXPECT_FALSE(D->isUniqued()); |
| 315 | EXPECT_FALSE(T->isUniqued()); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | TEST_F(MDNodeTest, isDistinct) { |
| 319 | MDNode *U = MDTuple::get(Context, None); |
| 320 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 321 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 322 | EXPECT_FALSE(U->isDistinct()); |
| 323 | EXPECT_TRUE(D->isDistinct()); |
| 324 | EXPECT_FALSE(T->isDistinct()); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | TEST_F(MDNodeTest, isTemporary) { |
| 328 | MDNode *U = MDTuple::get(Context, None); |
| 329 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 330 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 331 | EXPECT_FALSE(U->isTemporary()); |
| 332 | EXPECT_FALSE(D->isTemporary()); |
| 333 | EXPECT_TRUE(T->isTemporary()); |
Duncan P. N. Exon Smith | d1474ee | 2015-01-12 18:41:26 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 336 | TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) { |
| 337 | // temporary !{} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 338 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 339 | ASSERT_FALSE(Temp->isResolved()); |
| 340 | |
| 341 | // distinct !{temporary !{}} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 342 | Metadata *Ops[] = {Temp.get()}; |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 343 | MDNode *Distinct = MDNode::getDistinct(Context, Ops); |
| 344 | EXPECT_TRUE(Distinct->isResolved()); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 345 | EXPECT_EQ(Temp.get(), Distinct->getOperand(0)); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 346 | |
| 347 | // temporary !{} => !{} |
| 348 | MDNode *Empty = MDNode::get(Context, None); |
| 349 | Temp->replaceAllUsesWith(Empty); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 350 | EXPECT_EQ(Empty, Distinct->getOperand(0)); |
| 351 | } |
| 352 | |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 353 | TEST_F(MDNodeTest, handleChangedOperandRecursion) { |
| 354 | // !0 = !{} |
| 355 | MDNode *N0 = MDNode::get(Context, None); |
| 356 | |
| 357 | // !1 = !{!3, null} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 358 | auto Temp3 = MDTuple::getTemporary(Context, None); |
| 359 | Metadata *Ops1[] = {Temp3.get(), nullptr}; |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 360 | MDNode *N1 = MDNode::get(Context, Ops1); |
| 361 | |
| 362 | // !2 = !{!3, !0} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 363 | Metadata *Ops2[] = {Temp3.get(), N0}; |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 364 | MDNode *N2 = MDNode::get(Context, Ops2); |
| 365 | |
| 366 | // !3 = !{!2} |
| 367 | Metadata *Ops3[] = {N2}; |
| 368 | MDNode *N3 = MDNode::get(Context, Ops3); |
| 369 | Temp3->replaceAllUsesWith(N3); |
| 370 | |
| 371 | // !4 = !{!1} |
| 372 | Metadata *Ops4[] = {N1}; |
| 373 | MDNode *N4 = MDNode::get(Context, Ops4); |
| 374 | |
| 375 | // Confirm that the cycle prevented RAUW from getting dropped. |
| 376 | EXPECT_TRUE(N0->isResolved()); |
| 377 | EXPECT_FALSE(N1->isResolved()); |
| 378 | EXPECT_FALSE(N2->isResolved()); |
| 379 | EXPECT_FALSE(N3->isResolved()); |
| 380 | EXPECT_FALSE(N4->isResolved()); |
| 381 | |
| 382 | // Create a couple of distinct nodes to observe what's going on. |
| 383 | // |
| 384 | // !5 = distinct !{!2} |
| 385 | // !6 = distinct !{!3} |
| 386 | Metadata *Ops5[] = {N2}; |
| 387 | MDNode *N5 = MDNode::getDistinct(Context, Ops5); |
| 388 | Metadata *Ops6[] = {N3}; |
| 389 | MDNode *N6 = MDNode::getDistinct(Context, Ops6); |
| 390 | |
| 391 | // Mutate !2 to look like !1, causing a uniquing collision (and an RAUW). |
| 392 | // This will ripple up, with !3 colliding with !4, and RAUWing. Since !2 |
| 393 | // references !3, this can cause a re-entry of handleChangedOperand() when !3 |
| 394 | // is not ready for it. |
| 395 | // |
| 396 | // !2->replaceOperandWith(1, nullptr) |
| 397 | // !2: !{!3, !0} => !{!3, null} |
| 398 | // !2->replaceAllUsesWith(!1) |
| 399 | // !3: !{!2] => !{!1} |
| 400 | // !3->replaceAllUsesWith(!4) |
| 401 | N2->replaceOperandWith(1, nullptr); |
| 402 | |
| 403 | // If all has gone well, N2 and N3 will have been RAUW'ed and deleted from |
| 404 | // under us. Just check that the other nodes are sane. |
| 405 | // |
| 406 | // !1 = !{!4, null} |
| 407 | // !4 = !{!1} |
| 408 | // !5 = distinct !{!1} |
| 409 | // !6 = distinct !{!4} |
| 410 | EXPECT_EQ(N4, N1->getOperand(0)); |
| 411 | EXPECT_EQ(N1, N4->getOperand(0)); |
| 412 | EXPECT_EQ(N1, N5->getOperand(0)); |
| 413 | EXPECT_EQ(N4, N6->getOperand(0)); |
| 414 | } |
| 415 | |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 416 | TEST_F(MDNodeTest, replaceResolvedOperand) { |
| 417 | // Check code for replacing one resolved operand with another. If doing this |
| 418 | // directly (via replaceOperandWith()) becomes illegal, change the operand to |
| 419 | // a global value that gets RAUW'ed. |
| 420 | // |
| 421 | // Use a temporary node to keep N from being resolved. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 422 | auto Temp = MDTuple::getTemporary(Context, None); |
| 423 | Metadata *Ops[] = {nullptr, Temp.get()}; |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 424 | |
NAKAMURA Takumi | 2f8f054 | 2015-01-13 08:13:46 +0000 | [diff] [blame] | 425 | MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>()); |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 426 | MDNode *N = MDTuple::get(Context, Ops); |
| 427 | EXPECT_EQ(nullptr, N->getOperand(0)); |
| 428 | ASSERT_FALSE(N->isResolved()); |
| 429 | |
| 430 | // Check code for replacing resolved nodes. |
| 431 | N->replaceOperandWith(0, Empty); |
| 432 | EXPECT_EQ(Empty, N->getOperand(0)); |
| 433 | |
| 434 | // Check code for adding another unresolved operand. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 435 | N->replaceOperandWith(0, Temp.get()); |
| 436 | EXPECT_EQ(Temp.get(), N->getOperand(0)); |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 437 | |
| 438 | // Remove the references to Temp; required for teardown. |
| 439 | Temp->replaceAllUsesWith(nullptr); |
| 440 | } |
| 441 | |
Duncan P. N. Exon Smith | e335309 | 2015-01-19 22:24:52 +0000 | [diff] [blame] | 442 | TEST_F(MDNodeTest, replaceWithUniqued) { |
| 443 | auto *Empty = MDTuple::get(Context, None); |
| 444 | MDTuple *FirstUniqued; |
| 445 | { |
| 446 | Metadata *Ops[] = {Empty}; |
| 447 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 448 | EXPECT_TRUE(Temp->isTemporary()); |
| 449 | |
| 450 | // Don't expect a collision. |
| 451 | auto *Current = Temp.get(); |
| 452 | FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 453 | EXPECT_TRUE(FirstUniqued->isUniqued()); |
| 454 | EXPECT_TRUE(FirstUniqued->isResolved()); |
| 455 | EXPECT_EQ(Current, FirstUniqued); |
| 456 | } |
| 457 | { |
| 458 | Metadata *Ops[] = {Empty}; |
| 459 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 460 | EXPECT_TRUE(Temp->isTemporary()); |
| 461 | |
| 462 | // Should collide with Uniqued above this time. |
| 463 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 464 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 465 | EXPECT_TRUE(Uniqued->isResolved()); |
| 466 | EXPECT_EQ(FirstUniqued, Uniqued); |
| 467 | } |
| 468 | { |
| 469 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 470 | Metadata *Ops[] = {Unresolved.get()}; |
| 471 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 472 | EXPECT_TRUE(Temp->isTemporary()); |
| 473 | |
| 474 | // Shouldn't be resolved. |
| 475 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 476 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 477 | EXPECT_FALSE(Uniqued->isResolved()); |
| 478 | |
| 479 | // Should be a different node. |
| 480 | EXPECT_NE(FirstUniqued, Uniqued); |
| 481 | |
| 482 | // Should resolve when we update its node (note: be careful to avoid a |
| 483 | // collision with any other nodes above). |
| 484 | Uniqued->replaceOperandWith(0, nullptr); |
| 485 | EXPECT_TRUE(Uniqued->isResolved()); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | TEST_F(MDNodeTest, replaceWithDistinct) { |
| 490 | { |
| 491 | auto *Empty = MDTuple::get(Context, None); |
| 492 | Metadata *Ops[] = {Empty}; |
| 493 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 494 | EXPECT_TRUE(Temp->isTemporary()); |
| 495 | |
| 496 | // Don't expect a collision. |
| 497 | auto *Current = Temp.get(); |
| 498 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 499 | EXPECT_TRUE(Distinct->isDistinct()); |
| 500 | EXPECT_TRUE(Distinct->isResolved()); |
| 501 | EXPECT_EQ(Current, Distinct); |
| 502 | } |
| 503 | { |
| 504 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 505 | Metadata *Ops[] = {Unresolved.get()}; |
| 506 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 507 | EXPECT_TRUE(Temp->isTemporary()); |
| 508 | |
| 509 | // Don't expect a collision. |
| 510 | auto *Current = Temp.get(); |
| 511 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 512 | EXPECT_TRUE(Distinct->isDistinct()); |
| 513 | EXPECT_TRUE(Distinct->isResolved()); |
| 514 | EXPECT_EQ(Current, Distinct); |
| 515 | |
| 516 | // Cleanup; required for teardown. |
| 517 | Unresolved->replaceAllUsesWith(nullptr); |
| 518 | } |
| 519 | } |
| 520 | |
Duncan P. N. Exon Smith | 4ee4a98 | 2015-02-10 19:13:46 +0000 | [diff] [blame] | 521 | TEST_F(MDNodeTest, replaceWithPermanent) { |
| 522 | Metadata *Ops[] = {nullptr}; |
| 523 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 524 | auto *T = Temp.get(); |
| 525 | |
| 526 | // U is a normal, uniqued node that references T. |
| 527 | auto *U = MDTuple::get(Context, T); |
| 528 | EXPECT_TRUE(U->isUniqued()); |
| 529 | |
| 530 | // Make Temp self-referencing. |
| 531 | Temp->replaceOperandWith(0, T); |
| 532 | |
| 533 | // Try to uniquify Temp. This should, despite the name in the API, give a |
| 534 | // 'distinct' node, since self-references aren't allowed to be uniqued. |
| 535 | // |
| 536 | // Since it's distinct, N should have the same address as when it was a |
| 537 | // temporary (i.e., be equal to T not U). |
| 538 | auto *N = MDNode::replaceWithPermanent(std::move(Temp)); |
| 539 | EXPECT_EQ(N, T); |
| 540 | EXPECT_TRUE(N->isDistinct()); |
| 541 | |
| 542 | // U should be the canonical unique node with N as the argument. |
| 543 | EXPECT_EQ(U, MDTuple::get(Context, N)); |
| 544 | EXPECT_TRUE(U->isUniqued()); |
| 545 | |
| 546 | // This temporary should collide with U when replaced, but it should still be |
| 547 | // uniqued. |
| 548 | EXPECT_EQ(U, MDNode::replaceWithPermanent(MDTuple::getTemporary(Context, N))); |
| 549 | EXPECT_TRUE(U->isUniqued()); |
| 550 | |
| 551 | // This temporary should become a new uniqued node. |
| 552 | auto Temp2 = MDTuple::getTemporary(Context, U); |
| 553 | auto *V = Temp2.get(); |
| 554 | EXPECT_EQ(V, MDNode::replaceWithPermanent(std::move(Temp2))); |
| 555 | EXPECT_TRUE(V->isUniqued()); |
| 556 | EXPECT_EQ(U, V->getOperand(0)); |
| 557 | } |
| 558 | |
Duncan P. N. Exon Smith | 8d53697 | 2015-01-22 21:36:45 +0000 | [diff] [blame] | 559 | TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) { |
| 560 | TrackingMDRef Ref; |
| 561 | EXPECT_EQ(nullptr, Ref.get()); |
| 562 | { |
| 563 | auto Temp = MDTuple::getTemporary(Context, None); |
| 564 | Ref.reset(Temp.get()); |
| 565 | EXPECT_EQ(Temp.get(), Ref.get()); |
| 566 | } |
| 567 | EXPECT_EQ(nullptr, Ref.get()); |
| 568 | } |
| 569 | |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 570 | typedef MetadataTest MDLocationTest; |
| 571 | |
| 572 | TEST_F(MDLocationTest, Overflow) { |
| 573 | MDNode *N = MDNode::get(Context, None); |
| 574 | { |
| 575 | MDLocation *L = MDLocation::get(Context, 2, 7, N); |
| 576 | EXPECT_EQ(2u, L->getLine()); |
| 577 | EXPECT_EQ(7u, L->getColumn()); |
| 578 | } |
Duncan P. N. Exon Smith | 2f5bb31 | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 579 | unsigned U16 = 1u << 16; |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 580 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 581 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 - 1, N); |
| 582 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | 2f5bb31 | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 583 | EXPECT_EQ(U16 - 1, L->getColumn()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 584 | } |
| 585 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 586 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16, N); |
| 587 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 588 | EXPECT_EQ(0u, L->getColumn()); |
| 589 | } |
| 590 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 591 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 + 1, N); |
| 592 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 593 | EXPECT_EQ(0u, L->getColumn()); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | TEST_F(MDLocationTest, getDistinct) { |
| 598 | MDNode *N = MDNode::get(Context, None); |
| 599 | MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N); |
| 600 | EXPECT_TRUE(L0->isDistinct()); |
| 601 | MDLocation *L1 = MDLocation::get(Context, 2, 7, N); |
| 602 | EXPECT_FALSE(L1->isDistinct()); |
| 603 | EXPECT_EQ(L1, MDLocation::get(Context, 2, 7, N)); |
| 604 | } |
| 605 | |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 606 | TEST_F(MDLocationTest, getTemporary) { |
| 607 | MDNode *N = MDNode::get(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 608 | auto L = MDLocation::getTemporary(Context, 2, 7, N); |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 609 | EXPECT_TRUE(L->isTemporary()); |
| 610 | EXPECT_FALSE(L->isResolved()); |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 613 | typedef MetadataTest GenericDebugNodeTest; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 614 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 615 | TEST_F(GenericDebugNodeTest, get) { |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 616 | StringRef Header = "header"; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 617 | auto *Empty = MDNode::get(Context, None); |
| 618 | Metadata *Ops1[] = {Empty}; |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 619 | auto *N = GenericDebugNode::get(Context, 15, Header, Ops1); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 620 | EXPECT_EQ(15u, N->getTag()); |
| 621 | EXPECT_EQ(2u, N->getNumOperands()); |
| 622 | EXPECT_EQ(Header, N->getHeader()); |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 623 | EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 624 | EXPECT_EQ(1u, N->getNumDwarfOperands()); |
| 625 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 626 | EXPECT_EQ(Empty, N->getOperand(1)); |
| 627 | ASSERT_TRUE(N->isUniqued()); |
| 628 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 629 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 630 | |
| 631 | N->replaceOperandWith(1, nullptr); |
| 632 | EXPECT_EQ(15u, N->getTag()); |
| 633 | EXPECT_EQ(Header, N->getHeader()); |
| 634 | EXPECT_EQ(nullptr, N->getDwarfOperand(0)); |
| 635 | ASSERT_TRUE(N->isUniqued()); |
| 636 | |
| 637 | Metadata *Ops2[] = {nullptr}; |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 638 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 639 | |
| 640 | N->replaceDwarfOperandWith(0, Empty); |
| 641 | EXPECT_EQ(15u, N->getTag()); |
| 642 | EXPECT_EQ(Header, N->getHeader()); |
| 643 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 644 | ASSERT_TRUE(N->isUniqued()); |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 645 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 648 | TEST_F(GenericDebugNodeTest, getEmptyHeader) { |
Duncan P. N. Exon Smith | 2da09e4 | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 649 | // Canonicalize !"" to null. |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 650 | auto *N = GenericDebugNode::get(Context, 15, StringRef(), None); |
| 651 | EXPECT_EQ(StringRef(), N->getHeader()); |
| 652 | EXPECT_EQ(nullptr, N->getOperand(0)); |
Duncan P. N. Exon Smith | 2da09e4 | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 655 | typedef MetadataTest MDSubrangeTest; |
| 656 | |
| 657 | TEST_F(MDSubrangeTest, get) { |
| 658 | auto *N = MDSubrange::get(Context, 5, 7); |
| 659 | EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); |
| 660 | EXPECT_EQ(5, N->getCount()); |
| 661 | EXPECT_EQ(7, N->getLo()); |
| 662 | EXPECT_EQ(N, MDSubrange::get(Context, 5, 7)); |
| 663 | EXPECT_EQ(MDSubrange::get(Context, 5, 0), MDSubrange::get(Context, 5)); |
| 664 | } |
| 665 | |
| 666 | typedef MetadataTest MDEnumeratorTest; |
| 667 | |
| 668 | TEST_F(MDEnumeratorTest, get) { |
| 669 | auto *N = MDEnumerator::get(Context, 7, "name"); |
| 670 | EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag()); |
| 671 | EXPECT_EQ(7, N->getValue()); |
| 672 | EXPECT_EQ("name", N->getName()); |
| 673 | EXPECT_EQ(N, MDEnumerator::get(Context, 7, "name")); |
| 674 | |
| 675 | EXPECT_NE(N, MDEnumerator::get(Context, 8, "name")); |
| 676 | EXPECT_NE(N, MDEnumerator::get(Context, 7, "nam")); |
| 677 | } |
| 678 | |
| 679 | typedef MetadataTest MDBasicTypeTest; |
| 680 | |
| 681 | TEST_F(MDBasicTypeTest, get) { |
| 682 | auto *N = |
| 683 | MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7); |
| 684 | EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag()); |
| 685 | EXPECT_EQ("special", N->getName()); |
| 686 | EXPECT_EQ(33u, N->getSizeInBits()); |
| 687 | EXPECT_EQ(26u, N->getAlignInBits()); |
| 688 | EXPECT_EQ(7u, N->getEncoding()); |
| 689 | EXPECT_EQ(0u, N->getLine()); |
| 690 | EXPECT_EQ(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 691 | 26, 7)); |
| 692 | |
| 693 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, |
| 694 | "special", 33, 26, 7)); |
| 695 | EXPECT_NE(N, |
| 696 | MDBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7)); |
| 697 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32, |
| 698 | 26, 7)); |
| 699 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 700 | 25, 7)); |
| 701 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 702 | 26, 6)); |
| 703 | } |
| 704 | |
| 705 | typedef MetadataTest MDDerivedTypeTest; |
| 706 | |
| 707 | TEST_F(MDDerivedTypeTest, get) { |
| 708 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 709 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 710 | Metadata *BaseType = MDTuple::getDistinct(Context, None); |
| 711 | Metadata *ExtraData = MDTuple::getDistinct(Context, None); |
| 712 | |
| 713 | auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 714 | File, 1, Scope, BaseType, 2, 3, 4, 5, ExtraData); |
| 715 | EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag()); |
| 716 | EXPECT_EQ("something", N->getName()); |
| 717 | EXPECT_EQ(File, N->getFile()); |
| 718 | EXPECT_EQ(1u, N->getLine()); |
| 719 | EXPECT_EQ(Scope, N->getScope()); |
| 720 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 721 | EXPECT_EQ(2u, N->getSizeInBits()); |
| 722 | EXPECT_EQ(3u, N->getAlignInBits()); |
| 723 | EXPECT_EQ(4u, N->getOffsetInBits()); |
| 724 | EXPECT_EQ(5u, N->getFlags()); |
| 725 | EXPECT_EQ(ExtraData, N->getExtraData()); |
| 726 | EXPECT_EQ(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 727 | "something", File, 1, Scope, BaseType, 2, 3, |
| 728 | 4, 5, ExtraData)); |
| 729 | |
| 730 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_reference_type, |
| 731 | "something", File, 1, Scope, BaseType, 2, 3, |
| 732 | 4, 5, ExtraData)); |
| 733 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else", |
| 734 | File, 1, Scope, BaseType, 2, 3, 4, 5, |
| 735 | ExtraData)); |
| 736 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 737 | "something", Scope, 1, Scope, BaseType, 2, 3, |
| 738 | 4, 5, ExtraData)); |
| 739 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 740 | "something", File, 2, Scope, BaseType, 2, 3, |
| 741 | 4, 5, ExtraData)); |
| 742 | EXPECT_NE(N, |
| 743 | MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 744 | File, 1, File, BaseType, 2, 3, 4, 5, ExtraData)); |
| 745 | EXPECT_NE(N, |
| 746 | MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 747 | File, 1, Scope, File, 2, 3, 4, 5, ExtraData)); |
| 748 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 749 | "something", File, 1, Scope, BaseType, 3, 3, |
| 750 | 4, 5, ExtraData)); |
| 751 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 752 | "something", File, 1, Scope, BaseType, 2, 2, |
| 753 | 4, 5, ExtraData)); |
| 754 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 755 | "something", File, 1, Scope, BaseType, 2, 3, |
| 756 | 5, 5, ExtraData)); |
| 757 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 758 | "something", File, 1, Scope, BaseType, 2, 3, |
| 759 | 4, 4, ExtraData)); |
| 760 | EXPECT_NE(N, |
| 761 | MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 762 | File, 1, Scope, BaseType, 2, 3, 4, 5, File)); |
| 763 | } |
| 764 | |
| 765 | typedef MetadataTest MDCompositeTypeTest; |
| 766 | |
| 767 | TEST_F(MDCompositeTypeTest, get) { |
| 768 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 769 | StringRef Name = "some name"; |
| 770 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 771 | unsigned Line = 1; |
| 772 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 773 | Metadata *BaseType = MDTuple::getDistinct(Context, None); |
| 774 | unsigned SizeInBits = 2; |
| 775 | unsigned AlignInBits = 3; |
| 776 | unsigned OffsetInBits = 4; |
| 777 | unsigned Flags = 5; |
| 778 | Metadata *Elements = MDTuple::getDistinct(Context, None); |
| 779 | unsigned RuntimeLang = 6; |
| 780 | Metadata *VTableHolder = MDTuple::getDistinct(Context, None); |
| 781 | Metadata *TemplateParams = MDTuple::getDistinct(Context, None); |
| 782 | StringRef Identifier = "some id"; |
| 783 | |
| 784 | auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 785 | BaseType, SizeInBits, AlignInBits, |
| 786 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 787 | VTableHolder, TemplateParams, Identifier); |
| 788 | EXPECT_EQ(Tag, N->getTag()); |
| 789 | EXPECT_EQ(Name, N->getName()); |
| 790 | EXPECT_EQ(File, N->getFile()); |
| 791 | EXPECT_EQ(Line, N->getLine()); |
| 792 | EXPECT_EQ(Scope, N->getScope()); |
| 793 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 794 | EXPECT_EQ(SizeInBits, N->getSizeInBits()); |
| 795 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
| 796 | EXPECT_EQ(OffsetInBits, N->getOffsetInBits()); |
| 797 | EXPECT_EQ(Flags, N->getFlags()); |
| 798 | EXPECT_EQ(Elements, N->getElements()); |
| 799 | EXPECT_EQ(RuntimeLang, N->getRuntimeLang()); |
| 800 | EXPECT_EQ(VTableHolder, N->getVTableHolder()); |
| 801 | EXPECT_EQ(TemplateParams, N->getTemplateParams()); |
| 802 | EXPECT_EQ(Identifier, N->getIdentifier()); |
| 803 | |
| 804 | EXPECT_EQ(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 805 | BaseType, SizeInBits, AlignInBits, |
| 806 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 807 | VTableHolder, TemplateParams, Identifier)); |
| 808 | |
| 809 | EXPECT_NE(N, MDCompositeType::get(Context, Tag + 1, Name, File, Line, Scope, |
| 810 | BaseType, SizeInBits, AlignInBits, |
| 811 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 812 | VTableHolder, TemplateParams, Identifier)); |
| 813 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, "abc", File, Line, Scope, |
| 814 | BaseType, SizeInBits, AlignInBits, |
| 815 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 816 | VTableHolder, TemplateParams, Identifier)); |
| 817 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, Scope, Line, Scope, |
| 818 | BaseType, SizeInBits, AlignInBits, |
| 819 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 820 | VTableHolder, TemplateParams, Identifier)); |
| 821 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line + 1, Scope, |
| 822 | BaseType, SizeInBits, AlignInBits, |
| 823 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 824 | VTableHolder, TemplateParams, Identifier)); |
| 825 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, File, |
| 826 | BaseType, SizeInBits, AlignInBits, |
| 827 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 828 | VTableHolder, TemplateParams, Identifier)); |
| 829 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, File, |
| 830 | SizeInBits, AlignInBits, OffsetInBits, |
| 831 | Flags, Elements, RuntimeLang, VTableHolder, |
| 832 | TemplateParams, Identifier)); |
| 833 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 834 | BaseType, SizeInBits + 1, AlignInBits, |
| 835 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 836 | VTableHolder, TemplateParams, Identifier)); |
| 837 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 838 | BaseType, SizeInBits, AlignInBits + 1, |
| 839 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 840 | VTableHolder, TemplateParams, Identifier)); |
| 841 | EXPECT_NE(N, MDCompositeType::get( |
| 842 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 843 | AlignInBits, OffsetInBits + 1, Flags, Elements, RuntimeLang, |
| 844 | VTableHolder, TemplateParams, Identifier)); |
| 845 | EXPECT_NE(N, MDCompositeType::get( |
| 846 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 847 | AlignInBits, OffsetInBits, Flags + 1, Elements, RuntimeLang, |
| 848 | VTableHolder, TemplateParams, Identifier)); |
| 849 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 850 | BaseType, SizeInBits, AlignInBits, |
| 851 | OffsetInBits, Flags, File, RuntimeLang, |
| 852 | VTableHolder, TemplateParams, Identifier)); |
| 853 | EXPECT_NE(N, MDCompositeType::get( |
| 854 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 855 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang + 1, |
| 856 | VTableHolder, TemplateParams, Identifier)); |
| 857 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 858 | BaseType, SizeInBits, AlignInBits, |
| 859 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 860 | File, TemplateParams, Identifier)); |
| 861 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 862 | BaseType, SizeInBits, AlignInBits, |
| 863 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 864 | VTableHolder, File, Identifier)); |
| 865 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 866 | BaseType, SizeInBits, AlignInBits, |
| 867 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 868 | VTableHolder, TemplateParams, "other")); |
| 869 | |
| 870 | // Be sure that missing identifiers get null pointers. |
| 871 | EXPECT_FALSE(MDCompositeType::get( |
| 872 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 873 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 874 | VTableHolder, TemplateParams, "")->getRawIdentifier()); |
| 875 | EXPECT_FALSE(MDCompositeType::get( |
| 876 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 877 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 878 | VTableHolder, TemplateParams)->getRawIdentifier()); |
| 879 | } |
| 880 | |
| 881 | typedef MetadataTest MDSubroutineTypeTest; |
| 882 | |
| 883 | TEST_F(MDSubroutineTypeTest, get) { |
| 884 | unsigned Flags = 1; |
| 885 | Metadata *TypeArray = MDTuple::getDistinct(Context, None); |
| 886 | |
| 887 | auto *N = MDSubroutineType::get(Context, Flags, TypeArray); |
| 888 | EXPECT_EQ(dwarf::DW_TAG_subroutine_type, N->getTag()); |
| 889 | EXPECT_EQ(Flags, N->getFlags()); |
| 890 | EXPECT_EQ(TypeArray, N->getTypeArray()); |
| 891 | EXPECT_EQ(N, MDSubroutineType::get(Context, Flags, TypeArray)); |
| 892 | |
| 893 | EXPECT_NE(N, MDSubroutineType::get(Context, Flags + 1, TypeArray)); |
| 894 | EXPECT_NE(N, MDSubroutineType::get(Context, Flags, |
| 895 | MDTuple::getDistinct(Context, None))); |
| 896 | } |
| 897 | |
| 898 | typedef MetadataTest MDFileTest; |
| 899 | |
| 900 | TEST_F(MDFileTest, get) { |
| 901 | StringRef Filename = "file"; |
| 902 | StringRef Directory = "dir"; |
| 903 | auto *N = MDFile::get(Context, Filename, Directory); |
| 904 | |
| 905 | EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag()); |
| 906 | EXPECT_EQ(Filename, N->getFilename()); |
| 907 | EXPECT_EQ(Directory, N->getDirectory()); |
| 908 | EXPECT_EQ(N, MDFile::get(Context, Filename, Directory)); |
| 909 | |
| 910 | EXPECT_NE(N, MDFile::get(Context, "other", Directory)); |
| 911 | EXPECT_NE(N, MDFile::get(Context, Filename, "other")); |
| 912 | } |
| 913 | |
| 914 | typedef MetadataTest MDCompileUnitTest; |
| 915 | |
| 916 | TEST_F(MDCompileUnitTest, get) { |
| 917 | unsigned SourceLanguage = 1; |
| 918 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 919 | StringRef Producer = "some producer"; |
| 920 | bool IsOptimized = false; |
| 921 | StringRef Flags = "flag after flag"; |
| 922 | unsigned RuntimeVersion = 2; |
| 923 | StringRef SplitDebugFilename = "another/file"; |
| 924 | unsigned EmissionKind = 3; |
| 925 | Metadata *EnumTypes = MDTuple::getDistinct(Context, None); |
| 926 | Metadata *RetainedTypes = MDTuple::getDistinct(Context, None); |
| 927 | Metadata *Subprograms = MDTuple::getDistinct(Context, None); |
| 928 | Metadata *GlobalVariables = MDTuple::getDistinct(Context, None); |
| 929 | Metadata *ImportedEntities = MDTuple::getDistinct(Context, None); |
| 930 | auto *N = MDCompileUnit::get( |
| 931 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 932 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 933 | RetainedTypes, Subprograms, GlobalVariables, ImportedEntities); |
| 934 | |
| 935 | EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag()); |
| 936 | EXPECT_EQ(SourceLanguage, N->getSourceLanguage()); |
| 937 | EXPECT_EQ(File, N->getFile()); |
| 938 | EXPECT_EQ(Producer, N->getProducer()); |
| 939 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
| 940 | EXPECT_EQ(Flags, N->getFlags()); |
| 941 | EXPECT_EQ(RuntimeVersion, N->getRuntimeVersion()); |
| 942 | EXPECT_EQ(SplitDebugFilename, N->getSplitDebugFilename()); |
| 943 | EXPECT_EQ(EmissionKind, N->getEmissionKind()); |
| 944 | EXPECT_EQ(EnumTypes, N->getEnumTypes()); |
| 945 | EXPECT_EQ(RetainedTypes, N->getRetainedTypes()); |
| 946 | EXPECT_EQ(Subprograms, N->getSubprograms()); |
| 947 | EXPECT_EQ(GlobalVariables, N->getGlobalVariables()); |
| 948 | EXPECT_EQ(ImportedEntities, N->getImportedEntities()); |
| 949 | EXPECT_EQ(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 950 | IsOptimized, Flags, RuntimeVersion, |
| 951 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 952 | RetainedTypes, Subprograms, GlobalVariables, |
| 953 | ImportedEntities)); |
| 954 | |
| 955 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage + 1, File, Producer, |
| 956 | IsOptimized, Flags, RuntimeVersion, |
| 957 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 958 | RetainedTypes, Subprograms, GlobalVariables, |
| 959 | ImportedEntities)); |
| 960 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, EnumTypes, Producer, |
| 961 | IsOptimized, Flags, RuntimeVersion, |
| 962 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 963 | RetainedTypes, Subprograms, GlobalVariables, |
| 964 | ImportedEntities)); |
| 965 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, "other", |
| 966 | IsOptimized, Flags, RuntimeVersion, |
| 967 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 968 | RetainedTypes, Subprograms, GlobalVariables, |
| 969 | ImportedEntities)); |
| 970 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 971 | !IsOptimized, Flags, RuntimeVersion, |
| 972 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 973 | RetainedTypes, Subprograms, GlobalVariables, |
| 974 | ImportedEntities)); |
| 975 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 976 | IsOptimized, "other", RuntimeVersion, |
| 977 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 978 | RetainedTypes, Subprograms, GlobalVariables, |
| 979 | ImportedEntities)); |
| 980 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 981 | IsOptimized, Flags, RuntimeVersion + 1, |
| 982 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 983 | RetainedTypes, Subprograms, GlobalVariables, |
| 984 | ImportedEntities)); |
| 985 | EXPECT_NE(N, |
| 986 | MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 987 | IsOptimized, Flags, RuntimeVersion, "other", |
| 988 | EmissionKind, EnumTypes, RetainedTypes, |
| 989 | Subprograms, GlobalVariables, ImportedEntities)); |
| 990 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 991 | IsOptimized, Flags, RuntimeVersion, |
| 992 | SplitDebugFilename, EmissionKind + 1, |
| 993 | EnumTypes, RetainedTypes, Subprograms, |
| 994 | GlobalVariables, ImportedEntities)); |
| 995 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 996 | IsOptimized, Flags, RuntimeVersion, |
| 997 | SplitDebugFilename, EmissionKind, File, |
| 998 | RetainedTypes, Subprograms, GlobalVariables, |
| 999 | ImportedEntities)); |
| 1000 | EXPECT_NE(N, MDCompileUnit::get( |
| 1001 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1002 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1003 | File, Subprograms, GlobalVariables, ImportedEntities)); |
| 1004 | EXPECT_NE(N, MDCompileUnit::get( |
| 1005 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1006 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1007 | RetainedTypes, File, GlobalVariables, ImportedEntities)); |
| 1008 | EXPECT_NE(N, MDCompileUnit::get( |
| 1009 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1010 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1011 | RetainedTypes, Subprograms, File, ImportedEntities)); |
| 1012 | EXPECT_NE(N, MDCompileUnit::get( |
| 1013 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1014 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1015 | RetainedTypes, Subprograms, GlobalVariables, File)); |
| 1016 | } |
| 1017 | |
| 1018 | typedef MetadataTest MDSubprogramTest; |
| 1019 | |
| 1020 | TEST_F(MDSubprogramTest, get) { |
| 1021 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1022 | StringRef Name = "name"; |
| 1023 | StringRef LinkageName = "linkage"; |
| 1024 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1025 | unsigned Line = 2; |
| 1026 | Metadata *Type = MDTuple::getDistinct(Context, None); |
| 1027 | bool IsLocalToUnit = false; |
| 1028 | bool IsDefinition = true; |
| 1029 | unsigned ScopeLine = 3; |
| 1030 | Metadata *ContainingType = MDTuple::getDistinct(Context, None); |
| 1031 | unsigned Virtuality = 4; |
| 1032 | unsigned VirtualIndex = 5; |
| 1033 | unsigned Flags = 6; |
| 1034 | bool IsOptimized = false; |
| 1035 | Metadata *Function = MDTuple::getDistinct(Context, None); |
| 1036 | Metadata *TemplateParams = MDTuple::getDistinct(Context, None); |
| 1037 | Metadata *Declaration = MDTuple::getDistinct(Context, None); |
| 1038 | Metadata *Variables = MDTuple::getDistinct(Context, None); |
| 1039 | |
| 1040 | auto *N = MDSubprogram::get( |
| 1041 | Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 1042 | IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, |
| 1043 | IsOptimized, Function, TemplateParams, Declaration, Variables); |
| 1044 | |
| 1045 | EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag()); |
| 1046 | EXPECT_EQ(Scope, N->getScope()); |
| 1047 | EXPECT_EQ(Name, N->getName()); |
| 1048 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 1049 | EXPECT_EQ(File, N->getFile()); |
| 1050 | EXPECT_EQ(Line, N->getLine()); |
| 1051 | EXPECT_EQ(Type, N->getType()); |
| 1052 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 1053 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
| 1054 | EXPECT_EQ(ScopeLine, N->getScopeLine()); |
| 1055 | EXPECT_EQ(ContainingType, N->getContainingType()); |
| 1056 | EXPECT_EQ(Virtuality, N->getVirtuality()); |
| 1057 | EXPECT_EQ(VirtualIndex, N->getVirtualIndex()); |
| 1058 | EXPECT_EQ(Flags, N->getFlags()); |
| 1059 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
| 1060 | EXPECT_EQ(Function, N->getFunction()); |
| 1061 | EXPECT_EQ(TemplateParams, N->getTemplateParams()); |
| 1062 | EXPECT_EQ(Declaration, N->getDeclaration()); |
| 1063 | EXPECT_EQ(Variables, N->getVariables()); |
| 1064 | EXPECT_EQ(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1065 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1066 | ContainingType, Virtuality, VirtualIndex, |
| 1067 | Flags, IsOptimized, Function, TemplateParams, |
| 1068 | Declaration, Variables)); |
| 1069 | |
| 1070 | EXPECT_NE(N, MDSubprogram::get(Context, File, Name, LinkageName, File, Line, |
| 1071 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1072 | ContainingType, Virtuality, VirtualIndex, |
| 1073 | Flags, IsOptimized, Function, TemplateParams, |
| 1074 | Declaration, Variables)); |
| 1075 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, "other", LinkageName, File, |
| 1076 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1077 | ScopeLine, ContainingType, Virtuality, |
| 1078 | VirtualIndex, Flags, IsOptimized, Function, |
| 1079 | TemplateParams, Declaration, Variables)); |
| 1080 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, "other", File, Line, |
| 1081 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1082 | ContainingType, Virtuality, VirtualIndex, |
| 1083 | Flags, IsOptimized, Function, TemplateParams, |
| 1084 | Declaration, Variables)); |
| 1085 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, Scope, Line, |
| 1086 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1087 | ContainingType, Virtuality, VirtualIndex, |
| 1088 | Flags, IsOptimized, Function, TemplateParams, |
| 1089 | Declaration, Variables)); |
| 1090 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, |
| 1091 | Line + 1, Type, IsLocalToUnit, IsDefinition, |
| 1092 | ScopeLine, ContainingType, Virtuality, |
| 1093 | VirtualIndex, Flags, IsOptimized, Function, |
| 1094 | TemplateParams, Declaration, Variables)); |
| 1095 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1096 | Scope, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1097 | ContainingType, Virtuality, VirtualIndex, |
| 1098 | Flags, IsOptimized, Function, TemplateParams, |
| 1099 | Declaration, Variables)); |
| 1100 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1101 | Type, !IsLocalToUnit, IsDefinition, ScopeLine, |
| 1102 | ContainingType, Virtuality, VirtualIndex, |
| 1103 | Flags, IsOptimized, Function, TemplateParams, |
| 1104 | Declaration, Variables)); |
| 1105 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1106 | Type, IsLocalToUnit, !IsDefinition, ScopeLine, |
| 1107 | ContainingType, Virtuality, VirtualIndex, |
| 1108 | Flags, IsOptimized, Function, TemplateParams, |
| 1109 | Declaration, Variables)); |
| 1110 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1111 | Type, IsLocalToUnit, IsDefinition, |
| 1112 | ScopeLine + 1, ContainingType, Virtuality, |
| 1113 | VirtualIndex, Flags, IsOptimized, Function, |
| 1114 | TemplateParams, Declaration, Variables)); |
| 1115 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1116 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1117 | Type, Virtuality, VirtualIndex, Flags, |
| 1118 | IsOptimized, Function, TemplateParams, |
| 1119 | Declaration, Variables)); |
| 1120 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1121 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1122 | ContainingType, Virtuality + 1, VirtualIndex, |
| 1123 | Flags, IsOptimized, Function, TemplateParams, |
| 1124 | Declaration, Variables)); |
| 1125 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1126 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1127 | ContainingType, Virtuality, VirtualIndex + 1, |
| 1128 | Flags, IsOptimized, Function, TemplateParams, |
| 1129 | Declaration, Variables)); |
| 1130 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1131 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1132 | ContainingType, Virtuality, VirtualIndex, |
| 1133 | ~Flags, IsOptimized, Function, TemplateParams, |
| 1134 | Declaration, Variables)); |
| 1135 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1136 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1137 | ContainingType, Virtuality, VirtualIndex, |
| 1138 | Flags, !IsOptimized, Function, TemplateParams, |
| 1139 | Declaration, Variables)); |
| 1140 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1141 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1142 | ContainingType, Virtuality, VirtualIndex, |
| 1143 | Flags, IsOptimized, Type, TemplateParams, |
| 1144 | Declaration, Variables)); |
| 1145 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1146 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1147 | ContainingType, Virtuality, VirtualIndex, |
| 1148 | Flags, IsOptimized, Function, Type, |
| 1149 | Declaration, Variables)); |
| 1150 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1151 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1152 | ContainingType, Virtuality, VirtualIndex, |
| 1153 | Flags, IsOptimized, Function, TemplateParams, |
| 1154 | Type, Variables)); |
| 1155 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1156 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1157 | ContainingType, Virtuality, VirtualIndex, |
| 1158 | Flags, IsOptimized, Function, TemplateParams, |
| 1159 | Declaration, Type)); |
| 1160 | } |
| 1161 | |
| 1162 | typedef MetadataTest MDLexicalBlockTest; |
| 1163 | |
| 1164 | TEST_F(MDLexicalBlockTest, get) { |
| 1165 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1166 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1167 | unsigned Line = 5; |
| 1168 | unsigned Column = 8; |
| 1169 | |
| 1170 | auto *N = MDLexicalBlock::get(Context, Scope, File, Line, Column); |
| 1171 | |
| 1172 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 1173 | EXPECT_EQ(Scope, N->getScope()); |
| 1174 | EXPECT_EQ(File, N->getFile()); |
| 1175 | EXPECT_EQ(Line, N->getLine()); |
| 1176 | EXPECT_EQ(Column, N->getColumn()); |
| 1177 | EXPECT_EQ(N, MDLexicalBlock::get(Context, Scope, File, Line, Column)); |
| 1178 | |
| 1179 | EXPECT_NE(N, MDLexicalBlock::get(Context, File, File, Line, Column)); |
| 1180 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, Scope, Line, Column)); |
| 1181 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line + 1, Column)); |
| 1182 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line, Column + 1)); |
| 1183 | } |
| 1184 | |
| 1185 | typedef MetadataTest MDLexicalBlockFileTest; |
| 1186 | |
| 1187 | TEST_F(MDLexicalBlockFileTest, get) { |
| 1188 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1189 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1190 | unsigned Discriminator = 5; |
| 1191 | |
| 1192 | auto *N = MDLexicalBlockFile::get(Context, Scope, File, Discriminator); |
| 1193 | |
| 1194 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 1195 | EXPECT_EQ(Scope, N->getScope()); |
| 1196 | EXPECT_EQ(File, N->getFile()); |
| 1197 | EXPECT_EQ(Discriminator, N->getDiscriminator()); |
| 1198 | EXPECT_EQ(N, MDLexicalBlockFile::get(Context, Scope, File, Discriminator)); |
| 1199 | |
| 1200 | EXPECT_NE(N, MDLexicalBlockFile::get(Context, File, File, Discriminator)); |
| 1201 | EXPECT_NE(N, MDLexicalBlockFile::get(Context, Scope, Scope, Discriminator)); |
| 1202 | EXPECT_NE(N, |
| 1203 | MDLexicalBlockFile::get(Context, Scope, File, Discriminator + 1)); |
| 1204 | } |
| 1205 | |
| 1206 | typedef MetadataTest MDNamespaceTest; |
| 1207 | |
| 1208 | TEST_F(MDNamespaceTest, get) { |
| 1209 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1210 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1211 | StringRef Name = "namespace"; |
| 1212 | unsigned Line = 5; |
| 1213 | |
| 1214 | auto *N = MDNamespace::get(Context, Scope, File, Name, Line); |
| 1215 | |
| 1216 | EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag()); |
| 1217 | EXPECT_EQ(Scope, N->getScope()); |
| 1218 | EXPECT_EQ(File, N->getFile()); |
| 1219 | EXPECT_EQ(Name, N->getName()); |
| 1220 | EXPECT_EQ(Line, N->getLine()); |
| 1221 | EXPECT_EQ(N, MDNamespace::get(Context, Scope, File, Name, Line)); |
| 1222 | |
| 1223 | EXPECT_NE(N, MDNamespace::get(Context, File, File, Name, Line)); |
| 1224 | EXPECT_NE(N, MDNamespace::get(Context, Scope, Scope, Name, Line)); |
| 1225 | EXPECT_NE(N, MDNamespace::get(Context, Scope, File, "other", Line)); |
| 1226 | EXPECT_NE(N, MDNamespace::get(Context, Scope, File, Name, Line + 1)); |
| 1227 | } |
| 1228 | |
| 1229 | typedef MetadataTest MDTemplateTypeParameterTest; |
| 1230 | |
| 1231 | TEST_F(MDTemplateTypeParameterTest, get) { |
| 1232 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1233 | StringRef Name = "template"; |
| 1234 | Metadata *Type = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1235 | |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1236 | auto *N = MDTemplateTypeParameter::get(Context, Scope, Name, Type); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1237 | |
| 1238 | EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag()); |
| 1239 | EXPECT_EQ(Scope, N->getScope()); |
| 1240 | EXPECT_EQ(Name, N->getName()); |
| 1241 | EXPECT_EQ(Type, N->getType()); |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1242 | EXPECT_EQ(N, MDTemplateTypeParameter::get(Context, Scope, Name, Type)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1243 | |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1244 | EXPECT_NE(N, MDTemplateTypeParameter::get(Context, Type, Name, Type)); |
| 1245 | EXPECT_NE(N, MDTemplateTypeParameter::get(Context, Scope, "other", Type)); |
| 1246 | EXPECT_NE(N, MDTemplateTypeParameter::get(Context, Scope, Name, Scope)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | typedef MetadataTest MDTemplateValueParameterTest; |
| 1250 | |
| 1251 | TEST_F(MDTemplateValueParameterTest, get) { |
| 1252 | unsigned Tag = dwarf::DW_TAG_template_value_parameter; |
| 1253 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1254 | StringRef Name = "template"; |
| 1255 | Metadata *Type = MDTuple::getDistinct(Context, None); |
| 1256 | Metadata *Value = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1257 | |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1258 | auto *N = |
| 1259 | MDTemplateValueParameter::get(Context, Tag, Scope, Name, Type, Value); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1260 | EXPECT_EQ(Tag, N->getTag()); |
| 1261 | EXPECT_EQ(Scope, N->getScope()); |
| 1262 | EXPECT_EQ(Name, N->getName()); |
| 1263 | EXPECT_EQ(Type, N->getType()); |
| 1264 | EXPECT_EQ(Value, N->getValue()); |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1265 | EXPECT_EQ( |
| 1266 | N, MDTemplateValueParameter::get(Context, Tag, Scope, Name, Type, Value)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1267 | |
| 1268 | EXPECT_NE(N, MDTemplateValueParameter::get( |
| 1269 | Context, dwarf::DW_TAG_GNU_template_template_param, Scope, |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1270 | Name, Type, Value)); |
| 1271 | EXPECT_NE( |
| 1272 | N, MDTemplateValueParameter::get(Context, Tag, Type, Name, Type, Value)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1273 | EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Scope, "other", Type, |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1274 | Value)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1275 | EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Scope, Name, Scope, |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1276 | Value)); |
| 1277 | EXPECT_NE( |
| 1278 | N, MDTemplateValueParameter::get(Context, Tag, Scope, Name, Type, Scope)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | typedef MetadataTest MDGlobalVariableTest; |
| 1282 | |
| 1283 | TEST_F(MDGlobalVariableTest, get) { |
| 1284 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1285 | StringRef Name = "name"; |
| 1286 | StringRef LinkageName = "linkage"; |
| 1287 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1288 | unsigned Line = 5; |
| 1289 | Metadata *Type = MDTuple::getDistinct(Context, None); |
| 1290 | bool IsLocalToUnit = false; |
| 1291 | bool IsDefinition = true; |
| 1292 | Metadata *Variable = MDTuple::getDistinct(Context, None); |
| 1293 | Metadata *StaticDataMemberDeclaration = MDTuple::getDistinct(Context, None); |
| 1294 | |
| 1295 | auto *N = MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, |
| 1296 | Type, IsLocalToUnit, IsDefinition, Variable, |
| 1297 | StaticDataMemberDeclaration); |
| 1298 | EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag()); |
| 1299 | EXPECT_EQ(Scope, N->getScope()); |
| 1300 | EXPECT_EQ(Name, N->getName()); |
| 1301 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 1302 | EXPECT_EQ(File, N->getFile()); |
| 1303 | EXPECT_EQ(Line, N->getLine()); |
| 1304 | EXPECT_EQ(Type, N->getType()); |
| 1305 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 1306 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
| 1307 | EXPECT_EQ(Variable, N->getVariable()); |
| 1308 | EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration()); |
| 1309 | EXPECT_EQ(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1310 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1311 | Variable, StaticDataMemberDeclaration)); |
| 1312 | |
| 1313 | EXPECT_NE(N, MDGlobalVariable::get(Context, File, Name, LinkageName, File, |
| 1314 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1315 | Variable, StaticDataMemberDeclaration)); |
| 1316 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, "other", LinkageName, File, |
| 1317 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1318 | Variable, StaticDataMemberDeclaration)); |
| 1319 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, "other", File, Line, |
| 1320 | Type, IsLocalToUnit, IsDefinition, |
| 1321 | Variable, StaticDataMemberDeclaration)); |
| 1322 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, Scope, |
| 1323 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1324 | Variable, StaticDataMemberDeclaration)); |
| 1325 | EXPECT_NE(N, |
| 1326 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1327 | Line + 1, Type, IsLocalToUnit, IsDefinition, |
| 1328 | Variable, StaticDataMemberDeclaration)); |
| 1329 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1330 | Line, Scope, IsLocalToUnit, IsDefinition, |
| 1331 | Variable, StaticDataMemberDeclaration)); |
| 1332 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1333 | Line, Type, !IsLocalToUnit, IsDefinition, |
| 1334 | Variable, StaticDataMemberDeclaration)); |
| 1335 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1336 | Line, Type, IsLocalToUnit, !IsDefinition, |
| 1337 | Variable, StaticDataMemberDeclaration)); |
| 1338 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1339 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1340 | Type, StaticDataMemberDeclaration)); |
| 1341 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1342 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1343 | Variable, Type)); |
| 1344 | } |
| 1345 | |
| 1346 | typedef MetadataTest MDLocalVariableTest; |
| 1347 | |
| 1348 | TEST_F(MDLocalVariableTest, get) { |
| 1349 | unsigned Tag = dwarf::DW_TAG_arg_variable; |
| 1350 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1351 | StringRef Name = "name"; |
| 1352 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1353 | unsigned Line = 5; |
| 1354 | Metadata *Type = MDTuple::getDistinct(Context, None); |
| 1355 | unsigned Arg = 6; |
| 1356 | unsigned Flags = 7; |
| 1357 | Metadata *InlinedAt = MDTuple::getDistinct(Context, None); |
| 1358 | |
| 1359 | auto *N = MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1360 | Arg, Flags, InlinedAt); |
| 1361 | EXPECT_EQ(Tag, N->getTag()); |
| 1362 | EXPECT_EQ(Scope, N->getScope()); |
| 1363 | EXPECT_EQ(Name, N->getName()); |
| 1364 | EXPECT_EQ(File, N->getFile()); |
| 1365 | EXPECT_EQ(Line, N->getLine()); |
| 1366 | EXPECT_EQ(Type, N->getType()); |
| 1367 | EXPECT_EQ(Arg, N->getArg()); |
| 1368 | EXPECT_EQ(Flags, N->getFlags()); |
| 1369 | EXPECT_EQ(InlinedAt, N->getInlinedAt()); |
| 1370 | EXPECT_EQ(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1371 | Arg, Flags, InlinedAt)); |
| 1372 | |
| 1373 | EXPECT_NE(N, MDLocalVariable::get(Context, dwarf::DW_TAG_auto_variable, Scope, |
| 1374 | Name, File, Line, Type, Arg, Flags, |
| 1375 | InlinedAt)); |
| 1376 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, File, Name, File, Line, |
| 1377 | Type, Arg, Flags, InlinedAt)); |
| 1378 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, "other", File, Line, |
| 1379 | Type, Arg, Flags, InlinedAt)); |
| 1380 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, Scope, Line, |
| 1381 | Type, Arg, Flags, InlinedAt)); |
| 1382 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line + 1, |
| 1383 | Type, Arg, Flags, InlinedAt)); |
| 1384 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, |
| 1385 | Scope, Arg, Flags, InlinedAt)); |
| 1386 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1387 | Arg + 1, Flags, InlinedAt)); |
| 1388 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1389 | Arg, ~Flags, InlinedAt)); |
| 1390 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1391 | Arg, Flags, Scope)); |
| 1392 | } |
| 1393 | |
| 1394 | typedef MetadataTest MDExpressionTest; |
| 1395 | |
| 1396 | TEST_F(MDExpressionTest, get) { |
| 1397 | uint64_t Elements[] = {2, 6, 9, 78, 0}; |
| 1398 | auto *N = MDExpression::get(Context, Elements); |
| 1399 | EXPECT_EQ(makeArrayRef(Elements), N->getElements()); |
| 1400 | EXPECT_EQ(N, MDExpression::get(Context, Elements)); |
Duncan P. N. Exon Smith | dddc537 | 2015-02-10 01:36:46 +0000 | [diff] [blame] | 1401 | |
| 1402 | EXPECT_EQ(5u, N->getNumElements()); |
| 1403 | EXPECT_EQ(2u, N->getElement(0)); |
| 1404 | EXPECT_EQ(6u, N->getElement(1)); |
| 1405 | EXPECT_EQ(9u, N->getElement(2)); |
| 1406 | EXPECT_EQ(78u, N->getElement(3)); |
| 1407 | EXPECT_EQ(0u, N->getElement(4)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | typedef MetadataTest MDObjCPropertyTest; |
| 1411 | |
| 1412 | TEST_F(MDObjCPropertyTest, get) { |
| 1413 | StringRef Name = "name"; |
| 1414 | Metadata *File = MDTuple::getDistinct(Context, None); |
| 1415 | unsigned Line = 5; |
| 1416 | StringRef GetterName = "getter"; |
| 1417 | StringRef SetterName = "setter"; |
| 1418 | unsigned Attributes = 7; |
| 1419 | Metadata *Type = MDTuple::getDistinct(Context, None); |
| 1420 | |
| 1421 | auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1422 | SetterName, Attributes, Type); |
| 1423 | |
| 1424 | EXPECT_EQ(dwarf::DW_TAG_APPLE_property, N->getTag()); |
| 1425 | EXPECT_EQ(Name, N->getName()); |
| 1426 | EXPECT_EQ(File, N->getFile()); |
| 1427 | EXPECT_EQ(Line, N->getLine()); |
| 1428 | EXPECT_EQ(GetterName, N->getGetterName()); |
| 1429 | EXPECT_EQ(SetterName, N->getSetterName()); |
| 1430 | EXPECT_EQ(Attributes, N->getAttributes()); |
| 1431 | EXPECT_EQ(Type, N->getType()); |
| 1432 | EXPECT_EQ(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1433 | SetterName, Attributes, Type)); |
| 1434 | |
| 1435 | EXPECT_NE(N, MDObjCProperty::get(Context, "other", File, Line, GetterName, |
| 1436 | SetterName, Attributes, Type)); |
| 1437 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, Type, Line, GetterName, |
| 1438 | SetterName, Attributes, Type)); |
| 1439 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line + 1, GetterName, |
| 1440 | SetterName, Attributes, Type)); |
| 1441 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, "other", |
| 1442 | SetterName, Attributes, Type)); |
| 1443 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1444 | "other", Attributes, Type)); |
| 1445 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1446 | SetterName, Attributes + 1, Type)); |
| 1447 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1448 | SetterName, Attributes, File)); |
| 1449 | } |
| 1450 | |
| 1451 | typedef MetadataTest MDImportedEntityTest; |
| 1452 | |
| 1453 | TEST_F(MDImportedEntityTest, get) { |
| 1454 | unsigned Tag = dwarf::DW_TAG_imported_module; |
| 1455 | Metadata *Scope = MDTuple::getDistinct(Context, None); |
| 1456 | Metadata *Entity = MDTuple::getDistinct(Context, None); |
| 1457 | unsigned Line = 5; |
| 1458 | StringRef Name = "name"; |
| 1459 | |
| 1460 | auto *N = MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name); |
| 1461 | |
| 1462 | EXPECT_EQ(Tag, N->getTag()); |
| 1463 | EXPECT_EQ(Scope, N->getScope()); |
| 1464 | EXPECT_EQ(Entity, N->getEntity()); |
| 1465 | EXPECT_EQ(Line, N->getLine()); |
| 1466 | EXPECT_EQ(Name, N->getName()); |
| 1467 | EXPECT_EQ(N, MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name)); |
| 1468 | |
| 1469 | EXPECT_NE(N, |
| 1470 | MDImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration, |
| 1471 | Scope, Entity, Line, Name)); |
| 1472 | EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Entity, Entity, Line, Name)); |
| 1473 | EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, Scope, Line, Name)); |
| 1474 | EXPECT_NE(N, |
| 1475 | MDImportedEntity::get(Context, Tag, Scope, Entity, Line + 1, Name)); |
| 1476 | EXPECT_NE(N, |
| 1477 | MDImportedEntity::get(Context, Tag, Scope, Entity, Line, "other")); |
| 1478 | } |
| 1479 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1480 | typedef MetadataTest MetadataAsValueTest; |
| 1481 | |
| 1482 | TEST_F(MetadataAsValueTest, MDNode) { |
| 1483 | MDNode *N = MDNode::get(Context, None); |
| 1484 | auto *V = MetadataAsValue::get(Context, N); |
| 1485 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 1486 | EXPECT_EQ(N, V->getMetadata()); |
| 1487 | |
| 1488 | auto *V2 = MetadataAsValue::get(Context, N); |
| 1489 | EXPECT_EQ(V, V2); |
| 1490 | } |
| 1491 | |
| 1492 | TEST_F(MetadataAsValueTest, MDNodeMDNode) { |
| 1493 | MDNode *N = MDNode::get(Context, None); |
| 1494 | Metadata *Ops[] = {N}; |
| 1495 | MDNode *N2 = MDNode::get(Context, Ops); |
| 1496 | auto *V = MetadataAsValue::get(Context, N2); |
| 1497 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 1498 | EXPECT_EQ(N2, V->getMetadata()); |
| 1499 | |
| 1500 | auto *V2 = MetadataAsValue::get(Context, N2); |
| 1501 | EXPECT_EQ(V, V2); |
| 1502 | |
| 1503 | auto *V3 = MetadataAsValue::get(Context, N); |
| 1504 | EXPECT_TRUE(V3->getType()->isMetadataTy()); |
| 1505 | EXPECT_NE(V, V3); |
| 1506 | EXPECT_EQ(N, V3->getMetadata()); |
| 1507 | } |
| 1508 | |
| 1509 | TEST_F(MetadataAsValueTest, MDNodeConstant) { |
| 1510 | auto *C = ConstantInt::getTrue(Context); |
| 1511 | auto *MD = ConstantAsMetadata::get(C); |
| 1512 | Metadata *Ops[] = {MD}; |
| 1513 | auto *N = MDNode::get(Context, Ops); |
| 1514 | |
| 1515 | auto *V = MetadataAsValue::get(Context, MD); |
| 1516 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 1517 | EXPECT_EQ(MD, V->getMetadata()); |
| 1518 | |
| 1519 | auto *V2 = MetadataAsValue::get(Context, N); |
| 1520 | EXPECT_EQ(MD, V2->getMetadata()); |
| 1521 | EXPECT_EQ(V, V2); |
| 1522 | } |
| 1523 | |
Duncan P. N. Exon Smith | 121eeff | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 1524 | typedef MetadataTest ValueAsMetadataTest; |
| 1525 | |
| 1526 | TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) { |
| 1527 | Type *Ty = Type::getInt1PtrTy(Context); |
| 1528 | std::unique_ptr<GlobalVariable> GV0( |
| 1529 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 1530 | auto *MD = ValueAsMetadata::get(GV0.get()); |
| 1531 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 1532 | ASSERT_TRUE(GV0->use_empty()); |
| 1533 | |
| 1534 | std::unique_ptr<GlobalVariable> GV1( |
| 1535 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 1536 | GV0->replaceAllUsesWith(GV1.get()); |
| 1537 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 1538 | } |
| 1539 | |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 1540 | TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) { |
| 1541 | // Create a constant. |
| 1542 | ConstantAsMetadata *CI = ConstantAsMetadata::get( |
| 1543 | ConstantInt::get(getGlobalContext(), APInt(8, 0))); |
| 1544 | |
| 1545 | // Create a temporary to prevent nodes from resolving. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 1546 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 1547 | |
| 1548 | // When the first operand of N1 gets reset to nullptr, it'll collide with N2. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 1549 | Metadata *Ops1[] = {CI, CI, Temp.get()}; |
| 1550 | Metadata *Ops2[] = {nullptr, CI, Temp.get()}; |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 1551 | |
| 1552 | auto *N1 = MDTuple::get(Context, Ops1); |
| 1553 | auto *N2 = MDTuple::get(Context, Ops2); |
| 1554 | ASSERT_NE(N1, N2); |
| 1555 | |
| 1556 | // Tell metadata that the constant is getting deleted. |
| 1557 | // |
| 1558 | // After this, N1 will be invalid, so don't touch it. |
| 1559 | ValueAsMetadata::handleDeletion(CI->getValue()); |
| 1560 | EXPECT_EQ(nullptr, N2->getOperand(0)); |
| 1561 | EXPECT_EQ(nullptr, N2->getOperand(1)); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 1562 | EXPECT_EQ(Temp.get(), N2->getOperand(2)); |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Clean up Temp for teardown. |
| 1565 | Temp->replaceAllUsesWith(nullptr); |
| 1566 | } |
| 1567 | |
Duncan P. N. Exon Smith | 121eeff | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 1568 | typedef MetadataTest TrackingMDRefTest; |
| 1569 | |
| 1570 | TEST_F(TrackingMDRefTest, UpdatesOnRAUW) { |
| 1571 | Type *Ty = Type::getInt1PtrTy(Context); |
| 1572 | std::unique_ptr<GlobalVariable> GV0( |
| 1573 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 1574 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV0.get())); |
| 1575 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 1576 | ASSERT_TRUE(GV0->use_empty()); |
| 1577 | |
| 1578 | std::unique_ptr<GlobalVariable> GV1( |
| 1579 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 1580 | GV0->replaceAllUsesWith(GV1.get()); |
| 1581 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 1582 | |
| 1583 | // Reset it, so we don't inadvertently test deletion. |
| 1584 | MD.reset(); |
| 1585 | } |
| 1586 | |
| 1587 | TEST_F(TrackingMDRefTest, UpdatesOnDeletion) { |
| 1588 | Type *Ty = Type::getInt1PtrTy(Context); |
| 1589 | std::unique_ptr<GlobalVariable> GV( |
| 1590 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 1591 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV.get())); |
| 1592 | EXPECT_TRUE(MD->getValue() == GV.get()); |
| 1593 | ASSERT_TRUE(GV->use_empty()); |
| 1594 | |
| 1595 | GV.reset(); |
| 1596 | EXPECT_TRUE(!MD); |
| 1597 | } |
| 1598 | |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1599 | TEST(NamedMDNodeTest, Search) { |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 1600 | LLVMContext Context; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1601 | ConstantAsMetadata *C = |
| 1602 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 1)); |
| 1603 | ConstantAsMetadata *C2 = |
| 1604 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 2)); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1605 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1606 | Metadata *const V = C; |
| 1607 | Metadata *const V2 = C2; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 1608 | MDNode *n = MDNode::get(Context, V); |
| 1609 | MDNode *n2 = MDNode::get(Context, V2); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1610 | |
Jeffrey Yasskin | 3d73d1a | 2010-03-13 01:39:20 +0000 | [diff] [blame] | 1611 | Module M("MyModule", Context); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1612 | const char *Name = "llvm.NMD1"; |
Dan Gohman | 2637cc1 | 2010-07-21 23:38:33 +0000 | [diff] [blame] | 1613 | NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name); |
| 1614 | NMD->addOperand(n); |
| 1615 | NMD->addOperand(n2); |
| 1616 | |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 1617 | std::string Str; |
| 1618 | raw_string_ostream oss(Str); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1619 | NMD->print(oss); |
Chris Lattner | 1e6e367 | 2009-12-31 02:12:13 +0000 | [diff] [blame] | 1620 | EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n", |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 1621 | oss.str().c_str()); |
| 1622 | } |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 1623 | } |