blob: 6662bd1a2c4d6c009d15037e65af50ef5189f26a [file] [log] [blame]
Duncan P. N. Exon Smith71db6422015-02-02 18:20:15 +00001//===- unittests/IR/MetadataTest.cpp - Metadata unit tests ----------------===//
Nick Lewycky49f89192009-04-04 07:22:01 +00002//
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 Smith845755c42015-01-13 00:46:34 +000010#include "llvm/ADT/STLExtras.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000011#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +000012#include "llvm/IR/DebugInfo.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000013#include "llvm/IR/DebugInfoMetadata.h"
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +000014#include "llvm/IR/Function.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000015#include "llvm/IR/Instructions.h"
16#include "llvm/IR/LLVMContext.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/IR/Metadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/Module.h"
19#include "llvm/IR/Type.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000020#include "llvm/Support/raw_ostream.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000021#include "gtest/gtest.h"
Nick Lewycky49f89192009-04-04 07:22:01 +000022using namespace llvm;
23
24namespace {
25
Duncan P. N. Exon Smith2711ca72015-01-19 19:02:06 +000026TEST(ContextAndReplaceableUsesTest, FromContext) {
27 LLVMContext Context;
28 ContextAndReplaceableUses CRU(Context);
29 EXPECT_EQ(&Context, &CRU.getContext());
30 EXPECT_FALSE(CRU.hasReplaceableUses());
31 EXPECT_FALSE(CRU.getReplaceableUses());
32}
33
34TEST(ContextAndReplaceableUsesTest, FromReplaceableUses) {
35 LLVMContext Context;
36 ContextAndReplaceableUses CRU(make_unique<ReplaceableMetadataImpl>(Context));
37 EXPECT_EQ(&Context, &CRU.getContext());
38 EXPECT_TRUE(CRU.hasReplaceableUses());
39 EXPECT_TRUE(CRU.getReplaceableUses());
40}
41
42TEST(ContextAndReplaceableUsesTest, makeReplaceable) {
43 LLVMContext Context;
44 ContextAndReplaceableUses CRU(Context);
45 CRU.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
46 EXPECT_EQ(&Context, &CRU.getContext());
47 EXPECT_TRUE(CRU.hasReplaceableUses());
48 EXPECT_TRUE(CRU.getReplaceableUses());
49}
50
51TEST(ContextAndReplaceableUsesTest, takeReplaceableUses) {
52 LLVMContext Context;
53 auto ReplaceableUses = make_unique<ReplaceableMetadataImpl>(Context);
54 auto *Ptr = ReplaceableUses.get();
55 ContextAndReplaceableUses CRU(std::move(ReplaceableUses));
56 ReplaceableUses = CRU.takeReplaceableUses();
57 EXPECT_EQ(&Context, &CRU.getContext());
58 EXPECT_FALSE(CRU.hasReplaceableUses());
59 EXPECT_FALSE(CRU.getReplaceableUses());
60 EXPECT_EQ(Ptr, ReplaceableUses.get());
61}
62
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000063class MetadataTest : public testing::Test {
64protected:
65 LLVMContext Context;
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +000066 MDNode *getNode() { return MDNode::get(Context, None); }
67 MDNode *getNode(Metadata *MD) { return MDNode::get(Context, MD); }
68 MDNode *getNode(Metadata *MD1, Metadata *MD2) {
69 Metadata *MDs[] = {MD1, MD2};
70 return MDNode::get(Context, MDs);
71 }
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000072};
73typedef MetadataTest MDStringTest;
Owen Anderson23587322009-07-31 21:38:10 +000074
Nick Lewycky49f89192009-04-04 07:22:01 +000075// Test that construction of MDString with different value produces different
76// MDString objects, even with the same string pointer and nulls in the string.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000077TEST_F(MDStringTest, CreateDifferent) {
Nick Lewycky49f89192009-04-04 07:22:01 +000078 char x[3] = { 'f', 0, 'A' };
Owen Anderson23587322009-07-31 21:38:10 +000079 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +000080 x[2] = 'B';
Owen Anderson23587322009-07-31 21:38:10 +000081 MDString *s2 = MDString::get(Context, StringRef(&x[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +000082 EXPECT_NE(s1, s2);
83}
84
85// Test that creation of MDStrings with the same string contents produces the
86// same MDString object, even with different pointers.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000087TEST_F(MDStringTest, CreateSame) {
Nick Lewycky49f89192009-04-04 07:22:01 +000088 char x[4] = { 'a', 'b', 'c', 'X' };
89 char y[4] = { 'a', 'b', 'c', 'Y' };
90
Owen Anderson23587322009-07-31 21:38:10 +000091 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
92 MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +000093 EXPECT_EQ(s1, s2);
94}
95
96// Test that MDString prints out the string we fed it.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000097TEST_F(MDStringTest, PrintingSimple) {
Nick Lewycky49f89192009-04-04 07:22:01 +000098 char *str = new char[13];
99 strncpy(str, "testing 1 2 3", 13);
Owen Anderson23587322009-07-31 21:38:10 +0000100 MDString *s = MDString::get(Context, StringRef(str, 13));
Nick Lewycky49f89192009-04-04 07:22:01 +0000101 strncpy(str, "aaaaaaaaaaaaa", 13);
102 delete[] str;
103
Chris Lattnerbe354a62009-08-23 04:47:35 +0000104 std::string Str;
105 raw_string_ostream oss(Str);
Nick Lewycky49f89192009-04-04 07:22:01 +0000106 s->print(oss);
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000107 EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str());
Nick Lewycky49f89192009-04-04 07:22:01 +0000108}
109
110// Test printing of MDString with non-printable characters.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000111TEST_F(MDStringTest, PrintingComplex) {
Jeffrey Yasskin065c3572011-08-30 20:53:29 +0000112 char str[5] = {0, '\n', '"', '\\', (char)-1};
Owen Anderson23587322009-07-31 21:38:10 +0000113 MDString *s = MDString::get(Context, StringRef(str+0, 5));
Chris Lattnerbe354a62009-08-23 04:47:35 +0000114 std::string Str;
115 raw_string_ostream oss(Str);
Nick Lewycky49f89192009-04-04 07:22:01 +0000116 s->print(oss);
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000117 EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str());
Nick Lewycky49f89192009-04-04 07:22:01 +0000118}
119
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000120typedef MetadataTest MDNodeTest;
121
Nick Lewycky49f89192009-04-04 07:22:01 +0000122// Test the two constructors, and containing other Constants.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000123TEST_F(MDNodeTest, Simple) {
Nick Lewycky49f89192009-04-04 07:22:01 +0000124 char x[3] = { 'a', 'b', 'c' };
125 char y[3] = { '1', '2', '3' };
126
Owen Anderson23587322009-07-31 21:38:10 +0000127 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
128 MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000129 ConstantAsMetadata *CI = ConstantAsMetadata::get(
130 ConstantInt::get(getGlobalContext(), APInt(8, 0)));
Nick Lewycky49f89192009-04-04 07:22:01 +0000131
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000132 std::vector<Metadata *> V;
Nick Lewycky49f89192009-04-04 07:22:01 +0000133 V.push_back(s1);
134 V.push_back(CI);
135 V.push_back(s2);
136
Jay Foad5514afe2011-04-21 19:59:31 +0000137 MDNode *n1 = MDNode::get(Context, V);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000138 Metadata *const c1 = n1;
Jay Foad5514afe2011-04-21 19:59:31 +0000139 MDNode *n2 = MDNode::get(Context, c1);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000140 Metadata *const c2 = n2;
Jay Foad5514afe2011-04-21 19:59:31 +0000141 MDNode *n3 = MDNode::get(Context, V);
Duncan Sands26a80f32012-03-31 08:20:11 +0000142 MDNode *n4 = MDNode::getIfExists(Context, V);
143 MDNode *n5 = MDNode::getIfExists(Context, c1);
144 MDNode *n6 = MDNode::getIfExists(Context, c2);
Nick Lewycky49f89192009-04-04 07:22:01 +0000145 EXPECT_NE(n1, n2);
Devang Patelf7188322009-09-03 01:39:20 +0000146 EXPECT_EQ(n1, n3);
Duncan Sands26a80f32012-03-31 08:20:11 +0000147 EXPECT_EQ(n4, n1);
148 EXPECT_EQ(n5, n2);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000149 EXPECT_EQ(n6, (Metadata *)nullptr);
Nick Lewycky49f89192009-04-04 07:22:01 +0000150
Chris Lattner9b493022009-12-31 01:22:29 +0000151 EXPECT_EQ(3u, n1->getNumOperands());
152 EXPECT_EQ(s1, n1->getOperand(0));
153 EXPECT_EQ(CI, n1->getOperand(1));
154 EXPECT_EQ(s2, n1->getOperand(2));
Nick Lewycky49f89192009-04-04 07:22:01 +0000155
Chris Lattner9b493022009-12-31 01:22:29 +0000156 EXPECT_EQ(1u, n2->getNumOperands());
157 EXPECT_EQ(n1, n2->getOperand(0));
Nick Lewycky49f89192009-04-04 07:22:01 +0000158}
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000159
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000160TEST_F(MDNodeTest, Delete) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000161 Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1);
162 Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext()));
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000163
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000164 Metadata *const V = LocalAsMetadata::get(I);
Jay Foad5514afe2011-04-21 19:59:31 +0000165 MDNode *n = MDNode::get(Context, V);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000166 TrackingMDRef wvh(n);
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000167
168 EXPECT_EQ(n, wvh);
169
170 delete I;
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000171}
Devang Patel0924b332009-07-30 00:03:41 +0000172
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000173TEST_F(MDNodeTest, SelfReference) {
Duncan P. N. Exon Smith8c662732014-12-16 07:45:05 +0000174 // !0 = !{!0}
175 // !1 = !{!0}
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000176 {
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000177 auto Temp = MDNode::getTemporary(Context, None);
178 Metadata *Args[] = {Temp.get()};
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000179 MDNode *Self = MDNode::get(Context, Args);
180 Self->replaceOperandWith(0, Self);
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000181 ASSERT_EQ(Self, Self->getOperand(0));
182
183 // Self-references should be distinct, so MDNode::get() should grab a
184 // uniqued node that references Self, not Self.
185 Args[0] = Self;
186 MDNode *Ref1 = MDNode::get(Context, Args);
187 MDNode *Ref2 = MDNode::get(Context, Args);
188 EXPECT_NE(Self, Ref1);
189 EXPECT_EQ(Ref1, Ref2);
190 }
191
Duncan P. N. Exon Smith8c662732014-12-16 07:45:05 +0000192 // !0 = !{!0, !{}}
193 // !1 = !{!0, !{}}
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000194 {
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000195 auto Temp = MDNode::getTemporary(Context, None);
196 Metadata *Args[] = {Temp.get(), MDNode::get(Context, None)};
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000197 MDNode *Self = MDNode::get(Context, Args);
198 Self->replaceOperandWith(0, Self);
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000199 ASSERT_EQ(Self, Self->getOperand(0));
200
201 // Self-references should be distinct, so MDNode::get() should grab a
202 // uniqued node that references Self, not Self itself.
203 Args[0] = Self;
204 MDNode *Ref1 = MDNode::get(Context, Args);
205 MDNode *Ref2 = MDNode::get(Context, Args);
206 EXPECT_NE(Self, Ref1);
207 EXPECT_EQ(Ref1, Ref2);
208 }
209}
210
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000211TEST_F(MDNodeTest, Print) {
212 Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7);
213 MDString *S = MDString::get(Context, "foo");
214 MDNode *N0 = getNode();
215 MDNode *N1 = getNode(N0);
216 MDNode *N2 = getNode(N0, N1);
217
218 Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2};
219 MDNode *N = MDNode::get(Context, Args);
220
221 std::string Expected;
222 {
223 raw_string_ostream OS(Expected);
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000224 OS << "!{";
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000225 C->printAsOperand(OS);
226 OS << ", ";
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000227 S->printAsOperand(OS);
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000228 OS << ", null";
229 MDNode *Nodes[] = {N0, N1, N2};
230 for (auto *Node : Nodes)
231 OS << ", <" << (void *)Node << ">";
Duncan P. N. Exon Smith738889f2015-02-25 22:46:38 +0000232 OS << "}";
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000233 }
234
235 std::string Actual;
236 {
237 raw_string_ostream OS(Actual);
238 N->print(OS);
239 }
240
241 EXPECT_EQ(Expected, Actual);
242}
243
Duncan P. N. Exon Smithbcd960a2015-01-05 23:31:54 +0000244TEST_F(MDNodeTest, NullOperand) {
245 // metadata !{}
246 MDNode *Empty = MDNode::get(Context, None);
247
248 // metadata !{metadata !{}}
249 Metadata *Ops[] = {Empty};
250 MDNode *N = MDNode::get(Context, Ops);
251 ASSERT_EQ(Empty, N->getOperand(0));
252
253 // metadata !{metadata !{}} => metadata !{null}
254 N->replaceOperandWith(0, nullptr);
255 ASSERT_EQ(nullptr, N->getOperand(0));
256
257 // metadata !{null}
258 Ops[0] = nullptr;
259 MDNode *NullOp = MDNode::get(Context, Ops);
260 ASSERT_EQ(nullptr, NullOp->getOperand(0));
261 EXPECT_EQ(N, NullOp);
262}
263
Duncan P. N. Exon Smith136ea3f2015-01-07 21:35:38 +0000264TEST_F(MDNodeTest, DistinctOnUniquingCollision) {
265 // !{}
266 MDNode *Empty = MDNode::get(Context, None);
267 ASSERT_TRUE(Empty->isResolved());
268 EXPECT_FALSE(Empty->isDistinct());
269
270 // !{!{}}
271 Metadata *Wrapped1Ops[] = {Empty};
272 MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops);
273 ASSERT_EQ(Empty, Wrapped1->getOperand(0));
274 ASSERT_TRUE(Wrapped1->isResolved());
275 EXPECT_FALSE(Wrapped1->isDistinct());
276
277 // !{!{!{}}}
278 Metadata *Wrapped2Ops[] = {Wrapped1};
279 MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops);
280 ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0));
281 ASSERT_TRUE(Wrapped2->isResolved());
282 EXPECT_FALSE(Wrapped2->isDistinct());
283
284 // !{!{!{}}} => !{!{}}
285 Wrapped2->replaceOperandWith(0, Empty);
286 ASSERT_EQ(Empty, Wrapped2->getOperand(0));
287 EXPECT_TRUE(Wrapped2->isDistinct());
288 EXPECT_FALSE(Wrapped1->isDistinct());
289}
290
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000291TEST_F(MDNodeTest, getDistinct) {
292 // !{}
293 MDNode *Empty = MDNode::get(Context, None);
294 ASSERT_TRUE(Empty->isResolved());
295 ASSERT_FALSE(Empty->isDistinct());
296 ASSERT_EQ(Empty, MDNode::get(Context, None));
297
298 // distinct !{}
299 MDNode *Distinct1 = MDNode::getDistinct(Context, None);
300 MDNode *Distinct2 = MDNode::getDistinct(Context, None);
301 EXPECT_TRUE(Distinct1->isResolved());
302 EXPECT_TRUE(Distinct2->isDistinct());
303 EXPECT_NE(Empty, Distinct1);
304 EXPECT_NE(Empty, Distinct2);
305 EXPECT_NE(Distinct1, Distinct2);
306
307 // !{}
308 ASSERT_EQ(Empty, MDNode::get(Context, None));
309}
310
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000311TEST_F(MDNodeTest, isUniqued) {
312 MDNode *U = MDTuple::get(Context, None);
313 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000314 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000315 EXPECT_TRUE(U->isUniqued());
316 EXPECT_FALSE(D->isUniqued());
317 EXPECT_FALSE(T->isUniqued());
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000318}
319
320TEST_F(MDNodeTest, isDistinct) {
321 MDNode *U = MDTuple::get(Context, None);
322 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000323 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000324 EXPECT_FALSE(U->isDistinct());
325 EXPECT_TRUE(D->isDistinct());
326 EXPECT_FALSE(T->isDistinct());
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000327}
328
329TEST_F(MDNodeTest, isTemporary) {
330 MDNode *U = MDTuple::get(Context, None);
331 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000332 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000333 EXPECT_FALSE(U->isTemporary());
334 EXPECT_FALSE(D->isTemporary());
335 EXPECT_TRUE(T->isTemporary());
Duncan P. N. Exon Smithd1474ee2015-01-12 18:41:26 +0000336}
337
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000338TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
339 // temporary !{}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000340 auto Temp = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000341 ASSERT_FALSE(Temp->isResolved());
342
343 // distinct !{temporary !{}}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000344 Metadata *Ops[] = {Temp.get()};
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000345 MDNode *Distinct = MDNode::getDistinct(Context, Ops);
346 EXPECT_TRUE(Distinct->isResolved());
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000347 EXPECT_EQ(Temp.get(), Distinct->getOperand(0));
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000348
349 // temporary !{} => !{}
350 MDNode *Empty = MDNode::get(Context, None);
351 Temp->replaceAllUsesWith(Empty);
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000352 EXPECT_EQ(Empty, Distinct->getOperand(0));
353}
354
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000355TEST_F(MDNodeTest, handleChangedOperandRecursion) {
356 // !0 = !{}
357 MDNode *N0 = MDNode::get(Context, None);
358
359 // !1 = !{!3, null}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000360 auto Temp3 = MDTuple::getTemporary(Context, None);
361 Metadata *Ops1[] = {Temp3.get(), nullptr};
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000362 MDNode *N1 = MDNode::get(Context, Ops1);
363
364 // !2 = !{!3, !0}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000365 Metadata *Ops2[] = {Temp3.get(), N0};
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000366 MDNode *N2 = MDNode::get(Context, Ops2);
367
368 // !3 = !{!2}
369 Metadata *Ops3[] = {N2};
370 MDNode *N3 = MDNode::get(Context, Ops3);
371 Temp3->replaceAllUsesWith(N3);
372
373 // !4 = !{!1}
374 Metadata *Ops4[] = {N1};
375 MDNode *N4 = MDNode::get(Context, Ops4);
376
377 // Confirm that the cycle prevented RAUW from getting dropped.
378 EXPECT_TRUE(N0->isResolved());
379 EXPECT_FALSE(N1->isResolved());
380 EXPECT_FALSE(N2->isResolved());
381 EXPECT_FALSE(N3->isResolved());
382 EXPECT_FALSE(N4->isResolved());
383
384 // Create a couple of distinct nodes to observe what's going on.
385 //
386 // !5 = distinct !{!2}
387 // !6 = distinct !{!3}
388 Metadata *Ops5[] = {N2};
389 MDNode *N5 = MDNode::getDistinct(Context, Ops5);
390 Metadata *Ops6[] = {N3};
391 MDNode *N6 = MDNode::getDistinct(Context, Ops6);
392
393 // Mutate !2 to look like !1, causing a uniquing collision (and an RAUW).
394 // This will ripple up, with !3 colliding with !4, and RAUWing. Since !2
395 // references !3, this can cause a re-entry of handleChangedOperand() when !3
396 // is not ready for it.
397 //
398 // !2->replaceOperandWith(1, nullptr)
399 // !2: !{!3, !0} => !{!3, null}
400 // !2->replaceAllUsesWith(!1)
401 // !3: !{!2] => !{!1}
402 // !3->replaceAllUsesWith(!4)
403 N2->replaceOperandWith(1, nullptr);
404
405 // If all has gone well, N2 and N3 will have been RAUW'ed and deleted from
406 // under us. Just check that the other nodes are sane.
407 //
408 // !1 = !{!4, null}
409 // !4 = !{!1}
410 // !5 = distinct !{!1}
411 // !6 = distinct !{!4}
412 EXPECT_EQ(N4, N1->getOperand(0));
413 EXPECT_EQ(N1, N4->getOperand(0));
414 EXPECT_EQ(N1, N5->getOperand(0));
415 EXPECT_EQ(N4, N6->getOperand(0));
416}
417
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000418TEST_F(MDNodeTest, replaceResolvedOperand) {
419 // Check code for replacing one resolved operand with another. If doing this
420 // directly (via replaceOperandWith()) becomes illegal, change the operand to
421 // a global value that gets RAUW'ed.
422 //
423 // Use a temporary node to keep N from being resolved.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000424 auto Temp = MDTuple::getTemporary(Context, None);
425 Metadata *Ops[] = {nullptr, Temp.get()};
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000426
NAKAMURA Takumi2f8f0542015-01-13 08:13:46 +0000427 MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>());
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000428 MDNode *N = MDTuple::get(Context, Ops);
429 EXPECT_EQ(nullptr, N->getOperand(0));
430 ASSERT_FALSE(N->isResolved());
431
432 // Check code for replacing resolved nodes.
433 N->replaceOperandWith(0, Empty);
434 EXPECT_EQ(Empty, N->getOperand(0));
435
436 // Check code for adding another unresolved operand.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000437 N->replaceOperandWith(0, Temp.get());
438 EXPECT_EQ(Temp.get(), N->getOperand(0));
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000439
440 // Remove the references to Temp; required for teardown.
441 Temp->replaceAllUsesWith(nullptr);
442}
443
Duncan P. N. Exon Smithe3353092015-01-19 22:24:52 +0000444TEST_F(MDNodeTest, replaceWithUniqued) {
445 auto *Empty = MDTuple::get(Context, None);
446 MDTuple *FirstUniqued;
447 {
448 Metadata *Ops[] = {Empty};
449 auto Temp = MDTuple::getTemporary(Context, Ops);
450 EXPECT_TRUE(Temp->isTemporary());
451
452 // Don't expect a collision.
453 auto *Current = Temp.get();
454 FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp));
455 EXPECT_TRUE(FirstUniqued->isUniqued());
456 EXPECT_TRUE(FirstUniqued->isResolved());
457 EXPECT_EQ(Current, FirstUniqued);
458 }
459 {
460 Metadata *Ops[] = {Empty};
461 auto Temp = MDTuple::getTemporary(Context, Ops);
462 EXPECT_TRUE(Temp->isTemporary());
463
464 // Should collide with Uniqued above this time.
465 auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
466 EXPECT_TRUE(Uniqued->isUniqued());
467 EXPECT_TRUE(Uniqued->isResolved());
468 EXPECT_EQ(FirstUniqued, Uniqued);
469 }
470 {
471 auto Unresolved = MDTuple::getTemporary(Context, None);
472 Metadata *Ops[] = {Unresolved.get()};
473 auto Temp = MDTuple::getTemporary(Context, Ops);
474 EXPECT_TRUE(Temp->isTemporary());
475
476 // Shouldn't be resolved.
477 auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
478 EXPECT_TRUE(Uniqued->isUniqued());
479 EXPECT_FALSE(Uniqued->isResolved());
480
481 // Should be a different node.
482 EXPECT_NE(FirstUniqued, Uniqued);
483
484 // Should resolve when we update its node (note: be careful to avoid a
485 // collision with any other nodes above).
486 Uniqued->replaceOperandWith(0, nullptr);
487 EXPECT_TRUE(Uniqued->isResolved());
488 }
489}
490
491TEST_F(MDNodeTest, replaceWithDistinct) {
492 {
493 auto *Empty = MDTuple::get(Context, None);
494 Metadata *Ops[] = {Empty};
495 auto Temp = MDTuple::getTemporary(Context, Ops);
496 EXPECT_TRUE(Temp->isTemporary());
497
498 // Don't expect a collision.
499 auto *Current = Temp.get();
500 auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
501 EXPECT_TRUE(Distinct->isDistinct());
502 EXPECT_TRUE(Distinct->isResolved());
503 EXPECT_EQ(Current, Distinct);
504 }
505 {
506 auto Unresolved = MDTuple::getTemporary(Context, None);
507 Metadata *Ops[] = {Unresolved.get()};
508 auto Temp = MDTuple::getTemporary(Context, Ops);
509 EXPECT_TRUE(Temp->isTemporary());
510
511 // Don't expect a collision.
512 auto *Current = Temp.get();
513 auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
514 EXPECT_TRUE(Distinct->isDistinct());
515 EXPECT_TRUE(Distinct->isResolved());
516 EXPECT_EQ(Current, Distinct);
517
518 // Cleanup; required for teardown.
519 Unresolved->replaceAllUsesWith(nullptr);
520 }
521}
522
Duncan P. N. Exon Smith4ee4a982015-02-10 19:13:46 +0000523TEST_F(MDNodeTest, replaceWithPermanent) {
524 Metadata *Ops[] = {nullptr};
525 auto Temp = MDTuple::getTemporary(Context, Ops);
526 auto *T = Temp.get();
527
528 // U is a normal, uniqued node that references T.
529 auto *U = MDTuple::get(Context, T);
530 EXPECT_TRUE(U->isUniqued());
531
532 // Make Temp self-referencing.
533 Temp->replaceOperandWith(0, T);
534
535 // Try to uniquify Temp. This should, despite the name in the API, give a
536 // 'distinct' node, since self-references aren't allowed to be uniqued.
537 //
538 // Since it's distinct, N should have the same address as when it was a
539 // temporary (i.e., be equal to T not U).
540 auto *N = MDNode::replaceWithPermanent(std::move(Temp));
541 EXPECT_EQ(N, T);
542 EXPECT_TRUE(N->isDistinct());
543
544 // U should be the canonical unique node with N as the argument.
545 EXPECT_EQ(U, MDTuple::get(Context, N));
546 EXPECT_TRUE(U->isUniqued());
547
548 // This temporary should collide with U when replaced, but it should still be
549 // uniqued.
550 EXPECT_EQ(U, MDNode::replaceWithPermanent(MDTuple::getTemporary(Context, N)));
551 EXPECT_TRUE(U->isUniqued());
552
553 // This temporary should become a new uniqued node.
554 auto Temp2 = MDTuple::getTemporary(Context, U);
555 auto *V = Temp2.get();
556 EXPECT_EQ(V, MDNode::replaceWithPermanent(std::move(Temp2)));
557 EXPECT_TRUE(V->isUniqued());
558 EXPECT_EQ(U, V->getOperand(0));
559}
560
Duncan P. N. Exon Smith8d536972015-01-22 21:36:45 +0000561TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) {
562 TrackingMDRef Ref;
563 EXPECT_EQ(nullptr, Ref.get());
564 {
565 auto Temp = MDTuple::getTemporary(Context, None);
566 Ref.reset(Temp.get());
567 EXPECT_EQ(Temp.get(), Ref.get());
568 }
569 EXPECT_EQ(nullptr, Ref.get());
570}
571
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000572typedef MetadataTest MDLocationTest;
573
574TEST_F(MDLocationTest, Overflow) {
575 MDNode *N = MDNode::get(Context, None);
576 {
577 MDLocation *L = MDLocation::get(Context, 2, 7, N);
578 EXPECT_EQ(2u, L->getLine());
579 EXPECT_EQ(7u, L->getColumn());
580 }
Duncan P. N. Exon Smith2f5bb312015-01-16 17:33:08 +0000581 unsigned U16 = 1u << 16;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000582 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000583 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 - 1, N);
584 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smith2f5bb312015-01-16 17:33:08 +0000585 EXPECT_EQ(U16 - 1, L->getColumn());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000586 }
587 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000588 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16, N);
589 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000590 EXPECT_EQ(0u, L->getColumn());
591 }
592 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000593 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 + 1, N);
594 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000595 EXPECT_EQ(0u, L->getColumn());
596 }
597}
598
599TEST_F(MDLocationTest, getDistinct) {
600 MDNode *N = MDNode::get(Context, None);
601 MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N);
602 EXPECT_TRUE(L0->isDistinct());
603 MDLocation *L1 = MDLocation::get(Context, 2, 7, N);
604 EXPECT_FALSE(L1->isDistinct());
605 EXPECT_EQ(L1, MDLocation::get(Context, 2, 7, N));
606}
607
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000608TEST_F(MDLocationTest, getTemporary) {
609 MDNode *N = MDNode::get(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000610 auto L = MDLocation::getTemporary(Context, 2, 7, N);
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000611 EXPECT_TRUE(L->isTemporary());
612 EXPECT_FALSE(L->isResolved());
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000613}
614
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000615typedef MetadataTest GenericDebugNodeTest;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000616
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000617TEST_F(GenericDebugNodeTest, get) {
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000618 StringRef Header = "header";
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000619 auto *Empty = MDNode::get(Context, None);
620 Metadata *Ops1[] = {Empty};
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000621 auto *N = GenericDebugNode::get(Context, 15, Header, Ops1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000622 EXPECT_EQ(15u, N->getTag());
623 EXPECT_EQ(2u, N->getNumOperands());
624 EXPECT_EQ(Header, N->getHeader());
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000625 EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000626 EXPECT_EQ(1u, N->getNumDwarfOperands());
627 EXPECT_EQ(Empty, N->getDwarfOperand(0));
628 EXPECT_EQ(Empty, N->getOperand(1));
629 ASSERT_TRUE(N->isUniqued());
630
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000631 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000632
633 N->replaceOperandWith(1, nullptr);
634 EXPECT_EQ(15u, N->getTag());
635 EXPECT_EQ(Header, N->getHeader());
636 EXPECT_EQ(nullptr, N->getDwarfOperand(0));
637 ASSERT_TRUE(N->isUniqued());
638
639 Metadata *Ops2[] = {nullptr};
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000640 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000641
642 N->replaceDwarfOperandWith(0, Empty);
643 EXPECT_EQ(15u, N->getTag());
644 EXPECT_EQ(Header, N->getHeader());
645 EXPECT_EQ(Empty, N->getDwarfOperand(0));
646 ASSERT_TRUE(N->isUniqued());
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000647 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000648
649 TempGenericDebugNode Temp = N->clone();
650 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000651}
652
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000653TEST_F(GenericDebugNodeTest, getEmptyHeader) {
Duncan P. N. Exon Smith2da09e42015-01-20 00:58:46 +0000654 // Canonicalize !"" to null.
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000655 auto *N = GenericDebugNode::get(Context, 15, StringRef(), None);
656 EXPECT_EQ(StringRef(), N->getHeader());
657 EXPECT_EQ(nullptr, N->getOperand(0));
Duncan P. N. Exon Smith2da09e42015-01-20 00:58:46 +0000658}
659
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000660typedef MetadataTest MDSubrangeTest;
661
662TEST_F(MDSubrangeTest, get) {
663 auto *N = MDSubrange::get(Context, 5, 7);
664 EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
665 EXPECT_EQ(5, N->getCount());
666 EXPECT_EQ(7, N->getLo());
667 EXPECT_EQ(N, MDSubrange::get(Context, 5, 7));
668 EXPECT_EQ(MDSubrange::get(Context, 5, 0), MDSubrange::get(Context, 5));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000669
670 TempMDSubrange Temp = N->clone();
671 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000672}
673
Duncan P. N. Exon Smith5c9a1772015-02-18 23:17:51 +0000674TEST_F(MDSubrangeTest, getEmptyArray) {
675 auto *N = MDSubrange::get(Context, -1, 0);
676 EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
677 EXPECT_EQ(-1, N->getCount());
678 EXPECT_EQ(0, N->getLo());
679 EXPECT_EQ(N, MDSubrange::get(Context, -1, 0));
680}
681
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000682typedef MetadataTest MDEnumeratorTest;
683
684TEST_F(MDEnumeratorTest, get) {
685 auto *N = MDEnumerator::get(Context, 7, "name");
686 EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag());
687 EXPECT_EQ(7, N->getValue());
688 EXPECT_EQ("name", N->getName());
689 EXPECT_EQ(N, MDEnumerator::get(Context, 7, "name"));
690
691 EXPECT_NE(N, MDEnumerator::get(Context, 8, "name"));
692 EXPECT_NE(N, MDEnumerator::get(Context, 7, "nam"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000693
694 TempMDEnumerator Temp = N->clone();
695 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000696}
697
698typedef MetadataTest MDBasicTypeTest;
699
700TEST_F(MDBasicTypeTest, get) {
701 auto *N =
702 MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7);
703 EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag());
704 EXPECT_EQ("special", N->getName());
705 EXPECT_EQ(33u, N->getSizeInBits());
706 EXPECT_EQ(26u, N->getAlignInBits());
707 EXPECT_EQ(7u, N->getEncoding());
708 EXPECT_EQ(0u, N->getLine());
709 EXPECT_EQ(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
710 26, 7));
711
712 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type,
713 "special", 33, 26, 7));
714 EXPECT_NE(N,
715 MDBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7));
716 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32,
717 26, 7));
718 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
719 25, 7));
720 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
721 26, 6));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000722
723 TempMDBasicType Temp = N->clone();
724 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000725}
726
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000727TEST_F(MDBasicTypeTest, getWithLargeValues) {
728 auto *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special",
729 UINT64_MAX, UINT64_MAX - 1, 7);
730 EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
731 EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits());
732}
733
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +0000734TEST_F(MDBasicTypeTest, getUnspecified) {
735 auto *N =
736 MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, "unspecified");
737 EXPECT_EQ(dwarf::DW_TAG_unspecified_type, N->getTag());
738 EXPECT_EQ("unspecified", N->getName());
739 EXPECT_EQ(0u, N->getSizeInBits());
740 EXPECT_EQ(0u, N->getAlignInBits());
741 EXPECT_EQ(0u, N->getEncoding());
742 EXPECT_EQ(0u, N->getLine());
743}
744
745typedef MetadataTest MDTypeTest;
746
747TEST_F(MDTypeTest, clone) {
748 // Check that MDType has a specialized clone that returns TempMDType.
749 MDType *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32,
750 dwarf::DW_ATE_signed);
751
752 TempMDType Temp = N->clone();
753 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
754}
755
756TEST_F(MDTypeTest, setFlags) {
757 // void (void)
758 Metadata *TypesOps[] = {nullptr};
759 Metadata *Types = MDTuple::get(Context, TypesOps);
760
761 MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types);
762 EXPECT_EQ(0u, D->getFlags());
763 D->setFlags(DIDescriptor::FlagRValueReference);
764 EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags());
765 D->setFlags(0u);
766 EXPECT_EQ(0u, D->getFlags());
767
768 TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types);
769 EXPECT_EQ(0u, T->getFlags());
770 T->setFlags(DIDescriptor::FlagRValueReference);
771 EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags());
772 T->setFlags(0u);
773 EXPECT_EQ(0u, T->getFlags());
774}
775
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000776typedef MetadataTest MDDerivedTypeTest;
777
778TEST_F(MDDerivedTypeTest, get) {
779 Metadata *File = MDTuple::getDistinct(Context, None);
780 Metadata *Scope = MDTuple::getDistinct(Context, None);
781 Metadata *BaseType = MDTuple::getDistinct(Context, None);
782 Metadata *ExtraData = MDTuple::getDistinct(Context, None);
783
784 auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
785 File, 1, Scope, BaseType, 2, 3, 4, 5, ExtraData);
786 EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag());
787 EXPECT_EQ("something", N->getName());
788 EXPECT_EQ(File, N->getFile());
789 EXPECT_EQ(1u, N->getLine());
790 EXPECT_EQ(Scope, N->getScope());
791 EXPECT_EQ(BaseType, N->getBaseType());
792 EXPECT_EQ(2u, N->getSizeInBits());
793 EXPECT_EQ(3u, N->getAlignInBits());
794 EXPECT_EQ(4u, N->getOffsetInBits());
795 EXPECT_EQ(5u, N->getFlags());
796 EXPECT_EQ(ExtraData, N->getExtraData());
797 EXPECT_EQ(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
798 "something", File, 1, Scope, BaseType, 2, 3,
799 4, 5, ExtraData));
800
801 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_reference_type,
802 "something", File, 1, Scope, BaseType, 2, 3,
803 4, 5, ExtraData));
804 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else",
805 File, 1, Scope, BaseType, 2, 3, 4, 5,
806 ExtraData));
807 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
808 "something", Scope, 1, Scope, BaseType, 2, 3,
809 4, 5, ExtraData));
810 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
811 "something", File, 2, Scope, BaseType, 2, 3,
812 4, 5, ExtraData));
813 EXPECT_NE(N,
814 MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
815 File, 1, File, BaseType, 2, 3, 4, 5, ExtraData));
816 EXPECT_NE(N,
817 MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
818 File, 1, Scope, File, 2, 3, 4, 5, ExtraData));
819 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
820 "something", File, 1, Scope, BaseType, 3, 3,
821 4, 5, ExtraData));
822 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
823 "something", File, 1, Scope, BaseType, 2, 2,
824 4, 5, ExtraData));
825 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
826 "something", File, 1, Scope, BaseType, 2, 3,
827 5, 5, ExtraData));
828 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
829 "something", File, 1, Scope, BaseType, 2, 3,
830 4, 4, ExtraData));
831 EXPECT_NE(N,
832 MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
833 File, 1, Scope, BaseType, 2, 3, 4, 5, File));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000834
835 TempMDDerivedType Temp = N->clone();
836 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000837}
838
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000839TEST_F(MDDerivedTypeTest, getWithLargeValues) {
840 Metadata *File = MDTuple::getDistinct(Context, None);
841 Metadata *Scope = MDTuple::getDistinct(Context, None);
842 Metadata *BaseType = MDTuple::getDistinct(Context, None);
843 Metadata *ExtraData = MDTuple::getDistinct(Context, None);
844
845 auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
846 File, 1, Scope, BaseType, UINT64_MAX,
847 UINT64_MAX - 1, UINT64_MAX - 2, 5, ExtraData);
848 EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
849 EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits());
850 EXPECT_EQ(UINT64_MAX - 2, N->getOffsetInBits());
851}
852
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000853typedef MetadataTest MDCompositeTypeTest;
854
855TEST_F(MDCompositeTypeTest, get) {
856 unsigned Tag = dwarf::DW_TAG_structure_type;
857 StringRef Name = "some name";
858 Metadata *File = MDTuple::getDistinct(Context, None);
859 unsigned Line = 1;
860 Metadata *Scope = MDTuple::getDistinct(Context, None);
861 Metadata *BaseType = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000862 uint64_t SizeInBits = 2;
863 uint64_t AlignInBits = 3;
864 uint64_t OffsetInBits = 4;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000865 unsigned Flags = 5;
866 Metadata *Elements = MDTuple::getDistinct(Context, None);
867 unsigned RuntimeLang = 6;
868 Metadata *VTableHolder = MDTuple::getDistinct(Context, None);
869 Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
870 StringRef Identifier = "some id";
871
872 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
873 BaseType, SizeInBits, AlignInBits,
874 OffsetInBits, Flags, Elements, RuntimeLang,
875 VTableHolder, TemplateParams, Identifier);
876 EXPECT_EQ(Tag, N->getTag());
877 EXPECT_EQ(Name, N->getName());
878 EXPECT_EQ(File, N->getFile());
879 EXPECT_EQ(Line, N->getLine());
880 EXPECT_EQ(Scope, N->getScope());
881 EXPECT_EQ(BaseType, N->getBaseType());
882 EXPECT_EQ(SizeInBits, N->getSizeInBits());
883 EXPECT_EQ(AlignInBits, N->getAlignInBits());
884 EXPECT_EQ(OffsetInBits, N->getOffsetInBits());
885 EXPECT_EQ(Flags, N->getFlags());
886 EXPECT_EQ(Elements, N->getElements());
887 EXPECT_EQ(RuntimeLang, N->getRuntimeLang());
888 EXPECT_EQ(VTableHolder, N->getVTableHolder());
889 EXPECT_EQ(TemplateParams, N->getTemplateParams());
890 EXPECT_EQ(Identifier, N->getIdentifier());
891
892 EXPECT_EQ(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
893 BaseType, SizeInBits, AlignInBits,
894 OffsetInBits, Flags, Elements, RuntimeLang,
895 VTableHolder, TemplateParams, Identifier));
896
897 EXPECT_NE(N, MDCompositeType::get(Context, Tag + 1, Name, File, Line, Scope,
898 BaseType, SizeInBits, AlignInBits,
899 OffsetInBits, Flags, Elements, RuntimeLang,
900 VTableHolder, TemplateParams, Identifier));
901 EXPECT_NE(N, MDCompositeType::get(Context, Tag, "abc", File, Line, Scope,
902 BaseType, SizeInBits, AlignInBits,
903 OffsetInBits, Flags, Elements, RuntimeLang,
904 VTableHolder, TemplateParams, Identifier));
905 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, Scope, Line, Scope,
906 BaseType, SizeInBits, AlignInBits,
907 OffsetInBits, Flags, Elements, RuntimeLang,
908 VTableHolder, TemplateParams, Identifier));
909 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line + 1, Scope,
910 BaseType, SizeInBits, AlignInBits,
911 OffsetInBits, Flags, Elements, RuntimeLang,
912 VTableHolder, TemplateParams, Identifier));
913 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, File,
914 BaseType, SizeInBits, AlignInBits,
915 OffsetInBits, Flags, Elements, RuntimeLang,
916 VTableHolder, TemplateParams, Identifier));
917 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, File,
918 SizeInBits, AlignInBits, OffsetInBits,
919 Flags, Elements, RuntimeLang, VTableHolder,
920 TemplateParams, Identifier));
921 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
922 BaseType, SizeInBits + 1, AlignInBits,
923 OffsetInBits, Flags, Elements, RuntimeLang,
924 VTableHolder, TemplateParams, Identifier));
925 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
926 BaseType, SizeInBits, AlignInBits + 1,
927 OffsetInBits, Flags, Elements, RuntimeLang,
928 VTableHolder, TemplateParams, Identifier));
929 EXPECT_NE(N, MDCompositeType::get(
930 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
931 AlignInBits, OffsetInBits + 1, Flags, Elements, RuntimeLang,
932 VTableHolder, TemplateParams, Identifier));
933 EXPECT_NE(N, MDCompositeType::get(
934 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
935 AlignInBits, OffsetInBits, Flags + 1, Elements, RuntimeLang,
936 VTableHolder, TemplateParams, Identifier));
937 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
938 BaseType, SizeInBits, AlignInBits,
939 OffsetInBits, Flags, File, RuntimeLang,
940 VTableHolder, TemplateParams, Identifier));
941 EXPECT_NE(N, MDCompositeType::get(
942 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
943 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang + 1,
944 VTableHolder, TemplateParams, Identifier));
945 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
946 BaseType, SizeInBits, AlignInBits,
947 OffsetInBits, Flags, Elements, RuntimeLang,
948 File, TemplateParams, Identifier));
949 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
950 BaseType, SizeInBits, AlignInBits,
951 OffsetInBits, Flags, Elements, RuntimeLang,
952 VTableHolder, File, Identifier));
953 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
954 BaseType, SizeInBits, AlignInBits,
955 OffsetInBits, Flags, Elements, RuntimeLang,
956 VTableHolder, TemplateParams, "other"));
957
958 // Be sure that missing identifiers get null pointers.
959 EXPECT_FALSE(MDCompositeType::get(
960 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
961 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
962 VTableHolder, TemplateParams, "")->getRawIdentifier());
963 EXPECT_FALSE(MDCompositeType::get(
964 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
965 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
966 VTableHolder, TemplateParams)->getRawIdentifier());
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000967
968 TempMDCompositeType Temp = N->clone();
969 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000970}
971
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000972TEST_F(MDCompositeTypeTest, getWithLargeValues) {
973 unsigned Tag = dwarf::DW_TAG_structure_type;
974 StringRef Name = "some name";
975 Metadata *File = MDTuple::getDistinct(Context, None);
976 unsigned Line = 1;
977 Metadata *Scope = MDTuple::getDistinct(Context, None);
978 Metadata *BaseType = MDTuple::getDistinct(Context, None);
979 uint64_t SizeInBits = UINT64_MAX;
980 uint64_t AlignInBits = UINT64_MAX - 1;
981 uint64_t OffsetInBits = UINT64_MAX - 2;
982 unsigned Flags = 5;
983 Metadata *Elements = MDTuple::getDistinct(Context, None);
984 unsigned RuntimeLang = 6;
985 Metadata *VTableHolder = MDTuple::getDistinct(Context, None);
986 Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
987 StringRef Identifier = "some id";
988
989 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
990 BaseType, SizeInBits, AlignInBits,
991 OffsetInBits, Flags, Elements, RuntimeLang,
992 VTableHolder, TemplateParams, Identifier);
993 EXPECT_EQ(SizeInBits, N->getSizeInBits());
994 EXPECT_EQ(AlignInBits, N->getAlignInBits());
995 EXPECT_EQ(OffsetInBits, N->getOffsetInBits());
996}
997
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +0000998TEST_F(MDCompositeTypeTest, replaceOperands) {
999 unsigned Tag = dwarf::DW_TAG_structure_type;
1000 StringRef Name = "some name";
1001 Metadata *File = MDTuple::getDistinct(Context, None);
1002 unsigned Line = 1;
1003 Metadata *Scope = MDTuple::getDistinct(Context, None);
1004 Metadata *BaseType = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001005 uint64_t SizeInBits = 2;
1006 uint64_t AlignInBits = 3;
1007 uint64_t OffsetInBits = 4;
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +00001008 unsigned Flags = 5;
1009 unsigned RuntimeLang = 6;
1010 StringRef Identifier = "some id";
1011
1012 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1013 BaseType, SizeInBits, AlignInBits,
1014 OffsetInBits, Flags, nullptr, RuntimeLang,
1015 nullptr, nullptr, Identifier);
1016
1017 auto *Elements = MDTuple::getDistinct(Context, None);
1018 EXPECT_EQ(nullptr, N->getElements());
1019 N->replaceElements(Elements);
1020 EXPECT_EQ(Elements, N->getElements());
1021 N->replaceElements(nullptr);
1022 EXPECT_EQ(nullptr, N->getElements());
1023
1024 auto *VTableHolder = MDTuple::getDistinct(Context, None);
1025 EXPECT_EQ(nullptr, N->getVTableHolder());
1026 N->replaceVTableHolder(VTableHolder);
1027 EXPECT_EQ(VTableHolder, N->getVTableHolder());
1028 N->replaceVTableHolder(nullptr);
1029 EXPECT_EQ(nullptr, N->getVTableHolder());
1030
1031 auto *TemplateParams = MDTuple::getDistinct(Context, None);
1032 EXPECT_EQ(nullptr, N->getTemplateParams());
1033 N->replaceTemplateParams(TemplateParams);
1034 EXPECT_EQ(TemplateParams, N->getTemplateParams());
1035 N->replaceTemplateParams(nullptr);
1036 EXPECT_EQ(nullptr, N->getTemplateParams());
1037}
1038
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001039typedef MetadataTest MDSubroutineTypeTest;
1040
1041TEST_F(MDSubroutineTypeTest, get) {
1042 unsigned Flags = 1;
1043 Metadata *TypeArray = MDTuple::getDistinct(Context, None);
1044
1045 auto *N = MDSubroutineType::get(Context, Flags, TypeArray);
1046 EXPECT_EQ(dwarf::DW_TAG_subroutine_type, N->getTag());
1047 EXPECT_EQ(Flags, N->getFlags());
1048 EXPECT_EQ(TypeArray, N->getTypeArray());
1049 EXPECT_EQ(N, MDSubroutineType::get(Context, Flags, TypeArray));
1050
1051 EXPECT_NE(N, MDSubroutineType::get(Context, Flags + 1, TypeArray));
1052 EXPECT_NE(N, MDSubroutineType::get(Context, Flags,
1053 MDTuple::getDistinct(Context, None)));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001054
1055 TempMDSubroutineType Temp = N->clone();
1056 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smitha9f0a8d2015-02-19 23:25:21 +00001057
1058 // Test always-empty operands.
1059 EXPECT_EQ(nullptr, N->getScope());
1060 EXPECT_EQ(nullptr, N->getFile());
1061 EXPECT_EQ("", N->getName());
1062 EXPECT_EQ(nullptr, N->getBaseType());
1063 EXPECT_EQ(nullptr, N->getVTableHolder());
1064 EXPECT_EQ(nullptr, N->getTemplateParams());
1065 EXPECT_EQ("", N->getIdentifier());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001066}
1067
1068typedef MetadataTest MDFileTest;
1069
1070TEST_F(MDFileTest, get) {
1071 StringRef Filename = "file";
1072 StringRef Directory = "dir";
1073 auto *N = MDFile::get(Context, Filename, Directory);
1074
1075 EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag());
1076 EXPECT_EQ(Filename, N->getFilename());
1077 EXPECT_EQ(Directory, N->getDirectory());
1078 EXPECT_EQ(N, MDFile::get(Context, Filename, Directory));
1079
1080 EXPECT_NE(N, MDFile::get(Context, "other", Directory));
1081 EXPECT_NE(N, MDFile::get(Context, Filename, "other"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001082
1083 TempMDFile Temp = N->clone();
1084 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001085}
1086
Duncan P. N. Exon Smith2c6a0a92015-02-28 21:47:02 +00001087TEST_F(MDFileTest, ScopeGetFile) {
1088 // Ensure that MDScope::getFile() returns itself.
1089 MDScope *N = MDFile::get(Context, "file", "dir");
1090 EXPECT_EQ(N, N->getFile());
1091}
1092
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001093typedef MetadataTest MDCompileUnitTest;
1094
1095TEST_F(MDCompileUnitTest, get) {
1096 unsigned SourceLanguage = 1;
1097 Metadata *File = MDTuple::getDistinct(Context, None);
1098 StringRef Producer = "some producer";
1099 bool IsOptimized = false;
1100 StringRef Flags = "flag after flag";
1101 unsigned RuntimeVersion = 2;
1102 StringRef SplitDebugFilename = "another/file";
1103 unsigned EmissionKind = 3;
1104 Metadata *EnumTypes = MDTuple::getDistinct(Context, None);
1105 Metadata *RetainedTypes = MDTuple::getDistinct(Context, None);
1106 Metadata *Subprograms = MDTuple::getDistinct(Context, None);
1107 Metadata *GlobalVariables = MDTuple::getDistinct(Context, None);
1108 Metadata *ImportedEntities = MDTuple::getDistinct(Context, None);
1109 auto *N = MDCompileUnit::get(
1110 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1111 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1112 RetainedTypes, Subprograms, GlobalVariables, ImportedEntities);
1113
1114 EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
1115 EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
1116 EXPECT_EQ(File, N->getFile());
1117 EXPECT_EQ(Producer, N->getProducer());
1118 EXPECT_EQ(IsOptimized, N->isOptimized());
1119 EXPECT_EQ(Flags, N->getFlags());
1120 EXPECT_EQ(RuntimeVersion, N->getRuntimeVersion());
1121 EXPECT_EQ(SplitDebugFilename, N->getSplitDebugFilename());
1122 EXPECT_EQ(EmissionKind, N->getEmissionKind());
1123 EXPECT_EQ(EnumTypes, N->getEnumTypes());
1124 EXPECT_EQ(RetainedTypes, N->getRetainedTypes());
1125 EXPECT_EQ(Subprograms, N->getSubprograms());
1126 EXPECT_EQ(GlobalVariables, N->getGlobalVariables());
1127 EXPECT_EQ(ImportedEntities, N->getImportedEntities());
1128 EXPECT_EQ(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1129 IsOptimized, Flags, RuntimeVersion,
1130 SplitDebugFilename, EmissionKind, EnumTypes,
1131 RetainedTypes, Subprograms, GlobalVariables,
1132 ImportedEntities));
1133
1134 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage + 1, File, Producer,
1135 IsOptimized, Flags, RuntimeVersion,
1136 SplitDebugFilename, EmissionKind, EnumTypes,
1137 RetainedTypes, Subprograms, GlobalVariables,
1138 ImportedEntities));
1139 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, EnumTypes, Producer,
1140 IsOptimized, Flags, RuntimeVersion,
1141 SplitDebugFilename, EmissionKind, EnumTypes,
1142 RetainedTypes, Subprograms, GlobalVariables,
1143 ImportedEntities));
1144 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, "other",
1145 IsOptimized, Flags, RuntimeVersion,
1146 SplitDebugFilename, EmissionKind, EnumTypes,
1147 RetainedTypes, Subprograms, GlobalVariables,
1148 ImportedEntities));
1149 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1150 !IsOptimized, Flags, RuntimeVersion,
1151 SplitDebugFilename, EmissionKind, EnumTypes,
1152 RetainedTypes, Subprograms, GlobalVariables,
1153 ImportedEntities));
1154 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1155 IsOptimized, "other", RuntimeVersion,
1156 SplitDebugFilename, EmissionKind, EnumTypes,
1157 RetainedTypes, Subprograms, GlobalVariables,
1158 ImportedEntities));
1159 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1160 IsOptimized, Flags, RuntimeVersion + 1,
1161 SplitDebugFilename, EmissionKind, EnumTypes,
1162 RetainedTypes, Subprograms, GlobalVariables,
1163 ImportedEntities));
1164 EXPECT_NE(N,
1165 MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1166 IsOptimized, Flags, RuntimeVersion, "other",
1167 EmissionKind, EnumTypes, RetainedTypes,
1168 Subprograms, GlobalVariables, ImportedEntities));
1169 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1170 IsOptimized, Flags, RuntimeVersion,
1171 SplitDebugFilename, EmissionKind + 1,
1172 EnumTypes, RetainedTypes, Subprograms,
1173 GlobalVariables, ImportedEntities));
1174 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1175 IsOptimized, Flags, RuntimeVersion,
1176 SplitDebugFilename, EmissionKind, File,
1177 RetainedTypes, Subprograms, GlobalVariables,
1178 ImportedEntities));
1179 EXPECT_NE(N, MDCompileUnit::get(
1180 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1181 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1182 File, Subprograms, GlobalVariables, ImportedEntities));
1183 EXPECT_NE(N, MDCompileUnit::get(
1184 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1185 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1186 RetainedTypes, File, GlobalVariables, ImportedEntities));
1187 EXPECT_NE(N, MDCompileUnit::get(
1188 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1189 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1190 RetainedTypes, Subprograms, File, ImportedEntities));
1191 EXPECT_NE(N, MDCompileUnit::get(
1192 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1193 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1194 RetainedTypes, Subprograms, GlobalVariables, File));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001195
1196 TempMDCompileUnit Temp = N->clone();
1197 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001198}
1199
Duncan P. N. Exon Smith94bbbf02015-02-18 20:36:09 +00001200TEST_F(MDCompileUnitTest, replaceArrays) {
1201 unsigned SourceLanguage = 1;
1202 Metadata *File = MDTuple::getDistinct(Context, None);
1203 StringRef Producer = "some producer";
1204 bool IsOptimized = false;
1205 StringRef Flags = "flag after flag";
1206 unsigned RuntimeVersion = 2;
1207 StringRef SplitDebugFilename = "another/file";
1208 unsigned EmissionKind = 3;
1209 Metadata *EnumTypes = MDTuple::getDistinct(Context, None);
1210 Metadata *RetainedTypes = MDTuple::getDistinct(Context, None);
1211 Metadata *ImportedEntities = MDTuple::getDistinct(Context, None);
1212 auto *N = MDCompileUnit::get(
1213 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1214 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1215 RetainedTypes, nullptr, nullptr, ImportedEntities);
1216
1217 auto *Subprograms = MDTuple::getDistinct(Context, None);
1218 EXPECT_EQ(nullptr, N->getSubprograms());
1219 N->replaceSubprograms(Subprograms);
1220 EXPECT_EQ(Subprograms, N->getSubprograms());
1221 N->replaceSubprograms(nullptr);
1222 EXPECT_EQ(nullptr, N->getSubprograms());
1223
1224 auto *GlobalVariables = MDTuple::getDistinct(Context, None);
1225 EXPECT_EQ(nullptr, N->getGlobalVariables());
1226 N->replaceGlobalVariables(GlobalVariables);
1227 EXPECT_EQ(GlobalVariables, N->getGlobalVariables());
1228 N->replaceGlobalVariables(nullptr);
1229 EXPECT_EQ(nullptr, N->getGlobalVariables());
1230}
1231
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001232typedef MetadataTest MDSubprogramTest;
1233
1234TEST_F(MDSubprogramTest, get) {
1235 Metadata *Scope = MDTuple::getDistinct(Context, None);
1236 StringRef Name = "name";
1237 StringRef LinkageName = "linkage";
1238 Metadata *File = MDTuple::getDistinct(Context, None);
1239 unsigned Line = 2;
1240 Metadata *Type = MDTuple::getDistinct(Context, None);
1241 bool IsLocalToUnit = false;
1242 bool IsDefinition = true;
1243 unsigned ScopeLine = 3;
1244 Metadata *ContainingType = MDTuple::getDistinct(Context, None);
1245 unsigned Virtuality = 4;
1246 unsigned VirtualIndex = 5;
1247 unsigned Flags = 6;
1248 bool IsOptimized = false;
1249 Metadata *Function = MDTuple::getDistinct(Context, None);
1250 Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
1251 Metadata *Declaration = MDTuple::getDistinct(Context, None);
1252 Metadata *Variables = MDTuple::getDistinct(Context, None);
1253
1254 auto *N = MDSubprogram::get(
1255 Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1256 IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
1257 IsOptimized, Function, TemplateParams, Declaration, Variables);
1258
1259 EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag());
1260 EXPECT_EQ(Scope, N->getScope());
1261 EXPECT_EQ(Name, N->getName());
1262 EXPECT_EQ(LinkageName, N->getLinkageName());
1263 EXPECT_EQ(File, N->getFile());
1264 EXPECT_EQ(Line, N->getLine());
1265 EXPECT_EQ(Type, N->getType());
1266 EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit());
1267 EXPECT_EQ(IsDefinition, N->isDefinition());
1268 EXPECT_EQ(ScopeLine, N->getScopeLine());
1269 EXPECT_EQ(ContainingType, N->getContainingType());
1270 EXPECT_EQ(Virtuality, N->getVirtuality());
1271 EXPECT_EQ(VirtualIndex, N->getVirtualIndex());
1272 EXPECT_EQ(Flags, N->getFlags());
1273 EXPECT_EQ(IsOptimized, N->isOptimized());
1274 EXPECT_EQ(Function, N->getFunction());
1275 EXPECT_EQ(TemplateParams, N->getTemplateParams());
1276 EXPECT_EQ(Declaration, N->getDeclaration());
1277 EXPECT_EQ(Variables, N->getVariables());
1278 EXPECT_EQ(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1279 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1280 ContainingType, Virtuality, VirtualIndex,
1281 Flags, IsOptimized, Function, TemplateParams,
1282 Declaration, Variables));
1283
1284 EXPECT_NE(N, MDSubprogram::get(Context, File, Name, LinkageName, File, Line,
1285 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1286 ContainingType, Virtuality, VirtualIndex,
1287 Flags, IsOptimized, Function, TemplateParams,
1288 Declaration, Variables));
1289 EXPECT_NE(N, MDSubprogram::get(Context, Scope, "other", LinkageName, File,
1290 Line, Type, IsLocalToUnit, IsDefinition,
1291 ScopeLine, ContainingType, Virtuality,
1292 VirtualIndex, Flags, IsOptimized, Function,
1293 TemplateParams, Declaration, Variables));
1294 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, "other", File, Line,
1295 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1296 ContainingType, Virtuality, VirtualIndex,
1297 Flags, IsOptimized, Function, TemplateParams,
1298 Declaration, Variables));
1299 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, Scope, Line,
1300 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1301 ContainingType, Virtuality, VirtualIndex,
1302 Flags, IsOptimized, Function, TemplateParams,
1303 Declaration, Variables));
1304 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File,
1305 Line + 1, Type, IsLocalToUnit, IsDefinition,
1306 ScopeLine, ContainingType, Virtuality,
1307 VirtualIndex, Flags, IsOptimized, Function,
1308 TemplateParams, Declaration, Variables));
1309 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1310 Scope, IsLocalToUnit, IsDefinition, ScopeLine,
1311 ContainingType, Virtuality, VirtualIndex,
1312 Flags, IsOptimized, Function, TemplateParams,
1313 Declaration, Variables));
1314 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1315 Type, !IsLocalToUnit, IsDefinition, ScopeLine,
1316 ContainingType, Virtuality, VirtualIndex,
1317 Flags, IsOptimized, Function, TemplateParams,
1318 Declaration, Variables));
1319 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1320 Type, IsLocalToUnit, !IsDefinition, ScopeLine,
1321 ContainingType, Virtuality, VirtualIndex,
1322 Flags, IsOptimized, Function, TemplateParams,
1323 Declaration, Variables));
1324 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1325 Type, IsLocalToUnit, IsDefinition,
1326 ScopeLine + 1, ContainingType, Virtuality,
1327 VirtualIndex, Flags, IsOptimized, Function,
1328 TemplateParams, Declaration, Variables));
1329 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1330 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1331 Type, Virtuality, VirtualIndex, Flags,
1332 IsOptimized, Function, TemplateParams,
1333 Declaration, Variables));
1334 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1335 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1336 ContainingType, Virtuality + 1, VirtualIndex,
1337 Flags, IsOptimized, Function, TemplateParams,
1338 Declaration, Variables));
1339 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1340 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1341 ContainingType, Virtuality, VirtualIndex + 1,
1342 Flags, IsOptimized, Function, TemplateParams,
1343 Declaration, Variables));
1344 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1345 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1346 ContainingType, Virtuality, VirtualIndex,
1347 ~Flags, IsOptimized, Function, TemplateParams,
1348 Declaration, Variables));
1349 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1350 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1351 ContainingType, Virtuality, VirtualIndex,
1352 Flags, !IsOptimized, Function, TemplateParams,
1353 Declaration, Variables));
1354 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1355 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1356 ContainingType, Virtuality, VirtualIndex,
1357 Flags, IsOptimized, Type, TemplateParams,
1358 Declaration, Variables));
1359 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1360 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1361 ContainingType, Virtuality, VirtualIndex,
1362 Flags, IsOptimized, Function, Type,
1363 Declaration, Variables));
1364 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1365 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1366 ContainingType, Virtuality, VirtualIndex,
1367 Flags, IsOptimized, Function, TemplateParams,
1368 Type, Variables));
1369 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1370 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1371 ContainingType, Virtuality, VirtualIndex,
1372 Flags, IsOptimized, Function, TemplateParams,
1373 Declaration, Type));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001374
1375 TempMDSubprogram Temp = N->clone();
1376 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001377}
1378
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001379TEST_F(MDSubprogramTest, replaceFunction) {
1380 Metadata *Scope = MDTuple::getDistinct(Context, None);
1381 StringRef Name = "name";
1382 StringRef LinkageName = "linkage";
1383 Metadata *File = MDTuple::getDistinct(Context, None);
1384 unsigned Line = 2;
1385 Metadata *Type = MDTuple::getDistinct(Context, None);
1386 bool IsLocalToUnit = false;
1387 bool IsDefinition = true;
1388 unsigned ScopeLine = 3;
1389 Metadata *ContainingType = MDTuple::getDistinct(Context, None);
1390 unsigned Virtuality = 4;
1391 unsigned VirtualIndex = 5;
1392 unsigned Flags = 6;
1393 bool IsOptimized = false;
1394 Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
1395 Metadata *Declaration = MDTuple::getDistinct(Context, None);
1396 Metadata *Variables = MDTuple::getDistinct(Context, None);
1397
1398 auto *N = MDSubprogram::get(
1399 Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1400 IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
1401 IsOptimized, nullptr, TemplateParams, Declaration, Variables);
1402
1403 EXPECT_EQ(nullptr, N->getFunction());
1404
1405 std::unique_ptr<Function> F(
1406 Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
1407 GlobalValue::ExternalLinkage));
1408 N->replaceFunction(F.get());
1409 EXPECT_EQ(ConstantAsMetadata::get(F.get()), N->getFunction());
1410
1411 N->replaceFunction(nullptr);
1412 EXPECT_EQ(nullptr, N->getFunction());
1413}
1414
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001415typedef MetadataTest MDLexicalBlockTest;
1416
1417TEST_F(MDLexicalBlockTest, get) {
1418 Metadata *Scope = MDTuple::getDistinct(Context, None);
1419 Metadata *File = MDTuple::getDistinct(Context, None);
1420 unsigned Line = 5;
1421 unsigned Column = 8;
1422
1423 auto *N = MDLexicalBlock::get(Context, Scope, File, Line, Column);
1424
1425 EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag());
1426 EXPECT_EQ(Scope, N->getScope());
1427 EXPECT_EQ(File, N->getFile());
1428 EXPECT_EQ(Line, N->getLine());
1429 EXPECT_EQ(Column, N->getColumn());
1430 EXPECT_EQ(N, MDLexicalBlock::get(Context, Scope, File, Line, Column));
1431
1432 EXPECT_NE(N, MDLexicalBlock::get(Context, File, File, Line, Column));
1433 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, Scope, Line, Column));
1434 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line + 1, Column));
1435 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line, Column + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001436
1437 TempMDLexicalBlock Temp = N->clone();
1438 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001439}
1440
1441typedef MetadataTest MDLexicalBlockFileTest;
1442
1443TEST_F(MDLexicalBlockFileTest, get) {
1444 Metadata *Scope = MDTuple::getDistinct(Context, None);
1445 Metadata *File = MDTuple::getDistinct(Context, None);
1446 unsigned Discriminator = 5;
1447
1448 auto *N = MDLexicalBlockFile::get(Context, Scope, File, Discriminator);
1449
1450 EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag());
1451 EXPECT_EQ(Scope, N->getScope());
1452 EXPECT_EQ(File, N->getFile());
1453 EXPECT_EQ(Discriminator, N->getDiscriminator());
1454 EXPECT_EQ(N, MDLexicalBlockFile::get(Context, Scope, File, Discriminator));
1455
1456 EXPECT_NE(N, MDLexicalBlockFile::get(Context, File, File, Discriminator));
1457 EXPECT_NE(N, MDLexicalBlockFile::get(Context, Scope, Scope, Discriminator));
1458 EXPECT_NE(N,
1459 MDLexicalBlockFile::get(Context, Scope, File, Discriminator + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001460
1461 TempMDLexicalBlockFile Temp = N->clone();
1462 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001463}
1464
1465typedef MetadataTest MDNamespaceTest;
1466
1467TEST_F(MDNamespaceTest, get) {
1468 Metadata *Scope = MDTuple::getDistinct(Context, None);
1469 Metadata *File = MDTuple::getDistinct(Context, None);
1470 StringRef Name = "namespace";
1471 unsigned Line = 5;
1472
1473 auto *N = MDNamespace::get(Context, Scope, File, Name, Line);
1474
1475 EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag());
1476 EXPECT_EQ(Scope, N->getScope());
1477 EXPECT_EQ(File, N->getFile());
1478 EXPECT_EQ(Name, N->getName());
1479 EXPECT_EQ(Line, N->getLine());
1480 EXPECT_EQ(N, MDNamespace::get(Context, Scope, File, Name, Line));
1481
1482 EXPECT_NE(N, MDNamespace::get(Context, File, File, Name, Line));
1483 EXPECT_NE(N, MDNamespace::get(Context, Scope, Scope, Name, Line));
1484 EXPECT_NE(N, MDNamespace::get(Context, Scope, File, "other", Line));
1485 EXPECT_NE(N, MDNamespace::get(Context, Scope, File, Name, Line + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001486
1487 TempMDNamespace Temp = N->clone();
1488 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001489}
1490
1491typedef MetadataTest MDTemplateTypeParameterTest;
1492
1493TEST_F(MDTemplateTypeParameterTest, get) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001494 StringRef Name = "template";
1495 Metadata *Type = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001496 Metadata *Other = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001497
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001498 auto *N = MDTemplateTypeParameter::get(Context, Name, Type);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001499
1500 EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001501 EXPECT_EQ(Name, N->getName());
1502 EXPECT_EQ(Type, N->getType());
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001503 EXPECT_EQ(N, MDTemplateTypeParameter::get(Context, Name, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001504
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001505 EXPECT_NE(N, MDTemplateTypeParameter::get(Context, "other", Type));
1506 EXPECT_NE(N, MDTemplateTypeParameter::get(Context, Name, Other));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001507
1508 TempMDTemplateTypeParameter Temp = N->clone();
1509 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001510}
1511
1512typedef MetadataTest MDTemplateValueParameterTest;
1513
1514TEST_F(MDTemplateValueParameterTest, get) {
1515 unsigned Tag = dwarf::DW_TAG_template_value_parameter;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001516 StringRef Name = "template";
1517 Metadata *Type = MDTuple::getDistinct(Context, None);
1518 Metadata *Value = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001519 Metadata *Other = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001520
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001521 auto *N = MDTemplateValueParameter::get(Context, Tag, Name, Type, Value);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001522 EXPECT_EQ(Tag, N->getTag());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001523 EXPECT_EQ(Name, N->getName());
1524 EXPECT_EQ(Type, N->getType());
1525 EXPECT_EQ(Value, N->getValue());
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001526 EXPECT_EQ(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, Value));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001527
1528 EXPECT_NE(N, MDTemplateValueParameter::get(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001529 Context, dwarf::DW_TAG_GNU_template_template_param, Name,
1530 Type, Value));
1531 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, "other", Type,
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +00001532 Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001533 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Other,
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +00001534 Value));
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001535 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, Other));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001536
1537 TempMDTemplateValueParameter Temp = N->clone();
1538 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001539}
1540
1541typedef MetadataTest MDGlobalVariableTest;
1542
1543TEST_F(MDGlobalVariableTest, get) {
1544 Metadata *Scope = MDTuple::getDistinct(Context, None);
1545 StringRef Name = "name";
1546 StringRef LinkageName = "linkage";
1547 Metadata *File = MDTuple::getDistinct(Context, None);
1548 unsigned Line = 5;
1549 Metadata *Type = MDTuple::getDistinct(Context, None);
1550 bool IsLocalToUnit = false;
1551 bool IsDefinition = true;
1552 Metadata *Variable = MDTuple::getDistinct(Context, None);
1553 Metadata *StaticDataMemberDeclaration = MDTuple::getDistinct(Context, None);
1554
1555 auto *N = MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
1556 Type, IsLocalToUnit, IsDefinition, Variable,
1557 StaticDataMemberDeclaration);
1558 EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag());
1559 EXPECT_EQ(Scope, N->getScope());
1560 EXPECT_EQ(Name, N->getName());
1561 EXPECT_EQ(LinkageName, N->getLinkageName());
1562 EXPECT_EQ(File, N->getFile());
1563 EXPECT_EQ(Line, N->getLine());
1564 EXPECT_EQ(Type, N->getType());
1565 EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit());
1566 EXPECT_EQ(IsDefinition, N->isDefinition());
1567 EXPECT_EQ(Variable, N->getVariable());
1568 EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration());
1569 EXPECT_EQ(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1570 Line, Type, IsLocalToUnit, IsDefinition,
1571 Variable, StaticDataMemberDeclaration));
1572
1573 EXPECT_NE(N, MDGlobalVariable::get(Context, File, Name, LinkageName, File,
1574 Line, Type, IsLocalToUnit, IsDefinition,
1575 Variable, StaticDataMemberDeclaration));
1576 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, "other", LinkageName, File,
1577 Line, Type, IsLocalToUnit, IsDefinition,
1578 Variable, StaticDataMemberDeclaration));
1579 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, "other", File, Line,
1580 Type, IsLocalToUnit, IsDefinition,
1581 Variable, StaticDataMemberDeclaration));
1582 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, Scope,
1583 Line, Type, IsLocalToUnit, IsDefinition,
1584 Variable, StaticDataMemberDeclaration));
1585 EXPECT_NE(N,
1586 MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1587 Line + 1, Type, IsLocalToUnit, IsDefinition,
1588 Variable, StaticDataMemberDeclaration));
1589 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1590 Line, Scope, IsLocalToUnit, IsDefinition,
1591 Variable, StaticDataMemberDeclaration));
1592 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1593 Line, Type, !IsLocalToUnit, IsDefinition,
1594 Variable, StaticDataMemberDeclaration));
1595 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1596 Line, Type, IsLocalToUnit, !IsDefinition,
1597 Variable, StaticDataMemberDeclaration));
1598 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1599 Line, Type, IsLocalToUnit, IsDefinition,
1600 Type, StaticDataMemberDeclaration));
1601 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1602 Line, Type, IsLocalToUnit, IsDefinition,
1603 Variable, Type));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001604
1605 TempMDGlobalVariable Temp = N->clone();
1606 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001607}
1608
1609typedef MetadataTest MDLocalVariableTest;
1610
1611TEST_F(MDLocalVariableTest, get) {
1612 unsigned Tag = dwarf::DW_TAG_arg_variable;
1613 Metadata *Scope = MDTuple::getDistinct(Context, None);
1614 StringRef Name = "name";
1615 Metadata *File = MDTuple::getDistinct(Context, None);
1616 unsigned Line = 5;
1617 Metadata *Type = MDTuple::getDistinct(Context, None);
1618 unsigned Arg = 6;
1619 unsigned Flags = 7;
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +00001620 Metadata *InlinedAtScope = MDTuple::getDistinct(Context, None);
1621 Metadata *InlinedAt =
1622 MDLocation::getDistinct(Context, 10, 20, InlinedAtScope);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001623
1624 auto *N = MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1625 Arg, Flags, InlinedAt);
1626 EXPECT_EQ(Tag, N->getTag());
1627 EXPECT_EQ(Scope, N->getScope());
1628 EXPECT_EQ(Name, N->getName());
1629 EXPECT_EQ(File, N->getFile());
1630 EXPECT_EQ(Line, N->getLine());
1631 EXPECT_EQ(Type, N->getType());
1632 EXPECT_EQ(Arg, N->getArg());
1633 EXPECT_EQ(Flags, N->getFlags());
1634 EXPECT_EQ(InlinedAt, N->getInlinedAt());
1635 EXPECT_EQ(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1636 Arg, Flags, InlinedAt));
1637
1638 EXPECT_NE(N, MDLocalVariable::get(Context, dwarf::DW_TAG_auto_variable, Scope,
1639 Name, File, Line, Type, Arg, Flags,
1640 InlinedAt));
1641 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, File, Name, File, Line,
1642 Type, Arg, Flags, InlinedAt));
1643 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, "other", File, Line,
1644 Type, Arg, Flags, InlinedAt));
1645 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, Scope, Line,
1646 Type, Arg, Flags, InlinedAt));
1647 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line + 1,
1648 Type, Arg, Flags, InlinedAt));
1649 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line,
1650 Scope, Arg, Flags, InlinedAt));
1651 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1652 Arg + 1, Flags, InlinedAt));
1653 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1654 Arg, ~Flags, InlinedAt));
1655 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1656 Arg, Flags, Scope));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001657
1658 TempMDLocalVariable Temp = N->clone();
1659 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +00001660
1661 auto *Inlined = N->withoutInline();
1662 EXPECT_NE(N, Inlined);
1663 EXPECT_EQ(N->getTag(), Inlined->getTag());
1664 EXPECT_EQ(N->getScope(), Inlined->getScope());
1665 EXPECT_EQ(N->getName(), Inlined->getName());
1666 EXPECT_EQ(N->getFile(), Inlined->getFile());
1667 EXPECT_EQ(N->getLine(), Inlined->getLine());
1668 EXPECT_EQ(N->getType(), Inlined->getType());
1669 EXPECT_EQ(N->getArg(), Inlined->getArg());
1670 EXPECT_EQ(N->getFlags(), Inlined->getFlags());
1671 EXPECT_EQ(nullptr, Inlined->getInlinedAt());
1672 EXPECT_EQ(N, Inlined->withInline(cast<MDLocation>(InlinedAt)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001673}
1674
1675typedef MetadataTest MDExpressionTest;
1676
1677TEST_F(MDExpressionTest, get) {
1678 uint64_t Elements[] = {2, 6, 9, 78, 0};
1679 auto *N = MDExpression::get(Context, Elements);
1680 EXPECT_EQ(makeArrayRef(Elements), N->getElements());
1681 EXPECT_EQ(N, MDExpression::get(Context, Elements));
Duncan P. N. Exon Smithdddc5372015-02-10 01:36:46 +00001682
1683 EXPECT_EQ(5u, N->getNumElements());
1684 EXPECT_EQ(2u, N->getElement(0));
1685 EXPECT_EQ(6u, N->getElement(1));
1686 EXPECT_EQ(9u, N->getElement(2));
1687 EXPECT_EQ(78u, N->getElement(3));
1688 EXPECT_EQ(0u, N->getElement(4));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001689
1690 TempMDExpression Temp = N->clone();
1691 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001692}
1693
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +00001694TEST_F(MDExpressionTest, isValid) {
1695#define EXPECT_VALID(...) \
1696 do { \
1697 uint64_t Elements[] = {__VA_ARGS__}; \
1698 EXPECT_TRUE(MDExpression::get(Context, Elements)->isValid()); \
1699 } while (false)
1700#define EXPECT_INVALID(...) \
1701 do { \
1702 uint64_t Elements[] = {__VA_ARGS__}; \
1703 EXPECT_FALSE(MDExpression::get(Context, Elements)->isValid()); \
1704 } while (false)
1705
1706 // Empty expression should be valid.
1707 EXPECT_TRUE(MDExpression::get(Context, None));
1708
1709 // Valid constructions.
1710 EXPECT_VALID(dwarf::DW_OP_plus, 6);
1711 EXPECT_VALID(dwarf::DW_OP_deref);
1712 EXPECT_VALID(dwarf::DW_OP_bit_piece, 3, 7);
1713 EXPECT_VALID(dwarf::DW_OP_plus, 6, dwarf::DW_OP_deref);
1714 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6);
1715 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_bit_piece, 3, 7);
1716 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6, dwarf::DW_OP_bit_piece, 3, 7);
1717
1718 // Invalid constructions.
1719 EXPECT_INVALID(~0u);
1720 EXPECT_INVALID(dwarf::DW_OP_plus);
1721 EXPECT_INVALID(dwarf::DW_OP_bit_piece);
1722 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3);
1723 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_plus, 3);
1724 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_deref);
1725
1726#undef EXPECT_VALID
1727#undef EXPECT_INVALID
1728}
1729
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001730typedef MetadataTest MDObjCPropertyTest;
1731
1732TEST_F(MDObjCPropertyTest, get) {
1733 StringRef Name = "name";
1734 Metadata *File = MDTuple::getDistinct(Context, None);
1735 unsigned Line = 5;
1736 StringRef GetterName = "getter";
1737 StringRef SetterName = "setter";
1738 unsigned Attributes = 7;
1739 Metadata *Type = MDTuple::getDistinct(Context, None);
1740
1741 auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName,
1742 SetterName, Attributes, Type);
1743
1744 EXPECT_EQ(dwarf::DW_TAG_APPLE_property, N->getTag());
1745 EXPECT_EQ(Name, N->getName());
1746 EXPECT_EQ(File, N->getFile());
1747 EXPECT_EQ(Line, N->getLine());
1748 EXPECT_EQ(GetterName, N->getGetterName());
1749 EXPECT_EQ(SetterName, N->getSetterName());
1750 EXPECT_EQ(Attributes, N->getAttributes());
1751 EXPECT_EQ(Type, N->getType());
1752 EXPECT_EQ(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1753 SetterName, Attributes, Type));
1754
1755 EXPECT_NE(N, MDObjCProperty::get(Context, "other", File, Line, GetterName,
1756 SetterName, Attributes, Type));
1757 EXPECT_NE(N, MDObjCProperty::get(Context, Name, Type, Line, GetterName,
1758 SetterName, Attributes, Type));
1759 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line + 1, GetterName,
1760 SetterName, Attributes, Type));
1761 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, "other",
1762 SetterName, Attributes, Type));
1763 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1764 "other", Attributes, Type));
1765 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1766 SetterName, Attributes + 1, Type));
1767 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1768 SetterName, Attributes, File));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001769
1770 TempMDObjCProperty Temp = N->clone();
1771 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001772}
1773
1774typedef MetadataTest MDImportedEntityTest;
1775
1776TEST_F(MDImportedEntityTest, get) {
1777 unsigned Tag = dwarf::DW_TAG_imported_module;
1778 Metadata *Scope = MDTuple::getDistinct(Context, None);
1779 Metadata *Entity = MDTuple::getDistinct(Context, None);
1780 unsigned Line = 5;
1781 StringRef Name = "name";
1782
1783 auto *N = MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name);
1784
1785 EXPECT_EQ(Tag, N->getTag());
1786 EXPECT_EQ(Scope, N->getScope());
1787 EXPECT_EQ(Entity, N->getEntity());
1788 EXPECT_EQ(Line, N->getLine());
1789 EXPECT_EQ(Name, N->getName());
1790 EXPECT_EQ(N, MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name));
1791
1792 EXPECT_NE(N,
1793 MDImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration,
1794 Scope, Entity, Line, Name));
1795 EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Entity, Entity, Line, Name));
1796 EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, Scope, Line, Name));
1797 EXPECT_NE(N,
1798 MDImportedEntity::get(Context, Tag, Scope, Entity, Line + 1, Name));
1799 EXPECT_NE(N,
1800 MDImportedEntity::get(Context, Tag, Scope, Entity, Line, "other"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001801
1802 TempMDImportedEntity Temp = N->clone();
1803 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001804}
1805
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001806typedef MetadataTest MetadataAsValueTest;
1807
1808TEST_F(MetadataAsValueTest, MDNode) {
1809 MDNode *N = MDNode::get(Context, None);
1810 auto *V = MetadataAsValue::get(Context, N);
1811 EXPECT_TRUE(V->getType()->isMetadataTy());
1812 EXPECT_EQ(N, V->getMetadata());
1813
1814 auto *V2 = MetadataAsValue::get(Context, N);
1815 EXPECT_EQ(V, V2);
1816}
1817
1818TEST_F(MetadataAsValueTest, MDNodeMDNode) {
1819 MDNode *N = MDNode::get(Context, None);
1820 Metadata *Ops[] = {N};
1821 MDNode *N2 = MDNode::get(Context, Ops);
1822 auto *V = MetadataAsValue::get(Context, N2);
1823 EXPECT_TRUE(V->getType()->isMetadataTy());
1824 EXPECT_EQ(N2, V->getMetadata());
1825
1826 auto *V2 = MetadataAsValue::get(Context, N2);
1827 EXPECT_EQ(V, V2);
1828
1829 auto *V3 = MetadataAsValue::get(Context, N);
1830 EXPECT_TRUE(V3->getType()->isMetadataTy());
1831 EXPECT_NE(V, V3);
1832 EXPECT_EQ(N, V3->getMetadata());
1833}
1834
1835TEST_F(MetadataAsValueTest, MDNodeConstant) {
1836 auto *C = ConstantInt::getTrue(Context);
1837 auto *MD = ConstantAsMetadata::get(C);
1838 Metadata *Ops[] = {MD};
1839 auto *N = MDNode::get(Context, Ops);
1840
1841 auto *V = MetadataAsValue::get(Context, MD);
1842 EXPECT_TRUE(V->getType()->isMetadataTy());
1843 EXPECT_EQ(MD, V->getMetadata());
1844
1845 auto *V2 = MetadataAsValue::get(Context, N);
1846 EXPECT_EQ(MD, V2->getMetadata());
1847 EXPECT_EQ(V, V2);
1848}
1849
Duncan P. N. Exon Smith121eeff2014-12-12 19:24:33 +00001850typedef MetadataTest ValueAsMetadataTest;
1851
1852TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) {
1853 Type *Ty = Type::getInt1PtrTy(Context);
1854 std::unique_ptr<GlobalVariable> GV0(
1855 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
1856 auto *MD = ValueAsMetadata::get(GV0.get());
1857 EXPECT_TRUE(MD->getValue() == GV0.get());
1858 ASSERT_TRUE(GV0->use_empty());
1859
1860 std::unique_ptr<GlobalVariable> GV1(
1861 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
1862 GV0->replaceAllUsesWith(GV1.get());
1863 EXPECT_TRUE(MD->getValue() == GV1.get());
1864}
1865
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00001866TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
1867 // Create a constant.
1868 ConstantAsMetadata *CI = ConstantAsMetadata::get(
1869 ConstantInt::get(getGlobalContext(), APInt(8, 0)));
1870
1871 // Create a temporary to prevent nodes from resolving.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +00001872 auto Temp = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00001873
1874 // When the first operand of N1 gets reset to nullptr, it'll collide with N2.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +00001875 Metadata *Ops1[] = {CI, CI, Temp.get()};
1876 Metadata *Ops2[] = {nullptr, CI, Temp.get()};
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00001877
1878 auto *N1 = MDTuple::get(Context, Ops1);
1879 auto *N2 = MDTuple::get(Context, Ops2);
1880 ASSERT_NE(N1, N2);
1881
1882 // Tell metadata that the constant is getting deleted.
1883 //
1884 // After this, N1 will be invalid, so don't touch it.
1885 ValueAsMetadata::handleDeletion(CI->getValue());
1886 EXPECT_EQ(nullptr, N2->getOperand(0));
1887 EXPECT_EQ(nullptr, N2->getOperand(1));
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +00001888 EXPECT_EQ(Temp.get(), N2->getOperand(2));
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00001889
1890 // Clean up Temp for teardown.
1891 Temp->replaceAllUsesWith(nullptr);
1892}
1893
Duncan P. N. Exon Smith121eeff2014-12-12 19:24:33 +00001894typedef MetadataTest TrackingMDRefTest;
1895
1896TEST_F(TrackingMDRefTest, UpdatesOnRAUW) {
1897 Type *Ty = Type::getInt1PtrTy(Context);
1898 std::unique_ptr<GlobalVariable> GV0(
1899 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
1900 TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV0.get()));
1901 EXPECT_TRUE(MD->getValue() == GV0.get());
1902 ASSERT_TRUE(GV0->use_empty());
1903
1904 std::unique_ptr<GlobalVariable> GV1(
1905 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
1906 GV0->replaceAllUsesWith(GV1.get());
1907 EXPECT_TRUE(MD->getValue() == GV1.get());
1908
1909 // Reset it, so we don't inadvertently test deletion.
1910 MD.reset();
1911}
1912
1913TEST_F(TrackingMDRefTest, UpdatesOnDeletion) {
1914 Type *Ty = Type::getInt1PtrTy(Context);
1915 std::unique_ptr<GlobalVariable> GV(
1916 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
1917 TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV.get()));
1918 EXPECT_TRUE(MD->getValue() == GV.get());
1919 ASSERT_TRUE(GV->use_empty());
1920
1921 GV.reset();
1922 EXPECT_TRUE(!MD);
1923}
1924
Devang Patel0924b332009-07-30 00:03:41 +00001925TEST(NamedMDNodeTest, Search) {
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +00001926 LLVMContext Context;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001927 ConstantAsMetadata *C =
1928 ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 1));
1929 ConstantAsMetadata *C2 =
1930 ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 2));
Devang Patel0924b332009-07-30 00:03:41 +00001931
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001932 Metadata *const V = C;
1933 Metadata *const V2 = C2;
Jay Foad5514afe2011-04-21 19:59:31 +00001934 MDNode *n = MDNode::get(Context, V);
1935 MDNode *n2 = MDNode::get(Context, V2);
Devang Patel0924b332009-07-30 00:03:41 +00001936
Jeffrey Yasskin3d73d1a2010-03-13 01:39:20 +00001937 Module M("MyModule", Context);
Devang Patel0924b332009-07-30 00:03:41 +00001938 const char *Name = "llvm.NMD1";
Dan Gohman2637cc12010-07-21 23:38:33 +00001939 NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name);
1940 NMD->addOperand(n);
1941 NMD->addOperand(n2);
1942
Chris Lattnerbe354a62009-08-23 04:47:35 +00001943 std::string Str;
1944 raw_string_ostream oss(Str);
Devang Patel0924b332009-07-30 00:03:41 +00001945 NMD->print(oss);
Chris Lattner1e6e3672009-12-31 02:12:13 +00001946 EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n",
Devang Patel0924b332009-07-30 00:03:41 +00001947 oss.str().c_str());
1948}
Nick Lewycky49f89192009-04-04 07:22:01 +00001949}