blob: 694b08bae5cb678eb6ae748b454d87d718085e73 [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 {
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000064public:
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +000065 MetadataTest() : M("test", Context), Counter(0) {}
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000066
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +000067protected:
68 LLVMContext Context;
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +000069 Module M;
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000070 int Counter;
71
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +000072 MDNode *getNode() { return MDNode::get(Context, None); }
73 MDNode *getNode(Metadata *MD) { return MDNode::get(Context, MD); }
74 MDNode *getNode(Metadata *MD1, Metadata *MD2) {
75 Metadata *MDs[] = {MD1, MD2};
76 return MDNode::get(Context, MDs);
77 }
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +000078
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +000079 MDTuple *getTuple() { return MDTuple::getDistinct(Context, None); }
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +000080 MDSubroutineType *getSubroutineType() {
81 return MDSubroutineType::getDistinct(Context, 0, getNode(nullptr));
82 }
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +000083 MDSubprogram *getSubprogram() {
84 return MDSubprogram::getDistinct(Context, nullptr, "", "", nullptr, 0,
85 nullptr, false, false, 0, nullptr, 0, 0, 0,
86 0);
87 }
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +000088 MDScopeRef getSubprogramRef() { return getSubprogram()->getRef(); }
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000089 MDFile *getFile() {
90 return MDFile::getDistinct(Context, "file.c", "/path/to/dir");
91 }
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +000092 MDTypeRef getBasicType(StringRef Name) {
93 return MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name)
94 ->getRef();
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000095 }
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +000096 MDTypeRef getDerivedType() {
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +000097 return MDDerivedType::getDistinct(Context, dwarf::DW_TAG_pointer_type, "",
98 nullptr, 0, nullptr,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +000099 getBasicType("basictype"), 1, 2, 0, 0)
100 ->getRef();
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000101 }
102 ConstantAsMetadata *getConstantAsMetadata() {
103 return ConstantAsMetadata::get(
104 ConstantInt::get(Type::getInt32Ty(Context), Counter++));
105 }
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000106 MDTypeRef getCompositeType() {
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000107 return MDCompositeType::getDistinct(
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000108 Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr,
109 nullptr, 32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "")
110 ->getRef();
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000111 }
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000112 ConstantAsMetadata *getFunctionAsMetadata(StringRef Name) {
113 return ConstantAsMetadata::get(M.getOrInsertFunction(
114 Name, FunctionType::get(Type::getVoidTy(Context), None, false)));
115 }
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000116};
117typedef MetadataTest MDStringTest;
Owen Anderson23587322009-07-31 21:38:10 +0000118
Nick Lewycky49f89192009-04-04 07:22:01 +0000119// Test that construction of MDString with different value produces different
120// MDString objects, even with the same string pointer and nulls in the string.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000121TEST_F(MDStringTest, CreateDifferent) {
Nick Lewycky49f89192009-04-04 07:22:01 +0000122 char x[3] = { 'f', 0, 'A' };
Owen Anderson23587322009-07-31 21:38:10 +0000123 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +0000124 x[2] = 'B';
Owen Anderson23587322009-07-31 21:38:10 +0000125 MDString *s2 = MDString::get(Context, StringRef(&x[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +0000126 EXPECT_NE(s1, s2);
127}
128
129// Test that creation of MDStrings with the same string contents produces the
130// same MDString object, even with different pointers.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000131TEST_F(MDStringTest, CreateSame) {
Nick Lewycky49f89192009-04-04 07:22:01 +0000132 char x[4] = { 'a', 'b', 'c', 'X' };
133 char y[4] = { 'a', 'b', 'c', 'Y' };
134
Owen Anderson23587322009-07-31 21:38:10 +0000135 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
136 MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
Nick Lewycky49f89192009-04-04 07:22:01 +0000137 EXPECT_EQ(s1, s2);
138}
139
140// Test that MDString prints out the string we fed it.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000141TEST_F(MDStringTest, PrintingSimple) {
Nick Lewycky49f89192009-04-04 07:22:01 +0000142 char *str = new char[13];
143 strncpy(str, "testing 1 2 3", 13);
Owen Anderson23587322009-07-31 21:38:10 +0000144 MDString *s = MDString::get(Context, StringRef(str, 13));
Nick Lewycky49f89192009-04-04 07:22:01 +0000145 strncpy(str, "aaaaaaaaaaaaa", 13);
146 delete[] str;
147
Chris Lattnerbe354a62009-08-23 04:47:35 +0000148 std::string Str;
149 raw_string_ostream oss(Str);
Nick Lewycky49f89192009-04-04 07:22:01 +0000150 s->print(oss);
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000151 EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str());
Nick Lewycky49f89192009-04-04 07:22:01 +0000152}
153
154// Test printing of MDString with non-printable characters.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000155TEST_F(MDStringTest, PrintingComplex) {
Jeffrey Yasskin065c3572011-08-30 20:53:29 +0000156 char str[5] = {0, '\n', '"', '\\', (char)-1};
Owen Anderson23587322009-07-31 21:38:10 +0000157 MDString *s = MDString::get(Context, StringRef(str+0, 5));
Chris Lattnerbe354a62009-08-23 04:47:35 +0000158 std::string Str;
159 raw_string_ostream oss(Str);
Nick Lewycky49f89192009-04-04 07:22:01 +0000160 s->print(oss);
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000161 EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str());
Nick Lewycky49f89192009-04-04 07:22:01 +0000162}
163
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000164typedef MetadataTest MDNodeTest;
165
Nick Lewycky49f89192009-04-04 07:22:01 +0000166// Test the two constructors, and containing other Constants.
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000167TEST_F(MDNodeTest, Simple) {
Nick Lewycky49f89192009-04-04 07:22:01 +0000168 char x[3] = { 'a', 'b', 'c' };
169 char y[3] = { '1', '2', '3' };
170
Owen Anderson23587322009-07-31 21:38:10 +0000171 MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
172 MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000173 ConstantAsMetadata *CI = ConstantAsMetadata::get(
174 ConstantInt::get(getGlobalContext(), APInt(8, 0)));
Nick Lewycky49f89192009-04-04 07:22:01 +0000175
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000176 std::vector<Metadata *> V;
Nick Lewycky49f89192009-04-04 07:22:01 +0000177 V.push_back(s1);
178 V.push_back(CI);
179 V.push_back(s2);
180
Jay Foad5514afe2011-04-21 19:59:31 +0000181 MDNode *n1 = MDNode::get(Context, V);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000182 Metadata *const c1 = n1;
Jay Foad5514afe2011-04-21 19:59:31 +0000183 MDNode *n2 = MDNode::get(Context, c1);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000184 Metadata *const c2 = n2;
Jay Foad5514afe2011-04-21 19:59:31 +0000185 MDNode *n3 = MDNode::get(Context, V);
Duncan Sands26a80f32012-03-31 08:20:11 +0000186 MDNode *n4 = MDNode::getIfExists(Context, V);
187 MDNode *n5 = MDNode::getIfExists(Context, c1);
188 MDNode *n6 = MDNode::getIfExists(Context, c2);
Nick Lewycky49f89192009-04-04 07:22:01 +0000189 EXPECT_NE(n1, n2);
Devang Patelf7188322009-09-03 01:39:20 +0000190 EXPECT_EQ(n1, n3);
Duncan Sands26a80f32012-03-31 08:20:11 +0000191 EXPECT_EQ(n4, n1);
192 EXPECT_EQ(n5, n2);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000193 EXPECT_EQ(n6, (Metadata *)nullptr);
Nick Lewycky49f89192009-04-04 07:22:01 +0000194
Chris Lattner9b493022009-12-31 01:22:29 +0000195 EXPECT_EQ(3u, n1->getNumOperands());
196 EXPECT_EQ(s1, n1->getOperand(0));
197 EXPECT_EQ(CI, n1->getOperand(1));
198 EXPECT_EQ(s2, n1->getOperand(2));
Nick Lewycky49f89192009-04-04 07:22:01 +0000199
Chris Lattner9b493022009-12-31 01:22:29 +0000200 EXPECT_EQ(1u, n2->getNumOperands());
201 EXPECT_EQ(n1, n2->getOperand(0));
Nick Lewycky49f89192009-04-04 07:22:01 +0000202}
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000203
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +0000204TEST_F(MDNodeTest, Delete) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000205 Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1);
206 Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext()));
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000207
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000208 Metadata *const V = LocalAsMetadata::get(I);
Jay Foad5514afe2011-04-21 19:59:31 +0000209 MDNode *n = MDNode::get(Context, V);
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000210 TrackingMDRef wvh(n);
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000211
212 EXPECT_EQ(n, wvh);
213
214 delete I;
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +0000215}
Devang Patel0924b332009-07-30 00:03:41 +0000216
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000217TEST_F(MDNodeTest, SelfReference) {
Duncan P. N. Exon Smith8c662732014-12-16 07:45:05 +0000218 // !0 = !{!0}
219 // !1 = !{!0}
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000220 {
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000221 auto Temp = MDNode::getTemporary(Context, None);
222 Metadata *Args[] = {Temp.get()};
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000223 MDNode *Self = MDNode::get(Context, Args);
224 Self->replaceOperandWith(0, Self);
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000225 ASSERT_EQ(Self, Self->getOperand(0));
226
227 // Self-references should be distinct, so MDNode::get() should grab a
228 // uniqued node that references Self, not Self.
229 Args[0] = Self;
230 MDNode *Ref1 = MDNode::get(Context, Args);
231 MDNode *Ref2 = MDNode::get(Context, Args);
232 EXPECT_NE(Self, Ref1);
233 EXPECT_EQ(Ref1, Ref2);
234 }
235
Duncan P. N. Exon Smith8c662732014-12-16 07:45:05 +0000236 // !0 = !{!0, !{}}
237 // !1 = !{!0, !{}}
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000238 {
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000239 auto Temp = MDNode::getTemporary(Context, None);
240 Metadata *Args[] = {Temp.get(), MDNode::get(Context, None)};
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000241 MDNode *Self = MDNode::get(Context, Args);
242 Self->replaceOperandWith(0, Self);
Duncan P. N. Exon Smithac8ee282014-12-07 19:52:06 +0000243 ASSERT_EQ(Self, Self->getOperand(0));
244
245 // Self-references should be distinct, so MDNode::get() should grab a
246 // uniqued node that references Self, not Self itself.
247 Args[0] = Self;
248 MDNode *Ref1 = MDNode::get(Context, Args);
249 MDNode *Ref2 = MDNode::get(Context, Args);
250 EXPECT_NE(Self, Ref1);
251 EXPECT_EQ(Ref1, Ref2);
252 }
253}
254
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000255TEST_F(MDNodeTest, Print) {
256 Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7);
257 MDString *S = MDString::get(Context, "foo");
258 MDNode *N0 = getNode();
259 MDNode *N1 = getNode(N0);
260 MDNode *N2 = getNode(N0, N1);
261
262 Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2};
263 MDNode *N = MDNode::get(Context, Args);
264
265 std::string Expected;
266 {
267 raw_string_ostream OS(Expected);
Duncan P. N. Exon Smithd6d70e72015-03-14 20:19:36 +0000268 OS << "<" << (void *)N << "> = !{";
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000269 C->printAsOperand(OS);
270 OS << ", ";
Duncan P. N. Exon Smithbb7d2fb2014-12-16 07:40:31 +0000271 S->printAsOperand(OS);
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000272 OS << ", null";
273 MDNode *Nodes[] = {N0, N1, N2};
274 for (auto *Node : Nodes)
275 OS << ", <" << (void *)Node << ">";
Duncan P. N. Exon Smith738889f2015-02-25 22:46:38 +0000276 OS << "}";
Duncan P. N. Exon Smithfee167f2014-12-16 07:09:37 +0000277 }
278
279 std::string Actual;
280 {
281 raw_string_ostream OS(Actual);
282 N->print(OS);
283 }
284
285 EXPECT_EQ(Expected, Actual);
286}
287
Duncan P. N. Exon Smithd6d70e72015-03-14 20:19:36 +0000288#define EXPECT_PRINTER_EQ(EXPECTED, PRINT) \
289 do { \
290 std::string Actual_; \
291 raw_string_ostream OS(Actual_); \
292 PRINT; \
293 OS.flush(); \
294 std::string Expected_(EXPECTED); \
295 EXPECT_EQ(Expected_, Actual_); \
296 } while (false)
297
Duncan P. N. Exon Smith3d510662015-03-16 21:21:10 +0000298TEST_F(MDNodeTest, PrintTemporary) {
299 MDNode *Arg = getNode();
300 TempMDNode Temp = MDNode::getTemporary(Context, Arg);
301 MDNode *N = getNode(Temp.get());
302 Module M("test", Context);
303 NamedMDNode *NMD = M.getOrInsertNamedMetadata("named");
304 NMD->addOperand(N);
305
306 EXPECT_PRINTER_EQ("!0 = !{!1}", N->print(OS, &M));
307 EXPECT_PRINTER_EQ("!1 = <temporary!> !{!2}", Temp->print(OS, &M));
308 EXPECT_PRINTER_EQ("!2 = !{}", Arg->print(OS, &M));
309
310 // Cleanup.
311 Temp->replaceAllUsesWith(Arg);
312}
313
Duncan P. N. Exon Smithd6d70e72015-03-14 20:19:36 +0000314TEST_F(MDNodeTest, PrintFromModule) {
315 Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7);
316 MDString *S = MDString::get(Context, "foo");
317 MDNode *N0 = getNode();
318 MDNode *N1 = getNode(N0);
319 MDNode *N2 = getNode(N0, N1);
320
321 Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2};
322 MDNode *N = MDNode::get(Context, Args);
323 Module M("test", Context);
324 NamedMDNode *NMD = M.getOrInsertNamedMetadata("named");
325 NMD->addOperand(N);
326
327 std::string Expected;
328 {
329 raw_string_ostream OS(Expected);
330 OS << "!0 = !{";
331 C->printAsOperand(OS);
332 OS << ", ";
333 S->printAsOperand(OS);
334 OS << ", null, !1, !2, !3}";
335 }
336
337 EXPECT_PRINTER_EQ(Expected, N->print(OS, &M));
338}
339
340TEST_F(MDNodeTest, PrintFromFunction) {
341 Module M("test", Context);
342 auto *FTy = FunctionType::get(Type::getVoidTy(Context), false);
343 auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M);
344 auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M);
345 auto *BB0 = BasicBlock::Create(Context, "entry", F0);
346 auto *BB1 = BasicBlock::Create(Context, "entry", F1);
347 auto *R0 = ReturnInst::Create(Context, BB0);
348 auto *R1 = ReturnInst::Create(Context, BB1);
349 auto *N0 = MDNode::getDistinct(Context, None);
350 auto *N1 = MDNode::getDistinct(Context, None);
351 R0->setMetadata("md", N0);
352 R1->setMetadata("md", N1);
353
354 EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M));
355 EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M));
356}
357
358TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
359 Module M("test", Context);
360
361 auto *Intrinsic =
362 Function::Create(FunctionType::get(Type::getVoidTy(Context),
363 Type::getMetadataTy(Context), false),
364 GlobalValue::ExternalLinkage, "llvm.intrinsic", &M);
365
366 auto *FTy = FunctionType::get(Type::getVoidTy(Context), false);
367 auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M);
368 auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M);
369 auto *BB0 = BasicBlock::Create(Context, "entry", F0);
370 auto *BB1 = BasicBlock::Create(Context, "entry", F1);
371 auto *N0 = MDNode::getDistinct(Context, None);
372 auto *N1 = MDNode::getDistinct(Context, None);
373 auto *MAV0 = MetadataAsValue::get(Context, N0);
374 auto *MAV1 = MetadataAsValue::get(Context, N1);
375 CallInst::Create(Intrinsic, MAV0, "", BB0);
376 CallInst::Create(Intrinsic, MAV1, "", BB1);
377
378 EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS));
379 EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS));
380 EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false));
381 EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false));
382 EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true));
383 EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true));
384}
385#undef EXPECT_PRINTER_EQ
386
Duncan P. N. Exon Smithbcd960a2015-01-05 23:31:54 +0000387TEST_F(MDNodeTest, NullOperand) {
388 // metadata !{}
389 MDNode *Empty = MDNode::get(Context, None);
390
391 // metadata !{metadata !{}}
392 Metadata *Ops[] = {Empty};
393 MDNode *N = MDNode::get(Context, Ops);
394 ASSERT_EQ(Empty, N->getOperand(0));
395
396 // metadata !{metadata !{}} => metadata !{null}
397 N->replaceOperandWith(0, nullptr);
398 ASSERT_EQ(nullptr, N->getOperand(0));
399
400 // metadata !{null}
401 Ops[0] = nullptr;
402 MDNode *NullOp = MDNode::get(Context, Ops);
403 ASSERT_EQ(nullptr, NullOp->getOperand(0));
404 EXPECT_EQ(N, NullOp);
405}
406
Duncan P. N. Exon Smith136ea3f2015-01-07 21:35:38 +0000407TEST_F(MDNodeTest, DistinctOnUniquingCollision) {
408 // !{}
409 MDNode *Empty = MDNode::get(Context, None);
410 ASSERT_TRUE(Empty->isResolved());
411 EXPECT_FALSE(Empty->isDistinct());
412
413 // !{!{}}
414 Metadata *Wrapped1Ops[] = {Empty};
415 MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops);
416 ASSERT_EQ(Empty, Wrapped1->getOperand(0));
417 ASSERT_TRUE(Wrapped1->isResolved());
418 EXPECT_FALSE(Wrapped1->isDistinct());
419
420 // !{!{!{}}}
421 Metadata *Wrapped2Ops[] = {Wrapped1};
422 MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops);
423 ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0));
424 ASSERT_TRUE(Wrapped2->isResolved());
425 EXPECT_FALSE(Wrapped2->isDistinct());
426
427 // !{!{!{}}} => !{!{}}
428 Wrapped2->replaceOperandWith(0, Empty);
429 ASSERT_EQ(Empty, Wrapped2->getOperand(0));
430 EXPECT_TRUE(Wrapped2->isDistinct());
431 EXPECT_FALSE(Wrapped1->isDistinct());
432}
433
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000434TEST_F(MDNodeTest, getDistinct) {
435 // !{}
436 MDNode *Empty = MDNode::get(Context, None);
437 ASSERT_TRUE(Empty->isResolved());
438 ASSERT_FALSE(Empty->isDistinct());
439 ASSERT_EQ(Empty, MDNode::get(Context, None));
440
441 // distinct !{}
442 MDNode *Distinct1 = MDNode::getDistinct(Context, None);
443 MDNode *Distinct2 = MDNode::getDistinct(Context, None);
444 EXPECT_TRUE(Distinct1->isResolved());
445 EXPECT_TRUE(Distinct2->isDistinct());
446 EXPECT_NE(Empty, Distinct1);
447 EXPECT_NE(Empty, Distinct2);
448 EXPECT_NE(Distinct1, Distinct2);
449
450 // !{}
451 ASSERT_EQ(Empty, MDNode::get(Context, None));
452}
453
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000454TEST_F(MDNodeTest, isUniqued) {
455 MDNode *U = MDTuple::get(Context, None);
456 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000457 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000458 EXPECT_TRUE(U->isUniqued());
459 EXPECT_FALSE(D->isUniqued());
460 EXPECT_FALSE(T->isUniqued());
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000461}
462
463TEST_F(MDNodeTest, isDistinct) {
464 MDNode *U = MDTuple::get(Context, None);
465 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000466 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000467 EXPECT_FALSE(U->isDistinct());
468 EXPECT_TRUE(D->isDistinct());
469 EXPECT_FALSE(T->isDistinct());
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000470}
471
472TEST_F(MDNodeTest, isTemporary) {
473 MDNode *U = MDTuple::get(Context, None);
474 MDNode *D = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000475 auto T = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smithde03a8b2015-01-19 18:45:35 +0000476 EXPECT_FALSE(U->isTemporary());
477 EXPECT_FALSE(D->isTemporary());
478 EXPECT_TRUE(T->isTemporary());
Duncan P. N. Exon Smithd1474ee2015-01-12 18:41:26 +0000479}
480
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000481TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
482 // temporary !{}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000483 auto Temp = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000484 ASSERT_FALSE(Temp->isResolved());
485
486 // distinct !{temporary !{}}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000487 Metadata *Ops[] = {Temp.get()};
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000488 MDNode *Distinct = MDNode::getDistinct(Context, Ops);
489 EXPECT_TRUE(Distinct->isResolved());
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000490 EXPECT_EQ(Temp.get(), Distinct->getOperand(0));
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000491
492 // temporary !{} => !{}
493 MDNode *Empty = MDNode::get(Context, None);
494 Temp->replaceAllUsesWith(Empty);
Duncan P. N. Exon Smith5e5b8502015-01-07 22:24:46 +0000495 EXPECT_EQ(Empty, Distinct->getOperand(0));
496}
497
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000498TEST_F(MDNodeTest, handleChangedOperandRecursion) {
499 // !0 = !{}
500 MDNode *N0 = MDNode::get(Context, None);
501
502 // !1 = !{!3, null}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000503 auto Temp3 = MDTuple::getTemporary(Context, None);
504 Metadata *Ops1[] = {Temp3.get(), nullptr};
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000505 MDNode *N1 = MDNode::get(Context, Ops1);
506
507 // !2 = !{!3, !0}
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000508 Metadata *Ops2[] = {Temp3.get(), N0};
Duncan P. N. Exon Smith5f461892015-01-12 19:22:04 +0000509 MDNode *N2 = MDNode::get(Context, Ops2);
510
511 // !3 = !{!2}
512 Metadata *Ops3[] = {N2};
513 MDNode *N3 = MDNode::get(Context, Ops3);
514 Temp3->replaceAllUsesWith(N3);
515
516 // !4 = !{!1}
517 Metadata *Ops4[] = {N1};
518 MDNode *N4 = MDNode::get(Context, Ops4);
519
520 // Confirm that the cycle prevented RAUW from getting dropped.
521 EXPECT_TRUE(N0->isResolved());
522 EXPECT_FALSE(N1->isResolved());
523 EXPECT_FALSE(N2->isResolved());
524 EXPECT_FALSE(N3->isResolved());
525 EXPECT_FALSE(N4->isResolved());
526
527 // Create a couple of distinct nodes to observe what's going on.
528 //
529 // !5 = distinct !{!2}
530 // !6 = distinct !{!3}
531 Metadata *Ops5[] = {N2};
532 MDNode *N5 = MDNode::getDistinct(Context, Ops5);
533 Metadata *Ops6[] = {N3};
534 MDNode *N6 = MDNode::getDistinct(Context, Ops6);
535
536 // Mutate !2 to look like !1, causing a uniquing collision (and an RAUW).
537 // This will ripple up, with !3 colliding with !4, and RAUWing. Since !2
538 // references !3, this can cause a re-entry of handleChangedOperand() when !3
539 // is not ready for it.
540 //
541 // !2->replaceOperandWith(1, nullptr)
542 // !2: !{!3, !0} => !{!3, null}
543 // !2->replaceAllUsesWith(!1)
544 // !3: !{!2] => !{!1}
545 // !3->replaceAllUsesWith(!4)
546 N2->replaceOperandWith(1, nullptr);
547
548 // If all has gone well, N2 and N3 will have been RAUW'ed and deleted from
549 // under us. Just check that the other nodes are sane.
550 //
551 // !1 = !{!4, null}
552 // !4 = !{!1}
553 // !5 = distinct !{!1}
554 // !6 = distinct !{!4}
555 EXPECT_EQ(N4, N1->getOperand(0));
556 EXPECT_EQ(N1, N4->getOperand(0));
557 EXPECT_EQ(N1, N5->getOperand(0));
558 EXPECT_EQ(N4, N6->getOperand(0));
559}
560
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000561TEST_F(MDNodeTest, replaceResolvedOperand) {
562 // Check code for replacing one resolved operand with another. If doing this
563 // directly (via replaceOperandWith()) becomes illegal, change the operand to
564 // a global value that gets RAUW'ed.
565 //
566 // Use a temporary node to keep N from being resolved.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000567 auto Temp = MDTuple::getTemporary(Context, None);
568 Metadata *Ops[] = {nullptr, Temp.get()};
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000569
NAKAMURA Takumi2f8f0542015-01-13 08:13:46 +0000570 MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>());
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000571 MDNode *N = MDTuple::get(Context, Ops);
572 EXPECT_EQ(nullptr, N->getOperand(0));
573 ASSERT_FALSE(N->isResolved());
574
575 // Check code for replacing resolved nodes.
576 N->replaceOperandWith(0, Empty);
577 EXPECT_EQ(Empty, N->getOperand(0));
578
579 // Check code for adding another unresolved operand.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000580 N->replaceOperandWith(0, Temp.get());
581 EXPECT_EQ(Temp.get(), N->getOperand(0));
Duncan P. N. Exon Smith845755c42015-01-13 00:46:34 +0000582
583 // Remove the references to Temp; required for teardown.
584 Temp->replaceAllUsesWith(nullptr);
585}
586
Duncan P. N. Exon Smithe3353092015-01-19 22:24:52 +0000587TEST_F(MDNodeTest, replaceWithUniqued) {
588 auto *Empty = MDTuple::get(Context, None);
589 MDTuple *FirstUniqued;
590 {
591 Metadata *Ops[] = {Empty};
592 auto Temp = MDTuple::getTemporary(Context, Ops);
593 EXPECT_TRUE(Temp->isTemporary());
594
595 // Don't expect a collision.
596 auto *Current = Temp.get();
597 FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp));
598 EXPECT_TRUE(FirstUniqued->isUniqued());
599 EXPECT_TRUE(FirstUniqued->isResolved());
600 EXPECT_EQ(Current, FirstUniqued);
601 }
602 {
603 Metadata *Ops[] = {Empty};
604 auto Temp = MDTuple::getTemporary(Context, Ops);
605 EXPECT_TRUE(Temp->isTemporary());
606
607 // Should collide with Uniqued above this time.
608 auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
609 EXPECT_TRUE(Uniqued->isUniqued());
610 EXPECT_TRUE(Uniqued->isResolved());
611 EXPECT_EQ(FirstUniqued, Uniqued);
612 }
613 {
614 auto Unresolved = MDTuple::getTemporary(Context, None);
615 Metadata *Ops[] = {Unresolved.get()};
616 auto Temp = MDTuple::getTemporary(Context, Ops);
617 EXPECT_TRUE(Temp->isTemporary());
618
619 // Shouldn't be resolved.
620 auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
621 EXPECT_TRUE(Uniqued->isUniqued());
622 EXPECT_FALSE(Uniqued->isResolved());
623
624 // Should be a different node.
625 EXPECT_NE(FirstUniqued, Uniqued);
626
627 // Should resolve when we update its node (note: be careful to avoid a
628 // collision with any other nodes above).
629 Uniqued->replaceOperandWith(0, nullptr);
630 EXPECT_TRUE(Uniqued->isResolved());
631 }
632}
633
Duncan P. N. Exon Smith014f1b82015-03-31 21:05:06 +0000634TEST_F(MDNodeTest, replaceWithUniquedResolvingOperand) {
Duncan P. N. Exon Smithcb33d6f2015-03-31 20:50:50 +0000635 // temp !{}
636 MDTuple *Op = MDTuple::getTemporary(Context, None).release();
637 EXPECT_FALSE(Op->isResolved());
638
639 // temp !{temp !{}}
640 Metadata *Ops[] = {Op};
641 MDTuple *N = MDTuple::getTemporary(Context, Ops).release();
642 EXPECT_FALSE(N->isResolved());
643
644 // temp !{temp !{}} => !{temp !{}}
645 ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N)));
646 EXPECT_FALSE(N->isResolved());
647
648 // !{temp !{}} => !{!{}}
649 ASSERT_EQ(Op, MDNode::replaceWithUniqued(TempMDTuple(Op)));
650 EXPECT_TRUE(Op->isResolved());
651 EXPECT_TRUE(N->isResolved());
652}
653
Duncan P. N. Exon Smith014f1b82015-03-31 21:05:06 +0000654TEST_F(MDNodeTest, replaceWithUniquedChangingOperand) {
Duncan P. N. Exon Smithcb33d6f2015-03-31 20:50:50 +0000655 // i1* @GV
656 Type *Ty = Type::getInt1PtrTy(Context);
657 std::unique_ptr<GlobalVariable> GV(
658 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
659 ConstantAsMetadata *Op = ConstantAsMetadata::get(GV.get());
660
661 // temp !{i1* @GV}
662 Metadata *Ops[] = {Op};
663 MDTuple *N = MDTuple::getTemporary(Context, Ops).release();
664
665 // temp !{i1* @GV} => !{i1* @GV}
666 ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N)));
667 ASSERT_TRUE(N->isUniqued());
668
669 // !{i1* @GV} => !{null}
670 GV.reset();
671 ASSERT_TRUE(N->isUniqued());
672 Metadata *NullOps[] = {nullptr};
673 ASSERT_EQ(N, MDTuple::get(Context, NullOps));
674}
675
Duncan P. N. Exon Smithe3353092015-01-19 22:24:52 +0000676TEST_F(MDNodeTest, replaceWithDistinct) {
677 {
678 auto *Empty = MDTuple::get(Context, None);
679 Metadata *Ops[] = {Empty};
680 auto Temp = MDTuple::getTemporary(Context, Ops);
681 EXPECT_TRUE(Temp->isTemporary());
682
683 // Don't expect a collision.
684 auto *Current = Temp.get();
685 auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
686 EXPECT_TRUE(Distinct->isDistinct());
687 EXPECT_TRUE(Distinct->isResolved());
688 EXPECT_EQ(Current, Distinct);
689 }
690 {
691 auto Unresolved = MDTuple::getTemporary(Context, None);
692 Metadata *Ops[] = {Unresolved.get()};
693 auto Temp = MDTuple::getTemporary(Context, Ops);
694 EXPECT_TRUE(Temp->isTemporary());
695
696 // Don't expect a collision.
697 auto *Current = Temp.get();
698 auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
699 EXPECT_TRUE(Distinct->isDistinct());
700 EXPECT_TRUE(Distinct->isResolved());
701 EXPECT_EQ(Current, Distinct);
702
703 // Cleanup; required for teardown.
704 Unresolved->replaceAllUsesWith(nullptr);
705 }
706}
707
Duncan P. N. Exon Smith4ee4a982015-02-10 19:13:46 +0000708TEST_F(MDNodeTest, replaceWithPermanent) {
709 Metadata *Ops[] = {nullptr};
710 auto Temp = MDTuple::getTemporary(Context, Ops);
711 auto *T = Temp.get();
712
713 // U is a normal, uniqued node that references T.
714 auto *U = MDTuple::get(Context, T);
715 EXPECT_TRUE(U->isUniqued());
716
717 // Make Temp self-referencing.
718 Temp->replaceOperandWith(0, T);
719
720 // Try to uniquify Temp. This should, despite the name in the API, give a
721 // 'distinct' node, since self-references aren't allowed to be uniqued.
722 //
723 // Since it's distinct, N should have the same address as when it was a
724 // temporary (i.e., be equal to T not U).
725 auto *N = MDNode::replaceWithPermanent(std::move(Temp));
726 EXPECT_EQ(N, T);
727 EXPECT_TRUE(N->isDistinct());
728
729 // U should be the canonical unique node with N as the argument.
730 EXPECT_EQ(U, MDTuple::get(Context, N));
731 EXPECT_TRUE(U->isUniqued());
732
733 // This temporary should collide with U when replaced, but it should still be
734 // uniqued.
735 EXPECT_EQ(U, MDNode::replaceWithPermanent(MDTuple::getTemporary(Context, N)));
736 EXPECT_TRUE(U->isUniqued());
737
738 // This temporary should become a new uniqued node.
739 auto Temp2 = MDTuple::getTemporary(Context, U);
740 auto *V = Temp2.get();
741 EXPECT_EQ(V, MDNode::replaceWithPermanent(std::move(Temp2)));
742 EXPECT_TRUE(V->isUniqued());
743 EXPECT_EQ(U, V->getOperand(0));
744}
745
Duncan P. N. Exon Smith8d536972015-01-22 21:36:45 +0000746TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) {
747 TrackingMDRef Ref;
748 EXPECT_EQ(nullptr, Ref.get());
749 {
750 auto Temp = MDTuple::getTemporary(Context, None);
751 Ref.reset(Temp.get());
752 EXPECT_EQ(Temp.get(), Ref.get());
753 }
754 EXPECT_EQ(nullptr, Ref.get());
755}
756
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000757typedef MetadataTest MDLocationTest;
758
759TEST_F(MDLocationTest, Overflow) {
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000760 MDSubprogram *N = getSubprogram();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000761 {
762 MDLocation *L = MDLocation::get(Context, 2, 7, N);
763 EXPECT_EQ(2u, L->getLine());
764 EXPECT_EQ(7u, L->getColumn());
765 }
Duncan P. N. Exon Smith2f5bb312015-01-16 17:33:08 +0000766 unsigned U16 = 1u << 16;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000767 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000768 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 - 1, N);
769 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smith2f5bb312015-01-16 17:33:08 +0000770 EXPECT_EQ(U16 - 1, L->getColumn());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000771 }
772 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000773 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16, N);
774 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000775 EXPECT_EQ(0u, L->getColumn());
776 }
777 {
Duncan P. N. Exon Smithaf677eb2015-02-06 22:50:13 +0000778 MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 + 1, N);
779 EXPECT_EQ(UINT32_MAX, L->getLine());
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000780 EXPECT_EQ(0u, L->getColumn());
781 }
782}
783
784TEST_F(MDLocationTest, getDistinct) {
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000785 MDNode *N = getSubprogram();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000786 MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N);
787 EXPECT_TRUE(L0->isDistinct());
788 MDLocation *L1 = MDLocation::get(Context, 2, 7, N);
789 EXPECT_FALSE(L1->isDistinct());
790 EXPECT_EQ(L1, MDLocation::get(Context, 2, 7, N));
791}
792
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000793TEST_F(MDLocationTest, getTemporary) {
794 MDNode *N = MDNode::get(Context, None);
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +0000795 auto L = MDLocation::getTemporary(Context, 2, 7, N);
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000796 EXPECT_TRUE(L->isTemporary());
797 EXPECT_FALSE(L->isResolved());
Duncan P. N. Exon Smith799e56a2015-01-19 20:37:44 +0000798}
799
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000800typedef MetadataTest GenericDebugNodeTest;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000801
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000802TEST_F(GenericDebugNodeTest, get) {
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000803 StringRef Header = "header";
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000804 auto *Empty = MDNode::get(Context, None);
805 Metadata *Ops1[] = {Empty};
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000806 auto *N = GenericDebugNode::get(Context, 15, Header, Ops1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000807 EXPECT_EQ(15u, N->getTag());
808 EXPECT_EQ(2u, N->getNumOperands());
809 EXPECT_EQ(Header, N->getHeader());
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000810 EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000811 EXPECT_EQ(1u, N->getNumDwarfOperands());
812 EXPECT_EQ(Empty, N->getDwarfOperand(0));
813 EXPECT_EQ(Empty, N->getOperand(1));
814 ASSERT_TRUE(N->isUniqued());
815
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000816 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000817
818 N->replaceOperandWith(1, nullptr);
819 EXPECT_EQ(15u, N->getTag());
820 EXPECT_EQ(Header, N->getHeader());
821 EXPECT_EQ(nullptr, N->getDwarfOperand(0));
822 ASSERT_TRUE(N->isUniqued());
823
824 Metadata *Ops2[] = {nullptr};
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000825 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000826
827 N->replaceDwarfOperandWith(0, Empty);
828 EXPECT_EQ(15u, N->getTag());
829 EXPECT_EQ(Header, N->getHeader());
830 EXPECT_EQ(Empty, N->getDwarfOperand(0));
831 ASSERT_TRUE(N->isUniqued());
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000832 EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000833
834 TempGenericDebugNode Temp = N->clone();
835 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000836}
837
Duncan P. N. Exon Smithe8b5e492015-01-22 22:47:44 +0000838TEST_F(GenericDebugNodeTest, getEmptyHeader) {
Duncan P. N. Exon Smith2da09e42015-01-20 00:58:46 +0000839 // Canonicalize !"" to null.
Duncan P. N. Exon Smith68ab0232015-01-22 23:10:55 +0000840 auto *N = GenericDebugNode::get(Context, 15, StringRef(), None);
841 EXPECT_EQ(StringRef(), N->getHeader());
842 EXPECT_EQ(nullptr, N->getOperand(0));
Duncan P. N. Exon Smith2da09e42015-01-20 00:58:46 +0000843}
844
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000845typedef MetadataTest MDSubrangeTest;
846
847TEST_F(MDSubrangeTest, get) {
848 auto *N = MDSubrange::get(Context, 5, 7);
849 EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
850 EXPECT_EQ(5, N->getCount());
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000851 EXPECT_EQ(7, N->getLowerBound());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000852 EXPECT_EQ(N, MDSubrange::get(Context, 5, 7));
853 EXPECT_EQ(MDSubrange::get(Context, 5, 0), MDSubrange::get(Context, 5));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000854
855 TempMDSubrange Temp = N->clone();
856 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000857}
858
Duncan P. N. Exon Smith5c9a1772015-02-18 23:17:51 +0000859TEST_F(MDSubrangeTest, getEmptyArray) {
860 auto *N = MDSubrange::get(Context, -1, 0);
861 EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
862 EXPECT_EQ(-1, N->getCount());
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000863 EXPECT_EQ(0, N->getLowerBound());
Duncan P. N. Exon Smith5c9a1772015-02-18 23:17:51 +0000864 EXPECT_EQ(N, MDSubrange::get(Context, -1, 0));
865}
866
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000867typedef MetadataTest MDEnumeratorTest;
868
869TEST_F(MDEnumeratorTest, get) {
870 auto *N = MDEnumerator::get(Context, 7, "name");
871 EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag());
872 EXPECT_EQ(7, N->getValue());
873 EXPECT_EQ("name", N->getName());
874 EXPECT_EQ(N, MDEnumerator::get(Context, 7, "name"));
875
876 EXPECT_NE(N, MDEnumerator::get(Context, 8, "name"));
877 EXPECT_NE(N, MDEnumerator::get(Context, 7, "nam"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000878
879 TempMDEnumerator Temp = N->clone();
880 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000881}
882
883typedef MetadataTest MDBasicTypeTest;
884
885TEST_F(MDBasicTypeTest, get) {
886 auto *N =
887 MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7);
888 EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag());
889 EXPECT_EQ("special", N->getName());
890 EXPECT_EQ(33u, N->getSizeInBits());
891 EXPECT_EQ(26u, N->getAlignInBits());
892 EXPECT_EQ(7u, N->getEncoding());
893 EXPECT_EQ(0u, N->getLine());
894 EXPECT_EQ(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
895 26, 7));
896
897 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type,
898 "special", 33, 26, 7));
899 EXPECT_NE(N,
900 MDBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7));
901 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32,
902 26, 7));
903 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
904 25, 7));
905 EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
906 26, 6));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +0000907
908 TempMDBasicType Temp = N->clone();
909 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000910}
911
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000912TEST_F(MDBasicTypeTest, getWithLargeValues) {
913 auto *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special",
914 UINT64_MAX, UINT64_MAX - 1, 7);
915 EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
916 EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits());
917}
918
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +0000919TEST_F(MDBasicTypeTest, getUnspecified) {
920 auto *N =
921 MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, "unspecified");
922 EXPECT_EQ(dwarf::DW_TAG_unspecified_type, N->getTag());
923 EXPECT_EQ("unspecified", N->getName());
924 EXPECT_EQ(0u, N->getSizeInBits());
925 EXPECT_EQ(0u, N->getAlignInBits());
926 EXPECT_EQ(0u, N->getEncoding());
927 EXPECT_EQ(0u, N->getLine());
928}
929
930typedef MetadataTest MDTypeTest;
931
932TEST_F(MDTypeTest, clone) {
933 // Check that MDType has a specialized clone that returns TempMDType.
934 MDType *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32,
935 dwarf::DW_ATE_signed);
936
937 TempMDType Temp = N->clone();
938 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
939}
940
941TEST_F(MDTypeTest, setFlags) {
942 // void (void)
943 Metadata *TypesOps[] = {nullptr};
944 Metadata *Types = MDTuple::get(Context, TypesOps);
945
946 MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types);
947 EXPECT_EQ(0u, D->getFlags());
948 D->setFlags(DIDescriptor::FlagRValueReference);
949 EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags());
950 D->setFlags(0u);
951 EXPECT_EQ(0u, D->getFlags());
952
953 TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types);
954 EXPECT_EQ(0u, T->getFlags());
955 T->setFlags(DIDescriptor::FlagRValueReference);
956 EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags());
957 T->setFlags(0u);
958 EXPECT_EQ(0u, T->getFlags());
959}
960
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000961typedef MetadataTest MDDerivedTypeTest;
962
963TEST_F(MDDerivedTypeTest, get) {
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000964 MDFile *File = getFile();
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000965 MDScopeRef Scope = getSubprogramRef();
966 MDTypeRef BaseType = getBasicType("basic");
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000967 MDTuple *ExtraData = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000968
969 auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
970 File, 1, Scope, BaseType, 2, 3, 4, 5, ExtraData);
971 EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag());
972 EXPECT_EQ("something", N->getName());
973 EXPECT_EQ(File, N->getFile());
974 EXPECT_EQ(1u, N->getLine());
975 EXPECT_EQ(Scope, N->getScope());
976 EXPECT_EQ(BaseType, N->getBaseType());
977 EXPECT_EQ(2u, N->getSizeInBits());
978 EXPECT_EQ(3u, N->getAlignInBits());
979 EXPECT_EQ(4u, N->getOffsetInBits());
980 EXPECT_EQ(5u, N->getFlags());
981 EXPECT_EQ(ExtraData, N->getExtraData());
982 EXPECT_EQ(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
983 "something", File, 1, Scope, BaseType, 2, 3,
984 4, 5, ExtraData));
985
986 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_reference_type,
987 "something", File, 1, Scope, BaseType, 2, 3,
988 4, 5, ExtraData));
989 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else",
990 File, 1, Scope, BaseType, 2, 3, 4, 5,
991 ExtraData));
992 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000993 "something", getFile(), 1, Scope, BaseType, 2,
994 3, 4, 5, ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000995 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
996 "something", File, 2, Scope, BaseType, 2, 3,
997 4, 5, ExtraData));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000998 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000999 "something", File, 1, getSubprogramRef(),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001000 BaseType, 2, 3, 4, 5, ExtraData));
1001 EXPECT_NE(N, MDDerivedType::get(
1002 Context, dwarf::DW_TAG_pointer_type, "something", File, 1,
1003 Scope, getBasicType("basic2"), 2, 3, 4, 5, ExtraData));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001004 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
1005 "something", File, 1, Scope, BaseType, 3, 3,
1006 4, 5, ExtraData));
1007 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
1008 "something", File, 1, Scope, BaseType, 2, 2,
1009 4, 5, ExtraData));
1010 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
1011 "something", File, 1, Scope, BaseType, 2, 3,
1012 5, 5, ExtraData));
1013 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
1014 "something", File, 1, Scope, BaseType, 2, 3,
1015 4, 4, ExtraData));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001016 EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
1017 "something", File, 1, Scope, BaseType, 2, 3,
1018 4, 5, getTuple()));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001019
1020 TempMDDerivedType Temp = N->clone();
1021 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001022}
1023
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001024TEST_F(MDDerivedTypeTest, getWithLargeValues) {
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001025 MDFile *File = getFile();
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001026 MDScopeRef Scope = getSubprogramRef();
1027 MDTypeRef BaseType = getBasicType("basic");
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001028 MDTuple *ExtraData = getTuple();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001029
1030 auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
1031 File, 1, Scope, BaseType, UINT64_MAX,
1032 UINT64_MAX - 1, UINT64_MAX - 2, 5, ExtraData);
1033 EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
1034 EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits());
1035 EXPECT_EQ(UINT64_MAX - 2, N->getOffsetInBits());
1036}
1037
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001038typedef MetadataTest MDCompositeTypeTest;
1039
1040TEST_F(MDCompositeTypeTest, get) {
1041 unsigned Tag = dwarf::DW_TAG_structure_type;
1042 StringRef Name = "some name";
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001043 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001044 unsigned Line = 1;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001045 MDScopeRef Scope = getSubprogramRef();
1046 MDTypeRef BaseType = getCompositeType();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001047 uint64_t SizeInBits = 2;
1048 uint64_t AlignInBits = 3;
1049 uint64_t OffsetInBits = 4;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001050 unsigned Flags = 5;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001051 MDTuple *Elements = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001052 unsigned RuntimeLang = 6;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001053 MDTypeRef VTableHolder = getCompositeType();
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001054 MDTuple *TemplateParams = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001055 StringRef Identifier = "some id";
1056
1057 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1058 BaseType, SizeInBits, AlignInBits,
1059 OffsetInBits, Flags, Elements, RuntimeLang,
1060 VTableHolder, TemplateParams, Identifier);
1061 EXPECT_EQ(Tag, N->getTag());
1062 EXPECT_EQ(Name, N->getName());
1063 EXPECT_EQ(File, N->getFile());
1064 EXPECT_EQ(Line, N->getLine());
1065 EXPECT_EQ(Scope, N->getScope());
1066 EXPECT_EQ(BaseType, N->getBaseType());
1067 EXPECT_EQ(SizeInBits, N->getSizeInBits());
1068 EXPECT_EQ(AlignInBits, N->getAlignInBits());
1069 EXPECT_EQ(OffsetInBits, N->getOffsetInBits());
1070 EXPECT_EQ(Flags, N->getFlags());
1071 EXPECT_EQ(Elements, N->getElements());
1072 EXPECT_EQ(RuntimeLang, N->getRuntimeLang());
1073 EXPECT_EQ(VTableHolder, N->getVTableHolder());
1074 EXPECT_EQ(TemplateParams, N->getTemplateParams());
1075 EXPECT_EQ(Identifier, N->getIdentifier());
1076
1077 EXPECT_EQ(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1078 BaseType, SizeInBits, AlignInBits,
1079 OffsetInBits, Flags, Elements, RuntimeLang,
1080 VTableHolder, TemplateParams, Identifier));
1081
1082 EXPECT_NE(N, MDCompositeType::get(Context, Tag + 1, Name, File, Line, Scope,
1083 BaseType, SizeInBits, AlignInBits,
1084 OffsetInBits, Flags, Elements, RuntimeLang,
1085 VTableHolder, TemplateParams, Identifier));
1086 EXPECT_NE(N, MDCompositeType::get(Context, Tag, "abc", File, Line, Scope,
1087 BaseType, SizeInBits, AlignInBits,
1088 OffsetInBits, Flags, Elements, RuntimeLang,
1089 VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001090 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, getFile(), Line, Scope,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001091 BaseType, SizeInBits, AlignInBits,
1092 OffsetInBits, Flags, Elements, RuntimeLang,
1093 VTableHolder, TemplateParams, Identifier));
1094 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line + 1, Scope,
1095 BaseType, SizeInBits, AlignInBits,
1096 OffsetInBits, Flags, Elements, RuntimeLang,
1097 VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001098 EXPECT_NE(N, MDCompositeType::get(
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001099 Context, Tag, Name, File, Line, getSubprogramRef(), BaseType,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001100 SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
1101 RuntimeLang, VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001102 EXPECT_NE(N, MDCompositeType::get(
1103 Context, Tag, Name, File, Line, Scope, getBasicType("other"),
1104 SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
1105 RuntimeLang, VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001106 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1107 BaseType, SizeInBits + 1, AlignInBits,
1108 OffsetInBits, Flags, Elements, RuntimeLang,
1109 VTableHolder, TemplateParams, Identifier));
1110 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1111 BaseType, SizeInBits, AlignInBits + 1,
1112 OffsetInBits, Flags, Elements, RuntimeLang,
1113 VTableHolder, TemplateParams, Identifier));
1114 EXPECT_NE(N, MDCompositeType::get(
1115 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1116 AlignInBits, OffsetInBits + 1, Flags, Elements, RuntimeLang,
1117 VTableHolder, TemplateParams, Identifier));
1118 EXPECT_NE(N, MDCompositeType::get(
1119 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1120 AlignInBits, OffsetInBits, Flags + 1, Elements, RuntimeLang,
1121 VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001122 EXPECT_NE(N, MDCompositeType::get(
1123 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1124 AlignInBits, OffsetInBits, Flags, getTuple(), RuntimeLang,
1125 VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001126 EXPECT_NE(N, MDCompositeType::get(
1127 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1128 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang + 1,
1129 VTableHolder, TemplateParams, Identifier));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001130 EXPECT_NE(N, MDCompositeType::get(
1131 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1132 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1133 getCompositeType(), TemplateParams, Identifier));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001134 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1135 BaseType, SizeInBits, AlignInBits,
1136 OffsetInBits, Flags, Elements, RuntimeLang,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001137 VTableHolder, getTuple(), Identifier));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001138 EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1139 BaseType, SizeInBits, AlignInBits,
1140 OffsetInBits, Flags, Elements, RuntimeLang,
1141 VTableHolder, TemplateParams, "other"));
1142
1143 // Be sure that missing identifiers get null pointers.
1144 EXPECT_FALSE(MDCompositeType::get(
1145 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1146 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1147 VTableHolder, TemplateParams, "")->getRawIdentifier());
1148 EXPECT_FALSE(MDCompositeType::get(
1149 Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
1150 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
1151 VTableHolder, TemplateParams)->getRawIdentifier());
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001152
1153 TempMDCompositeType Temp = N->clone();
1154 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001155}
1156
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001157TEST_F(MDCompositeTypeTest, getWithLargeValues) {
1158 unsigned Tag = dwarf::DW_TAG_structure_type;
1159 StringRef Name = "some name";
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001160 MDFile *File = getFile();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001161 unsigned Line = 1;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001162 MDScopeRef Scope = getSubprogramRef();
1163 MDTypeRef BaseType = getCompositeType();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001164 uint64_t SizeInBits = UINT64_MAX;
1165 uint64_t AlignInBits = UINT64_MAX - 1;
1166 uint64_t OffsetInBits = UINT64_MAX - 2;
1167 unsigned Flags = 5;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001168 MDTuple *Elements = getTuple();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001169 unsigned RuntimeLang = 6;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001170 MDTypeRef VTableHolder = getCompositeType();
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001171 MDTuple *TemplateParams = getTuple();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001172 StringRef Identifier = "some id";
1173
1174 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1175 BaseType, SizeInBits, AlignInBits,
1176 OffsetInBits, Flags, Elements, RuntimeLang,
1177 VTableHolder, TemplateParams, Identifier);
1178 EXPECT_EQ(SizeInBits, N->getSizeInBits());
1179 EXPECT_EQ(AlignInBits, N->getAlignInBits());
1180 EXPECT_EQ(OffsetInBits, N->getOffsetInBits());
1181}
1182
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +00001183TEST_F(MDCompositeTypeTest, replaceOperands) {
1184 unsigned Tag = dwarf::DW_TAG_structure_type;
1185 StringRef Name = "some name";
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001186 MDFile *File = getFile();
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +00001187 unsigned Line = 1;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001188 MDScopeRef Scope = getSubprogramRef();
1189 MDTypeRef BaseType = getCompositeType();
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +00001190 uint64_t SizeInBits = 2;
1191 uint64_t AlignInBits = 3;
1192 uint64_t OffsetInBits = 4;
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +00001193 unsigned Flags = 5;
1194 unsigned RuntimeLang = 6;
1195 StringRef Identifier = "some id";
1196
1197 auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
1198 BaseType, SizeInBits, AlignInBits,
1199 OffsetInBits, Flags, nullptr, RuntimeLang,
1200 nullptr, nullptr, Identifier);
1201
1202 auto *Elements = MDTuple::getDistinct(Context, None);
1203 EXPECT_EQ(nullptr, N->getElements());
1204 N->replaceElements(Elements);
1205 EXPECT_EQ(Elements, N->getElements());
1206 N->replaceElements(nullptr);
1207 EXPECT_EQ(nullptr, N->getElements());
1208
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001209 MDTypeRef VTableHolder = getCompositeType();
Duncan P. N. Exon Smithf51e00d2015-02-18 20:47:52 +00001210 EXPECT_EQ(nullptr, N->getVTableHolder());
1211 N->replaceVTableHolder(VTableHolder);
1212 EXPECT_EQ(VTableHolder, N->getVTableHolder());
1213 N->replaceVTableHolder(nullptr);
1214 EXPECT_EQ(nullptr, N->getVTableHolder());
1215
1216 auto *TemplateParams = MDTuple::getDistinct(Context, None);
1217 EXPECT_EQ(nullptr, N->getTemplateParams());
1218 N->replaceTemplateParams(TemplateParams);
1219 EXPECT_EQ(TemplateParams, N->getTemplateParams());
1220 N->replaceTemplateParams(nullptr);
1221 EXPECT_EQ(nullptr, N->getTemplateParams());
1222}
1223
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001224typedef MetadataTest MDSubroutineTypeTest;
1225
1226TEST_F(MDSubroutineTypeTest, get) {
1227 unsigned Flags = 1;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001228 MDTuple *TypeArray = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001229
1230 auto *N = MDSubroutineType::get(Context, Flags, TypeArray);
1231 EXPECT_EQ(dwarf::DW_TAG_subroutine_type, N->getTag());
1232 EXPECT_EQ(Flags, N->getFlags());
1233 EXPECT_EQ(TypeArray, N->getTypeArray());
1234 EXPECT_EQ(N, MDSubroutineType::get(Context, Flags, TypeArray));
1235
1236 EXPECT_NE(N, MDSubroutineType::get(Context, Flags + 1, TypeArray));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001237 EXPECT_NE(N, MDSubroutineType::get(Context, Flags, getTuple()));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001238
1239 TempMDSubroutineType Temp = N->clone();
1240 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smitha9f0a8d2015-02-19 23:25:21 +00001241
1242 // Test always-empty operands.
1243 EXPECT_EQ(nullptr, N->getScope());
1244 EXPECT_EQ(nullptr, N->getFile());
1245 EXPECT_EQ("", N->getName());
1246 EXPECT_EQ(nullptr, N->getBaseType());
1247 EXPECT_EQ(nullptr, N->getVTableHolder());
1248 EXPECT_EQ(nullptr, N->getTemplateParams());
1249 EXPECT_EQ("", N->getIdentifier());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001250}
1251
1252typedef MetadataTest MDFileTest;
1253
1254TEST_F(MDFileTest, get) {
1255 StringRef Filename = "file";
1256 StringRef Directory = "dir";
1257 auto *N = MDFile::get(Context, Filename, Directory);
1258
1259 EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag());
1260 EXPECT_EQ(Filename, N->getFilename());
1261 EXPECT_EQ(Directory, N->getDirectory());
1262 EXPECT_EQ(N, MDFile::get(Context, Filename, Directory));
1263
1264 EXPECT_NE(N, MDFile::get(Context, "other", Directory));
1265 EXPECT_NE(N, MDFile::get(Context, Filename, "other"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001266
1267 TempMDFile Temp = N->clone();
1268 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001269}
1270
Duncan P. N. Exon Smith2c6a0a92015-02-28 21:47:02 +00001271TEST_F(MDFileTest, ScopeGetFile) {
1272 // Ensure that MDScope::getFile() returns itself.
1273 MDScope *N = MDFile::get(Context, "file", "dir");
1274 EXPECT_EQ(N, N->getFile());
1275}
1276
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001277typedef MetadataTest MDCompileUnitTest;
1278
1279TEST_F(MDCompileUnitTest, get) {
1280 unsigned SourceLanguage = 1;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001281 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001282 StringRef Producer = "some producer";
1283 bool IsOptimized = false;
1284 StringRef Flags = "flag after flag";
1285 unsigned RuntimeVersion = 2;
1286 StringRef SplitDebugFilename = "another/file";
1287 unsigned EmissionKind = 3;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001288 MDTuple *EnumTypes = getTuple();
1289 MDTuple *RetainedTypes = getTuple();
1290 MDTuple *Subprograms = getTuple();
1291 MDTuple *GlobalVariables = getTuple();
1292 MDTuple *ImportedEntities = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001293 auto *N = MDCompileUnit::get(
1294 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1295 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1296 RetainedTypes, Subprograms, GlobalVariables, ImportedEntities);
1297
1298 EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
1299 EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
1300 EXPECT_EQ(File, N->getFile());
1301 EXPECT_EQ(Producer, N->getProducer());
1302 EXPECT_EQ(IsOptimized, N->isOptimized());
1303 EXPECT_EQ(Flags, N->getFlags());
1304 EXPECT_EQ(RuntimeVersion, N->getRuntimeVersion());
1305 EXPECT_EQ(SplitDebugFilename, N->getSplitDebugFilename());
1306 EXPECT_EQ(EmissionKind, N->getEmissionKind());
1307 EXPECT_EQ(EnumTypes, N->getEnumTypes());
1308 EXPECT_EQ(RetainedTypes, N->getRetainedTypes());
1309 EXPECT_EQ(Subprograms, N->getSubprograms());
1310 EXPECT_EQ(GlobalVariables, N->getGlobalVariables());
1311 EXPECT_EQ(ImportedEntities, N->getImportedEntities());
1312 EXPECT_EQ(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1313 IsOptimized, Flags, RuntimeVersion,
1314 SplitDebugFilename, EmissionKind, EnumTypes,
1315 RetainedTypes, Subprograms, GlobalVariables,
1316 ImportedEntities));
1317
1318 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage + 1, File, Producer,
1319 IsOptimized, Flags, RuntimeVersion,
1320 SplitDebugFilename, EmissionKind, EnumTypes,
1321 RetainedTypes, Subprograms, GlobalVariables,
1322 ImportedEntities));
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001323 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, getFile(), Producer,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001324 IsOptimized, Flags, RuntimeVersion,
1325 SplitDebugFilename, EmissionKind, EnumTypes,
1326 RetainedTypes, Subprograms, GlobalVariables,
1327 ImportedEntities));
1328 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, "other",
1329 IsOptimized, Flags, RuntimeVersion,
1330 SplitDebugFilename, EmissionKind, EnumTypes,
1331 RetainedTypes, Subprograms, GlobalVariables,
1332 ImportedEntities));
1333 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1334 !IsOptimized, Flags, RuntimeVersion,
1335 SplitDebugFilename, EmissionKind, EnumTypes,
1336 RetainedTypes, Subprograms, GlobalVariables,
1337 ImportedEntities));
1338 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1339 IsOptimized, "other", RuntimeVersion,
1340 SplitDebugFilename, EmissionKind, EnumTypes,
1341 RetainedTypes, Subprograms, GlobalVariables,
1342 ImportedEntities));
1343 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1344 IsOptimized, Flags, RuntimeVersion + 1,
1345 SplitDebugFilename, EmissionKind, EnumTypes,
1346 RetainedTypes, Subprograms, GlobalVariables,
1347 ImportedEntities));
1348 EXPECT_NE(N,
1349 MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1350 IsOptimized, Flags, RuntimeVersion, "other",
1351 EmissionKind, EnumTypes, RetainedTypes,
1352 Subprograms, GlobalVariables, ImportedEntities));
1353 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1354 IsOptimized, Flags, RuntimeVersion,
1355 SplitDebugFilename, EmissionKind + 1,
1356 EnumTypes, RetainedTypes, Subprograms,
1357 GlobalVariables, ImportedEntities));
1358 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1359 IsOptimized, Flags, RuntimeVersion,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001360 SplitDebugFilename, EmissionKind, getTuple(),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001361 RetainedTypes, Subprograms, GlobalVariables,
1362 ImportedEntities));
1363 EXPECT_NE(N, MDCompileUnit::get(
1364 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1365 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001366 getTuple(), Subprograms, GlobalVariables, ImportedEntities));
1367 EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer,
1368 IsOptimized, Flags, RuntimeVersion,
1369 SplitDebugFilename, EmissionKind, EnumTypes,
1370 RetainedTypes, getTuple(), GlobalVariables,
1371 ImportedEntities));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001372 EXPECT_NE(N, MDCompileUnit::get(
1373 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1374 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001375 RetainedTypes, Subprograms, getTuple(), ImportedEntities));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001376 EXPECT_NE(N, MDCompileUnit::get(
1377 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1378 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001379 RetainedTypes, Subprograms, GlobalVariables, getTuple()));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001380
1381 TempMDCompileUnit Temp = N->clone();
1382 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001383}
1384
Duncan P. N. Exon Smith94bbbf02015-02-18 20:36:09 +00001385TEST_F(MDCompileUnitTest, replaceArrays) {
1386 unsigned SourceLanguage = 1;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001387 MDFile *File = getFile();
Duncan P. N. Exon Smith94bbbf02015-02-18 20:36:09 +00001388 StringRef Producer = "some producer";
1389 bool IsOptimized = false;
1390 StringRef Flags = "flag after flag";
1391 unsigned RuntimeVersion = 2;
1392 StringRef SplitDebugFilename = "another/file";
1393 unsigned EmissionKind = 3;
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +00001394 MDTuple *EnumTypes = MDTuple::getDistinct(Context, None);
1395 MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None);
1396 MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None);
Duncan P. N. Exon Smith94bbbf02015-02-18 20:36:09 +00001397 auto *N = MDCompileUnit::get(
1398 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
1399 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
1400 RetainedTypes, nullptr, nullptr, ImportedEntities);
1401
1402 auto *Subprograms = MDTuple::getDistinct(Context, None);
1403 EXPECT_EQ(nullptr, N->getSubprograms());
1404 N->replaceSubprograms(Subprograms);
1405 EXPECT_EQ(Subprograms, N->getSubprograms());
1406 N->replaceSubprograms(nullptr);
1407 EXPECT_EQ(nullptr, N->getSubprograms());
1408
1409 auto *GlobalVariables = MDTuple::getDistinct(Context, None);
1410 EXPECT_EQ(nullptr, N->getGlobalVariables());
1411 N->replaceGlobalVariables(GlobalVariables);
1412 EXPECT_EQ(GlobalVariables, N->getGlobalVariables());
1413 N->replaceGlobalVariables(nullptr);
1414 EXPECT_EQ(nullptr, N->getGlobalVariables());
1415}
1416
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001417typedef MetadataTest MDSubprogramTest;
1418
1419TEST_F(MDSubprogramTest, get) {
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001420 MDScopeRef Scope = getCompositeType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001421 StringRef Name = "name";
1422 StringRef LinkageName = "linkage";
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001423 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001424 unsigned Line = 2;
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001425 MDSubroutineType *Type = getSubroutineType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001426 bool IsLocalToUnit = false;
1427 bool IsDefinition = true;
1428 unsigned ScopeLine = 3;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001429 MDTypeRef ContainingType = getCompositeType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001430 unsigned Virtuality = 4;
1431 unsigned VirtualIndex = 5;
1432 unsigned Flags = 6;
1433 bool IsOptimized = false;
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001434 ConstantAsMetadata *Function = getFunctionAsMetadata("foo");
1435 MDTuple *TemplateParams = getTuple();
1436 MDSubprogram *Declaration = getSubprogram();
1437 MDTuple *Variables = getTuple();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001438
1439 auto *N = MDSubprogram::get(
1440 Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1441 IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
1442 IsOptimized, Function, TemplateParams, Declaration, Variables);
1443
1444 EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag());
1445 EXPECT_EQ(Scope, N->getScope());
1446 EXPECT_EQ(Name, N->getName());
1447 EXPECT_EQ(LinkageName, N->getLinkageName());
1448 EXPECT_EQ(File, N->getFile());
1449 EXPECT_EQ(Line, N->getLine());
1450 EXPECT_EQ(Type, N->getType());
1451 EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit());
1452 EXPECT_EQ(IsDefinition, N->isDefinition());
1453 EXPECT_EQ(ScopeLine, N->getScopeLine());
1454 EXPECT_EQ(ContainingType, N->getContainingType());
1455 EXPECT_EQ(Virtuality, N->getVirtuality());
1456 EXPECT_EQ(VirtualIndex, N->getVirtualIndex());
1457 EXPECT_EQ(Flags, N->getFlags());
1458 EXPECT_EQ(IsOptimized, N->isOptimized());
1459 EXPECT_EQ(Function, N->getFunction());
1460 EXPECT_EQ(TemplateParams, N->getTemplateParams());
1461 EXPECT_EQ(Declaration, N->getDeclaration());
1462 EXPECT_EQ(Variables, N->getVariables());
1463 EXPECT_EQ(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1464 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1465 ContainingType, Virtuality, VirtualIndex,
1466 Flags, IsOptimized, Function, TemplateParams,
1467 Declaration, Variables));
1468
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001469 EXPECT_NE(N, MDSubprogram::get(Context, getCompositeType(), Name, LinkageName,
1470 File, Line, Type, IsLocalToUnit, IsDefinition,
1471 ScopeLine, ContainingType, Virtuality,
1472 VirtualIndex, Flags, IsOptimized, Function,
1473 TemplateParams, Declaration, Variables));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001474 EXPECT_NE(N, MDSubprogram::get(Context, Scope, "other", LinkageName, File,
1475 Line, Type, IsLocalToUnit, IsDefinition,
1476 ScopeLine, ContainingType, Virtuality,
1477 VirtualIndex, Flags, IsOptimized, Function,
1478 TemplateParams, Declaration, Variables));
1479 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, "other", File, Line,
1480 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1481 ContainingType, Virtuality, VirtualIndex,
1482 Flags, IsOptimized, Function, TemplateParams,
1483 Declaration, Variables));
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001484 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, getFile(),
1485 Line, Type, IsLocalToUnit, IsDefinition,
1486 ScopeLine, ContainingType, Virtuality,
1487 VirtualIndex, Flags, IsOptimized, Function,
1488 TemplateParams, Declaration, Variables));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001489 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File,
1490 Line + 1, Type, IsLocalToUnit, IsDefinition,
1491 ScopeLine, ContainingType, Virtuality,
1492 VirtualIndex, Flags, IsOptimized, Function,
1493 TemplateParams, Declaration, Variables));
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001494 EXPECT_NE(N, MDSubprogram::get(
1495 Context, Scope, Name, LinkageName, File, Line,
1496 getSubroutineType(), IsLocalToUnit, IsDefinition, ScopeLine,
1497 ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
1498 Function, TemplateParams, Declaration, Variables));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001499 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1500 Type, !IsLocalToUnit, IsDefinition, ScopeLine,
1501 ContainingType, Virtuality, VirtualIndex,
1502 Flags, IsOptimized, Function, TemplateParams,
1503 Declaration, Variables));
1504 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1505 Type, IsLocalToUnit, !IsDefinition, ScopeLine,
1506 ContainingType, Virtuality, VirtualIndex,
1507 Flags, IsOptimized, Function, TemplateParams,
1508 Declaration, Variables));
1509 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1510 Type, IsLocalToUnit, IsDefinition,
1511 ScopeLine + 1, ContainingType, Virtuality,
1512 VirtualIndex, Flags, IsOptimized, Function,
1513 TemplateParams, Declaration, Variables));
1514 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1515 Type, IsLocalToUnit, IsDefinition, ScopeLine,
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001516 getCompositeType(), Virtuality, VirtualIndex,
1517 Flags, IsOptimized, Function, TemplateParams,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001518 Declaration, Variables));
1519 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1520 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1521 ContainingType, Virtuality + 1, VirtualIndex,
1522 Flags, IsOptimized, Function, TemplateParams,
1523 Declaration, Variables));
1524 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1525 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1526 ContainingType, Virtuality, VirtualIndex + 1,
1527 Flags, IsOptimized, Function, TemplateParams,
1528 Declaration, Variables));
1529 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1530 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1531 ContainingType, Virtuality, VirtualIndex,
1532 ~Flags, IsOptimized, Function, TemplateParams,
1533 Declaration, Variables));
1534 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1535 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1536 ContainingType, Virtuality, VirtualIndex,
1537 Flags, !IsOptimized, Function, TemplateParams,
1538 Declaration, Variables));
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001539 EXPECT_NE(N,
1540 MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1541 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1542 ContainingType, Virtuality, VirtualIndex, Flags,
1543 IsOptimized, getFunctionAsMetadata("bar"),
1544 TemplateParams, Declaration, Variables));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001545 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1546 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1547 ContainingType, Virtuality, VirtualIndex,
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001548 Flags, IsOptimized, Function, getTuple(),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001549 Declaration, Variables));
1550 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1551 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1552 ContainingType, Virtuality, VirtualIndex,
1553 Flags, IsOptimized, Function, TemplateParams,
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001554 getSubprogram(), Variables));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001555 EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
1556 Type, IsLocalToUnit, IsDefinition, ScopeLine,
1557 ContainingType, Virtuality, VirtualIndex,
1558 Flags, IsOptimized, Function, TemplateParams,
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001559 Declaration, getTuple()));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001560
1561 TempMDSubprogram Temp = N->clone();
1562 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001563}
1564
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001565TEST_F(MDSubprogramTest, replaceFunction) {
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001566 MDScopeRef Scope = getCompositeType();
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001567 StringRef Name = "name";
1568 StringRef LinkageName = "linkage";
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001569 MDFile *File = getFile();
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001570 unsigned Line = 2;
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001571 MDSubroutineType *Type = getSubroutineType();
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001572 bool IsLocalToUnit = false;
1573 bool IsDefinition = true;
1574 unsigned ScopeLine = 3;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001575 MDTypeRef ContainingType = getCompositeType();
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001576 unsigned Virtuality = 4;
1577 unsigned VirtualIndex = 5;
1578 unsigned Flags = 6;
1579 bool IsOptimized = false;
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +00001580 MDTuple *TemplateParams = getTuple();
1581 MDSubprogram *Declaration = getSubprogram();
1582 MDTuple *Variables = getTuple();
Duncan P. N. Exon Smithdf523492015-02-18 20:32:57 +00001583
1584 auto *N = MDSubprogram::get(
1585 Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
1586 IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
1587 IsOptimized, nullptr, TemplateParams, Declaration, Variables);
1588
1589 EXPECT_EQ(nullptr, N->getFunction());
1590
1591 std::unique_ptr<Function> F(
1592 Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
1593 GlobalValue::ExternalLinkage));
1594 N->replaceFunction(F.get());
1595 EXPECT_EQ(ConstantAsMetadata::get(F.get()), N->getFunction());
1596
1597 N->replaceFunction(nullptr);
1598 EXPECT_EQ(nullptr, N->getFunction());
1599}
1600
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001601typedef MetadataTest MDLexicalBlockTest;
1602
1603TEST_F(MDLexicalBlockTest, get) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +00001604 MDLocalScope *Scope = getSubprogram();
1605 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001606 unsigned Line = 5;
1607 unsigned Column = 8;
1608
1609 auto *N = MDLexicalBlock::get(Context, Scope, File, Line, Column);
1610
1611 EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag());
1612 EXPECT_EQ(Scope, N->getScope());
1613 EXPECT_EQ(File, N->getFile());
1614 EXPECT_EQ(Line, N->getLine());
1615 EXPECT_EQ(Column, N->getColumn());
1616 EXPECT_EQ(N, MDLexicalBlock::get(Context, Scope, File, Line, Column));
1617
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +00001618 EXPECT_NE(N,
1619 MDLexicalBlock::get(Context, getSubprogram(), File, Line, Column));
1620 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, getFile(), Line, Column));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001621 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line + 1, Column));
1622 EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line, Column + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001623
1624 TempMDLexicalBlock Temp = N->clone();
1625 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001626}
1627
1628typedef MetadataTest MDLexicalBlockFileTest;
1629
1630TEST_F(MDLexicalBlockFileTest, get) {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +00001631 MDLocalScope *Scope = getSubprogram();
1632 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001633 unsigned Discriminator = 5;
1634
1635 auto *N = MDLexicalBlockFile::get(Context, Scope, File, Discriminator);
1636
1637 EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag());
1638 EXPECT_EQ(Scope, N->getScope());
1639 EXPECT_EQ(File, N->getFile());
1640 EXPECT_EQ(Discriminator, N->getDiscriminator());
1641 EXPECT_EQ(N, MDLexicalBlockFile::get(Context, Scope, File, Discriminator));
1642
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +00001643 EXPECT_NE(N, MDLexicalBlockFile::get(Context, getSubprogram(), File,
1644 Discriminator));
1645 EXPECT_NE(N,
1646 MDLexicalBlockFile::get(Context, Scope, getFile(), Discriminator));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001647 EXPECT_NE(N,
1648 MDLexicalBlockFile::get(Context, Scope, File, Discriminator + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001649
1650 TempMDLexicalBlockFile Temp = N->clone();
1651 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001652}
1653
1654typedef MetadataTest MDNamespaceTest;
1655
1656TEST_F(MDNamespaceTest, get) {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001657 MDScope *Scope = getFile();
1658 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001659 StringRef Name = "namespace";
1660 unsigned Line = 5;
1661
1662 auto *N = MDNamespace::get(Context, Scope, File, Name, Line);
1663
1664 EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag());
1665 EXPECT_EQ(Scope, N->getScope());
1666 EXPECT_EQ(File, N->getFile());
1667 EXPECT_EQ(Name, N->getName());
1668 EXPECT_EQ(Line, N->getLine());
1669 EXPECT_EQ(N, MDNamespace::get(Context, Scope, File, Name, Line));
1670
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001671 EXPECT_NE(N, MDNamespace::get(Context, getFile(), File, Name, Line));
1672 EXPECT_NE(N, MDNamespace::get(Context, Scope, getFile(), Name, Line));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001673 EXPECT_NE(N, MDNamespace::get(Context, Scope, File, "other", Line));
1674 EXPECT_NE(N, MDNamespace::get(Context, Scope, File, Name, Line + 1));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001675
1676 TempMDNamespace Temp = N->clone();
1677 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001678}
1679
1680typedef MetadataTest MDTemplateTypeParameterTest;
1681
1682TEST_F(MDTemplateTypeParameterTest, get) {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001683 StringRef Name = "template";
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001684 MDTypeRef Type = getBasicType("basic");
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001685
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001686 auto *N = MDTemplateTypeParameter::get(Context, Name, Type);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001687
1688 EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001689 EXPECT_EQ(Name, N->getName());
1690 EXPECT_EQ(Type, N->getType());
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001691 EXPECT_EQ(N, MDTemplateTypeParameter::get(Context, Name, Type));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001692
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001693 EXPECT_NE(N, MDTemplateTypeParameter::get(Context, "other", Type));
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001694 EXPECT_NE(N,
1695 MDTemplateTypeParameter::get(Context, Name, getBasicType("other")));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001696
1697 TempMDTemplateTypeParameter Temp = N->clone();
1698 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001699}
1700
1701typedef MetadataTest MDTemplateValueParameterTest;
1702
1703TEST_F(MDTemplateValueParameterTest, get) {
1704 unsigned Tag = dwarf::DW_TAG_template_value_parameter;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001705 StringRef Name = "template";
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001706 MDTypeRef Type = getBasicType("basic");
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001707 Metadata *Value = getConstantAsMetadata();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001708
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001709 auto *N = MDTemplateValueParameter::get(Context, Tag, Name, Type, Value);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001710 EXPECT_EQ(Tag, N->getTag());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001711 EXPECT_EQ(Name, N->getName());
1712 EXPECT_EQ(Type, N->getType());
1713 EXPECT_EQ(Value, N->getValue());
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001714 EXPECT_EQ(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, Value));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001715
1716 EXPECT_NE(N, MDTemplateValueParameter::get(
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +00001717 Context, dwarf::DW_TAG_GNU_template_template_param, Name,
1718 Type, Value));
1719 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, "other", Type,
Duncan P. N. Exon Smithbd33d372015-02-10 01:59:57 +00001720 Value));
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001721 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name,
1722 getBasicType("other"), Value));
1723 EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Type,
1724 getConstantAsMetadata()));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001725
1726 TempMDTemplateValueParameter Temp = N->clone();
1727 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001728}
1729
1730typedef MetadataTest MDGlobalVariableTest;
1731
1732TEST_F(MDGlobalVariableTest, get) {
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001733 MDScope *Scope = getSubprogram();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001734 StringRef Name = "name";
1735 StringRef LinkageName = "linkage";
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001736 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001737 unsigned Line = 5;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001738 MDTypeRef Type = getDerivedType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001739 bool IsLocalToUnit = false;
1740 bool IsDefinition = true;
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001741 ConstantAsMetadata *Variable = getConstantAsMetadata();
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001742 MDDerivedType *StaticDataMemberDeclaration =
1743 cast<MDDerivedType>(getDerivedType());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001744
1745 auto *N = MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
1746 Type, IsLocalToUnit, IsDefinition, Variable,
1747 StaticDataMemberDeclaration);
1748 EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag());
1749 EXPECT_EQ(Scope, N->getScope());
1750 EXPECT_EQ(Name, N->getName());
1751 EXPECT_EQ(LinkageName, N->getLinkageName());
1752 EXPECT_EQ(File, N->getFile());
1753 EXPECT_EQ(Line, N->getLine());
1754 EXPECT_EQ(Type, N->getType());
1755 EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit());
1756 EXPECT_EQ(IsDefinition, N->isDefinition());
1757 EXPECT_EQ(Variable, N->getVariable());
1758 EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration());
1759 EXPECT_EQ(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1760 Line, Type, IsLocalToUnit, IsDefinition,
1761 Variable, StaticDataMemberDeclaration));
1762
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001763 EXPECT_NE(N,
1764 MDGlobalVariable::get(Context, getSubprogram(), Name, LinkageName,
1765 File, Line, Type, IsLocalToUnit, IsDefinition,
1766 Variable, StaticDataMemberDeclaration));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001767 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, "other", LinkageName, File,
1768 Line, Type, IsLocalToUnit, IsDefinition,
1769 Variable, StaticDataMemberDeclaration));
1770 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, "other", File, Line,
1771 Type, IsLocalToUnit, IsDefinition,
1772 Variable, StaticDataMemberDeclaration));
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001773 EXPECT_NE(N,
1774 MDGlobalVariable::get(Context, Scope, Name, LinkageName, getFile(),
1775 Line, Type, IsLocalToUnit, IsDefinition,
1776 Variable, StaticDataMemberDeclaration));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001777 EXPECT_NE(N,
1778 MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1779 Line + 1, Type, IsLocalToUnit, IsDefinition,
1780 Variable, StaticDataMemberDeclaration));
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001781 EXPECT_NE(N,
1782 MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
1783 getDerivedType(), IsLocalToUnit, IsDefinition,
1784 Variable, StaticDataMemberDeclaration));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001785 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1786 Line, Type, !IsLocalToUnit, IsDefinition,
1787 Variable, StaticDataMemberDeclaration));
1788 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1789 Line, Type, IsLocalToUnit, !IsDefinition,
1790 Variable, StaticDataMemberDeclaration));
1791 EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
1792 Line, Type, IsLocalToUnit, IsDefinition,
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001793 getConstantAsMetadata(),
1794 StaticDataMemberDeclaration));
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001795 EXPECT_NE(N,
1796 MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
1797 Type, IsLocalToUnit, IsDefinition, Variable,
1798 cast<MDDerivedType>(getDerivedType())));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001799
1800 TempMDGlobalVariable Temp = N->clone();
1801 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001802}
1803
1804typedef MetadataTest MDLocalVariableTest;
1805
1806TEST_F(MDLocalVariableTest, get) {
1807 unsigned Tag = dwarf::DW_TAG_arg_variable;
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001808 MDLocalScope *Scope = getSubprogram();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001809 StringRef Name = "name";
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001810 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001811 unsigned Line = 5;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001812 MDTypeRef Type = getDerivedType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001813 unsigned Arg = 6;
1814 unsigned Flags = 7;
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001815 MDLocation *InlinedAt =
1816 MDLocation::getDistinct(Context, 10, 20, getSubprogram());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001817
1818 auto *N = MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1819 Arg, Flags, InlinedAt);
1820 EXPECT_EQ(Tag, N->getTag());
1821 EXPECT_EQ(Scope, N->getScope());
1822 EXPECT_EQ(Name, N->getName());
1823 EXPECT_EQ(File, N->getFile());
1824 EXPECT_EQ(Line, N->getLine());
1825 EXPECT_EQ(Type, N->getType());
1826 EXPECT_EQ(Arg, N->getArg());
1827 EXPECT_EQ(Flags, N->getFlags());
1828 EXPECT_EQ(InlinedAt, N->getInlinedAt());
1829 EXPECT_EQ(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1830 Arg, Flags, InlinedAt));
1831
1832 EXPECT_NE(N, MDLocalVariable::get(Context, dwarf::DW_TAG_auto_variable, Scope,
1833 Name, File, Line, Type, Arg, Flags,
1834 InlinedAt));
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001835 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, getSubprogram(), Name, File,
1836 Line, Type, Arg, Flags, InlinedAt));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001837 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, "other", File, Line,
1838 Type, Arg, Flags, InlinedAt));
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001839 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, getFile(), Line,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001840 Type, Arg, Flags, InlinedAt));
1841 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line + 1,
1842 Type, Arg, Flags, InlinedAt));
1843 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line,
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001844 getDerivedType(), Arg, Flags, InlinedAt));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001845 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1846 Arg + 1, Flags, InlinedAt));
1847 EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
1848 Arg, ~Flags, InlinedAt));
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +00001849 EXPECT_NE(N, MDLocalVariable::get(
1850 Context, Tag, Scope, Name, File, Line, Type, Arg, Flags,
1851 MDLocation::getDistinct(Context, 10, 20, getSubprogram())));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001852
1853 TempMDLocalVariable Temp = N->clone();
1854 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smithb3538492015-03-03 16:45:34 +00001855
1856 auto *Inlined = N->withoutInline();
1857 EXPECT_NE(N, Inlined);
1858 EXPECT_EQ(N->getTag(), Inlined->getTag());
1859 EXPECT_EQ(N->getScope(), Inlined->getScope());
1860 EXPECT_EQ(N->getName(), Inlined->getName());
1861 EXPECT_EQ(N->getFile(), Inlined->getFile());
1862 EXPECT_EQ(N->getLine(), Inlined->getLine());
1863 EXPECT_EQ(N->getType(), Inlined->getType());
1864 EXPECT_EQ(N->getArg(), Inlined->getArg());
1865 EXPECT_EQ(N->getFlags(), Inlined->getFlags());
1866 EXPECT_EQ(nullptr, Inlined->getInlinedAt());
1867 EXPECT_EQ(N, Inlined->withInline(cast<MDLocation>(InlinedAt)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001868}
1869
1870typedef MetadataTest MDExpressionTest;
1871
1872TEST_F(MDExpressionTest, get) {
1873 uint64_t Elements[] = {2, 6, 9, 78, 0};
1874 auto *N = MDExpression::get(Context, Elements);
1875 EXPECT_EQ(makeArrayRef(Elements), N->getElements());
1876 EXPECT_EQ(N, MDExpression::get(Context, Elements));
Duncan P. N. Exon Smithdddc5372015-02-10 01:36:46 +00001877
1878 EXPECT_EQ(5u, N->getNumElements());
1879 EXPECT_EQ(2u, N->getElement(0));
1880 EXPECT_EQ(6u, N->getElement(1));
1881 EXPECT_EQ(9u, N->getElement(2));
1882 EXPECT_EQ(78u, N->getElement(3));
1883 EXPECT_EQ(0u, N->getElement(4));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001884
1885 TempMDExpression Temp = N->clone();
1886 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001887}
1888
Duncan P. N. Exon Smith193a4fd2015-02-13 01:07:46 +00001889TEST_F(MDExpressionTest, isValid) {
1890#define EXPECT_VALID(...) \
1891 do { \
1892 uint64_t Elements[] = {__VA_ARGS__}; \
1893 EXPECT_TRUE(MDExpression::get(Context, Elements)->isValid()); \
1894 } while (false)
1895#define EXPECT_INVALID(...) \
1896 do { \
1897 uint64_t Elements[] = {__VA_ARGS__}; \
1898 EXPECT_FALSE(MDExpression::get(Context, Elements)->isValid()); \
1899 } while (false)
1900
1901 // Empty expression should be valid.
1902 EXPECT_TRUE(MDExpression::get(Context, None));
1903
1904 // Valid constructions.
1905 EXPECT_VALID(dwarf::DW_OP_plus, 6);
1906 EXPECT_VALID(dwarf::DW_OP_deref);
1907 EXPECT_VALID(dwarf::DW_OP_bit_piece, 3, 7);
1908 EXPECT_VALID(dwarf::DW_OP_plus, 6, dwarf::DW_OP_deref);
1909 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6);
1910 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_bit_piece, 3, 7);
1911 EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6, dwarf::DW_OP_bit_piece, 3, 7);
1912
1913 // Invalid constructions.
1914 EXPECT_INVALID(~0u);
1915 EXPECT_INVALID(dwarf::DW_OP_plus);
1916 EXPECT_INVALID(dwarf::DW_OP_bit_piece);
1917 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3);
1918 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_plus, 3);
1919 EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_deref);
1920
1921#undef EXPECT_VALID
1922#undef EXPECT_INVALID
1923}
1924
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001925typedef MetadataTest MDObjCPropertyTest;
1926
1927TEST_F(MDObjCPropertyTest, get) {
1928 StringRef Name = "name";
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001929 MDFile *File = getFile();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001930 unsigned Line = 5;
1931 StringRef GetterName = "getter";
1932 StringRef SetterName = "setter";
1933 unsigned Attributes = 7;
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001934 MDType *Type = cast<MDBasicType>(getBasicType("basic"));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001935
1936 auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName,
1937 SetterName, Attributes, Type);
1938
1939 EXPECT_EQ(dwarf::DW_TAG_APPLE_property, N->getTag());
1940 EXPECT_EQ(Name, N->getName());
1941 EXPECT_EQ(File, N->getFile());
1942 EXPECT_EQ(Line, N->getLine());
1943 EXPECT_EQ(GetterName, N->getGetterName());
1944 EXPECT_EQ(SetterName, N->getSetterName());
1945 EXPECT_EQ(Attributes, N->getAttributes());
1946 EXPECT_EQ(Type, N->getType());
1947 EXPECT_EQ(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1948 SetterName, Attributes, Type));
1949
1950 EXPECT_NE(N, MDObjCProperty::get(Context, "other", File, Line, GetterName,
1951 SetterName, Attributes, Type));
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001952 EXPECT_NE(N, MDObjCProperty::get(Context, Name, getFile(), Line, GetterName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001953 SetterName, Attributes, Type));
1954 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line + 1, GetterName,
1955 SetterName, Attributes, Type));
1956 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, "other",
1957 SetterName, Attributes, Type));
1958 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1959 "other", Attributes, Type));
1960 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1961 SetterName, Attributes + 1, Type));
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001962 EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
1963 SetterName, Attributes,
1964 cast<MDBasicType>(getBasicType("other"))));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001965
1966 TempMDObjCProperty Temp = N->clone();
1967 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001968}
1969
1970typedef MetadataTest MDImportedEntityTest;
1971
1972TEST_F(MDImportedEntityTest, get) {
1973 unsigned Tag = dwarf::DW_TAG_imported_module;
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001974 MDScope *Scope = getSubprogram();
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +00001975 DebugNodeRef Entity = getCompositeType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001976 unsigned Line = 5;
1977 StringRef Name = "name";
1978
1979 auto *N = MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name);
1980
1981 EXPECT_EQ(Tag, N->getTag());
1982 EXPECT_EQ(Scope, N->getScope());
1983 EXPECT_EQ(Entity, N->getEntity());
1984 EXPECT_EQ(Line, N->getLine());
1985 EXPECT_EQ(Name, N->getName());
1986 EXPECT_EQ(N, MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name));
1987
1988 EXPECT_NE(N,
1989 MDImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration,
1990 Scope, Entity, Line, Name));
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001991 EXPECT_NE(N, MDImportedEntity::get(Context, Tag, getSubprogram(), Entity,
1992 Line, Name));
1993 EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, getCompositeType(),
1994 Line, Name));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001995 EXPECT_NE(N,
1996 MDImportedEntity::get(Context, Tag, Scope, Entity, Line + 1, Name));
1997 EXPECT_NE(N,
1998 MDImportedEntity::get(Context, Tag, Scope, Entity, Line, "other"));
Duncan P. N. Exon Smith6873fea2015-02-17 23:10:13 +00001999
2000 TempMDImportedEntity Temp = N->clone();
2001 EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00002002}
2003
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00002004typedef MetadataTest MetadataAsValueTest;
2005
2006TEST_F(MetadataAsValueTest, MDNode) {
2007 MDNode *N = MDNode::get(Context, None);
2008 auto *V = MetadataAsValue::get(Context, N);
2009 EXPECT_TRUE(V->getType()->isMetadataTy());
2010 EXPECT_EQ(N, V->getMetadata());
2011
2012 auto *V2 = MetadataAsValue::get(Context, N);
2013 EXPECT_EQ(V, V2);
2014}
2015
2016TEST_F(MetadataAsValueTest, MDNodeMDNode) {
2017 MDNode *N = MDNode::get(Context, None);
2018 Metadata *Ops[] = {N};
2019 MDNode *N2 = MDNode::get(Context, Ops);
2020 auto *V = MetadataAsValue::get(Context, N2);
2021 EXPECT_TRUE(V->getType()->isMetadataTy());
2022 EXPECT_EQ(N2, V->getMetadata());
2023
2024 auto *V2 = MetadataAsValue::get(Context, N2);
2025 EXPECT_EQ(V, V2);
2026
2027 auto *V3 = MetadataAsValue::get(Context, N);
2028 EXPECT_TRUE(V3->getType()->isMetadataTy());
2029 EXPECT_NE(V, V3);
2030 EXPECT_EQ(N, V3->getMetadata());
2031}
2032
2033TEST_F(MetadataAsValueTest, MDNodeConstant) {
2034 auto *C = ConstantInt::getTrue(Context);
2035 auto *MD = ConstantAsMetadata::get(C);
2036 Metadata *Ops[] = {MD};
2037 auto *N = MDNode::get(Context, Ops);
2038
2039 auto *V = MetadataAsValue::get(Context, MD);
2040 EXPECT_TRUE(V->getType()->isMetadataTy());
2041 EXPECT_EQ(MD, V->getMetadata());
2042
2043 auto *V2 = MetadataAsValue::get(Context, N);
2044 EXPECT_EQ(MD, V2->getMetadata());
2045 EXPECT_EQ(V, V2);
2046}
2047
Duncan P. N. Exon Smith121eeff2014-12-12 19:24:33 +00002048typedef MetadataTest ValueAsMetadataTest;
2049
2050TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) {
2051 Type *Ty = Type::getInt1PtrTy(Context);
2052 std::unique_ptr<GlobalVariable> GV0(
2053 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
2054 auto *MD = ValueAsMetadata::get(GV0.get());
2055 EXPECT_TRUE(MD->getValue() == GV0.get());
2056 ASSERT_TRUE(GV0->use_empty());
2057
2058 std::unique_ptr<GlobalVariable> GV1(
2059 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
2060 GV0->replaceAllUsesWith(GV1.get());
2061 EXPECT_TRUE(MD->getValue() == GV1.get());
2062}
2063
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00002064TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
2065 // Create a constant.
2066 ConstantAsMetadata *CI = ConstantAsMetadata::get(
2067 ConstantInt::get(getGlobalContext(), APInt(8, 0)));
2068
2069 // Create a temporary to prevent nodes from resolving.
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +00002070 auto Temp = MDTuple::getTemporary(Context, None);
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00002071
2072 // 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 +00002073 Metadata *Ops1[] = {CI, CI, Temp.get()};
2074 Metadata *Ops2[] = {nullptr, CI, Temp.get()};
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00002075
2076 auto *N1 = MDTuple::get(Context, Ops1);
2077 auto *N2 = MDTuple::get(Context, Ops2);
2078 ASSERT_NE(N1, N2);
2079
2080 // Tell metadata that the constant is getting deleted.
2081 //
2082 // After this, N1 will be invalid, so don't touch it.
2083 ValueAsMetadata::handleDeletion(CI->getValue());
2084 EXPECT_EQ(nullptr, N2->getOperand(0));
2085 EXPECT_EQ(nullptr, N2->getOperand(1));
Duncan P. N. Exon Smith7d823132015-01-19 21:30:18 +00002086 EXPECT_EQ(Temp.get(), N2->getOperand(2));
Duncan P. N. Exon Smith4a4f7852015-01-14 19:56:10 +00002087
2088 // Clean up Temp for teardown.
2089 Temp->replaceAllUsesWith(nullptr);
2090}
2091
Duncan P. N. Exon Smith121eeff2014-12-12 19:24:33 +00002092typedef MetadataTest TrackingMDRefTest;
2093
2094TEST_F(TrackingMDRefTest, UpdatesOnRAUW) {
2095 Type *Ty = Type::getInt1PtrTy(Context);
2096 std::unique_ptr<GlobalVariable> GV0(
2097 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
2098 TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV0.get()));
2099 EXPECT_TRUE(MD->getValue() == GV0.get());
2100 ASSERT_TRUE(GV0->use_empty());
2101
2102 std::unique_ptr<GlobalVariable> GV1(
2103 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
2104 GV0->replaceAllUsesWith(GV1.get());
2105 EXPECT_TRUE(MD->getValue() == GV1.get());
2106
2107 // Reset it, so we don't inadvertently test deletion.
2108 MD.reset();
2109}
2110
2111TEST_F(TrackingMDRefTest, UpdatesOnDeletion) {
2112 Type *Ty = Type::getInt1PtrTy(Context);
2113 std::unique_ptr<GlobalVariable> GV(
2114 new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage));
2115 TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV.get()));
2116 EXPECT_TRUE(MD->getValue() == GV.get());
2117 ASSERT_TRUE(GV->use_empty());
2118
2119 GV.reset();
2120 EXPECT_TRUE(!MD);
2121}
2122
Devang Patel0924b332009-07-30 00:03:41 +00002123TEST(NamedMDNodeTest, Search) {
Jeffrey Yasskinbd8a7592010-03-04 23:24:19 +00002124 LLVMContext Context;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00002125 ConstantAsMetadata *C =
2126 ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 1));
2127 ConstantAsMetadata *C2 =
2128 ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 2));
Devang Patel0924b332009-07-30 00:03:41 +00002129
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00002130 Metadata *const V = C;
2131 Metadata *const V2 = C2;
Jay Foad5514afe2011-04-21 19:59:31 +00002132 MDNode *n = MDNode::get(Context, V);
2133 MDNode *n2 = MDNode::get(Context, V2);
Devang Patel0924b332009-07-30 00:03:41 +00002134
Jeffrey Yasskin3d73d1a2010-03-13 01:39:20 +00002135 Module M("MyModule", Context);
Devang Patel0924b332009-07-30 00:03:41 +00002136 const char *Name = "llvm.NMD1";
Dan Gohman2637cc12010-07-21 23:38:33 +00002137 NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name);
2138 NMD->addOperand(n);
2139 NMD->addOperand(n2);
2140
Chris Lattnerbe354a62009-08-23 04:47:35 +00002141 std::string Str;
2142 raw_string_ostream oss(Str);
Devang Patel0924b332009-07-30 00:03:41 +00002143 NMD->print(oss);
Chris Lattner1e6e3672009-12-31 02:12:13 +00002144 EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n",
Devang Patel0924b332009-07-30 00:03:41 +00002145 oss.str().c_str());
2146}
Nick Lewycky49f89192009-04-04 07:22:01 +00002147}