Duncan P. N. Exon Smith | 71db642 | 2015-02-02 18:20:15 +0000 | [diff] [blame] | 1 | //===- unittests/IR/MetadataTest.cpp - Metadata unit tests ----------------===// |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Constants.h" |
Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 12 | #include "llvm/IR/DebugInfo.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 13 | #include "llvm/IR/DebugInfoMetadata.h" |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Function.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Instructions.h" |
| 16 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Metadata.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Module.h" |
| 19 | #include "llvm/IR/Type.h" |
Chandler Carruth | 130cec2 | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 130cec2 | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 21 | #include "gtest/gtest.h" |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | |
Duncan P. N. Exon Smith | 2711ca7 | 2015-01-19 19:02:06 +0000 | [diff] [blame] | 26 | TEST(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 | |
| 34 | TEST(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 | |
| 42 | TEST(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 | |
| 51 | TEST(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 Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 63 | class MetadataTest : public testing::Test { |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 64 | public: |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 65 | MetadataTest() : M("test", Context), Counter(0) {} |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 66 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 67 | protected: |
| 68 | LLVMContext Context; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 69 | Module M; |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 70 | int Counter; |
| 71 | |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 72 | 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 Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 78 | |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 79 | MDTuple *getTuple() { return MDTuple::getDistinct(Context, None); } |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 80 | MDSubroutineType *getSubroutineType() { |
| 81 | return MDSubroutineType::getDistinct(Context, 0, getNode(nullptr)); |
| 82 | } |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 83 | 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 Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 88 | MDScopeRef getSubprogramRef() { return getSubprogram()->getRef(); } |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 89 | MDFile *getFile() { |
| 90 | return MDFile::getDistinct(Context, "file.c", "/path/to/dir"); |
| 91 | } |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 92 | MDTypeRef getBasicType(StringRef Name) { |
| 93 | return MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name) |
| 94 | ->getRef(); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 95 | } |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 96 | MDTypeRef getDerivedType() { |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 97 | return MDDerivedType::getDistinct(Context, dwarf::DW_TAG_pointer_type, "", |
| 98 | nullptr, 0, nullptr, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 99 | getBasicType("basictype"), 1, 2, 0, 0) |
| 100 | ->getRef(); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 101 | } |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 102 | Constant *getConstant() { |
| 103 | return ConstantInt::get(Type::getInt32Ty(Context), Counter++); |
| 104 | } |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 105 | ConstantAsMetadata *getConstantAsMetadata() { |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 106 | return ConstantAsMetadata::get(getConstant()); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 107 | } |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 108 | MDTypeRef getCompositeType() { |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 109 | return MDCompositeType::getDistinct( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 110 | Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr, |
| 111 | nullptr, 32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "") |
| 112 | ->getRef(); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 113 | } |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 114 | Function *getFunction(StringRef Name) { |
| 115 | return cast<Function>(M.getOrInsertFunction( |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 116 | Name, FunctionType::get(Type::getVoidTy(Context), None, false))); |
| 117 | } |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 118 | }; |
| 119 | typedef MetadataTest MDStringTest; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 120 | |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 121 | // Test that construction of MDString with different value produces different |
| 122 | // MDString objects, even with the same string pointer and nulls in the string. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 123 | TEST_F(MDStringTest, CreateDifferent) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 124 | char x[3] = { 'f', 0, 'A' }; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 125 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 126 | x[2] = 'B'; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 127 | MDString *s2 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 128 | EXPECT_NE(s1, s2); |
| 129 | } |
| 130 | |
| 131 | // Test that creation of MDStrings with the same string contents produces the |
| 132 | // same MDString object, even with different pointers. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 133 | TEST_F(MDStringTest, CreateSame) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 134 | char x[4] = { 'a', 'b', 'c', 'X' }; |
| 135 | char y[4] = { 'a', 'b', 'c', 'Y' }; |
| 136 | |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 137 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 138 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 139 | EXPECT_EQ(s1, s2); |
| 140 | } |
| 141 | |
| 142 | // Test that MDString prints out the string we fed it. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 143 | TEST_F(MDStringTest, PrintingSimple) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 144 | char *str = new char[13]; |
| 145 | strncpy(str, "testing 1 2 3", 13); |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 146 | MDString *s = MDString::get(Context, StringRef(str, 13)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 147 | strncpy(str, "aaaaaaaaaaaaa", 13); |
| 148 | delete[] str; |
| 149 | |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 150 | std::string Str; |
| 151 | raw_string_ostream oss(Str); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 152 | s->print(oss); |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 153 | EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str()); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // Test printing of MDString with non-printable characters. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 157 | TEST_F(MDStringTest, PrintingComplex) { |
Jeffrey Yasskin | 065c357 | 2011-08-30 20:53:29 +0000 | [diff] [blame] | 158 | char str[5] = {0, '\n', '"', '\\', (char)-1}; |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 159 | MDString *s = MDString::get(Context, StringRef(str+0, 5)); |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 160 | std::string Str; |
| 161 | raw_string_ostream oss(Str); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 162 | s->print(oss); |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 163 | EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str()); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 166 | typedef MetadataTest MDNodeTest; |
| 167 | |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 168 | // Test the two constructors, and containing other Constants. |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 169 | TEST_F(MDNodeTest, Simple) { |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 170 | char x[3] = { 'a', 'b', 'c' }; |
| 171 | char y[3] = { '1', '2', '3' }; |
| 172 | |
Owen Anderson | 2358732 | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 173 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 174 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 175 | ConstantAsMetadata *CI = ConstantAsMetadata::get( |
| 176 | ConstantInt::get(getGlobalContext(), APInt(8, 0))); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 177 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 178 | std::vector<Metadata *> V; |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 179 | V.push_back(s1); |
| 180 | V.push_back(CI); |
| 181 | V.push_back(s2); |
| 182 | |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 183 | MDNode *n1 = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 184 | Metadata *const c1 = n1; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 185 | MDNode *n2 = MDNode::get(Context, c1); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 186 | Metadata *const c2 = n2; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 187 | MDNode *n3 = MDNode::get(Context, V); |
Duncan Sands | 26a80f3 | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 188 | MDNode *n4 = MDNode::getIfExists(Context, V); |
| 189 | MDNode *n5 = MDNode::getIfExists(Context, c1); |
| 190 | MDNode *n6 = MDNode::getIfExists(Context, c2); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 191 | EXPECT_NE(n1, n2); |
Devang Patel | f718832 | 2009-09-03 01:39:20 +0000 | [diff] [blame] | 192 | EXPECT_EQ(n1, n3); |
Duncan Sands | 26a80f3 | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 193 | EXPECT_EQ(n4, n1); |
| 194 | EXPECT_EQ(n5, n2); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 195 | EXPECT_EQ(n6, (Metadata *)nullptr); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 9b49302 | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 197 | EXPECT_EQ(3u, n1->getNumOperands()); |
| 198 | EXPECT_EQ(s1, n1->getOperand(0)); |
| 199 | EXPECT_EQ(CI, n1->getOperand(1)); |
| 200 | EXPECT_EQ(s2, n1->getOperand(2)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 9b49302 | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 202 | EXPECT_EQ(1u, n2->getNumOperands()); |
| 203 | EXPECT_EQ(n1, n2->getOperand(0)); |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 204 | } |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 205 | |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 206 | TEST_F(MDNodeTest, Delete) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 207 | Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1); |
| 208 | Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext())); |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 209 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 210 | Metadata *const V = LocalAsMetadata::get(I); |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 211 | MDNode *n = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 212 | TrackingMDRef wvh(n); |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 213 | |
| 214 | EXPECT_EQ(n, wvh); |
| 215 | |
| 216 | delete I; |
Nick Lewycky | b8f9b7a | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 217 | } |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 218 | |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 219 | TEST_F(MDNodeTest, SelfReference) { |
Duncan P. N. Exon Smith | 8c66273 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 220 | // !0 = !{!0} |
| 221 | // !1 = !{!0} |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 222 | { |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 223 | auto Temp = MDNode::getTemporary(Context, None); |
| 224 | Metadata *Args[] = {Temp.get()}; |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 225 | MDNode *Self = MDNode::get(Context, Args); |
| 226 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 227 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 228 | |
| 229 | // Self-references should be distinct, so MDNode::get() should grab a |
| 230 | // uniqued node that references Self, not Self. |
| 231 | Args[0] = Self; |
| 232 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 233 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 234 | EXPECT_NE(Self, Ref1); |
| 235 | EXPECT_EQ(Ref1, Ref2); |
| 236 | } |
| 237 | |
Duncan P. N. Exon Smith | 8c66273 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 238 | // !0 = !{!0, !{}} |
| 239 | // !1 = !{!0, !{}} |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 240 | { |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 241 | auto Temp = MDNode::getTemporary(Context, None); |
| 242 | Metadata *Args[] = {Temp.get(), MDNode::get(Context, None)}; |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 243 | MDNode *Self = MDNode::get(Context, Args); |
| 244 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | ac8ee28 | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 245 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 246 | |
| 247 | // Self-references should be distinct, so MDNode::get() should grab a |
| 248 | // uniqued node that references Self, not Self itself. |
| 249 | Args[0] = Self; |
| 250 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 251 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 252 | EXPECT_NE(Self, Ref1); |
| 253 | EXPECT_EQ(Ref1, Ref2); |
| 254 | } |
| 255 | } |
| 256 | |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 257 | TEST_F(MDNodeTest, Print) { |
| 258 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7); |
| 259 | MDString *S = MDString::get(Context, "foo"); |
| 260 | MDNode *N0 = getNode(); |
| 261 | MDNode *N1 = getNode(N0); |
| 262 | MDNode *N2 = getNode(N0, N1); |
| 263 | |
| 264 | Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2}; |
| 265 | MDNode *N = MDNode::get(Context, Args); |
| 266 | |
| 267 | std::string Expected; |
| 268 | { |
| 269 | raw_string_ostream OS(Expected); |
Duncan P. N. Exon Smith | d6d70e7 | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 270 | OS << "<" << (void *)N << "> = !{"; |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 271 | C->printAsOperand(OS); |
| 272 | OS << ", "; |
Duncan P. N. Exon Smith | bb7d2fb | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 273 | S->printAsOperand(OS); |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 274 | OS << ", null"; |
| 275 | MDNode *Nodes[] = {N0, N1, N2}; |
| 276 | for (auto *Node : Nodes) |
| 277 | OS << ", <" << (void *)Node << ">"; |
Duncan P. N. Exon Smith | 738889f | 2015-02-25 22:46:38 +0000 | [diff] [blame] | 278 | OS << "}"; |
Duncan P. N. Exon Smith | fee167f | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | std::string Actual; |
| 282 | { |
| 283 | raw_string_ostream OS(Actual); |
| 284 | N->print(OS); |
| 285 | } |
| 286 | |
| 287 | EXPECT_EQ(Expected, Actual); |
| 288 | } |
| 289 | |
Duncan P. N. Exon Smith | d6d70e7 | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 290 | #define EXPECT_PRINTER_EQ(EXPECTED, PRINT) \ |
| 291 | do { \ |
| 292 | std::string Actual_; \ |
| 293 | raw_string_ostream OS(Actual_); \ |
| 294 | PRINT; \ |
| 295 | OS.flush(); \ |
| 296 | std::string Expected_(EXPECTED); \ |
| 297 | EXPECT_EQ(Expected_, Actual_); \ |
| 298 | } while (false) |
| 299 | |
Duncan P. N. Exon Smith | 3d51066 | 2015-03-16 21:21:10 +0000 | [diff] [blame] | 300 | TEST_F(MDNodeTest, PrintTemporary) { |
| 301 | MDNode *Arg = getNode(); |
| 302 | TempMDNode Temp = MDNode::getTemporary(Context, Arg); |
| 303 | MDNode *N = getNode(Temp.get()); |
| 304 | Module M("test", Context); |
| 305 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("named"); |
| 306 | NMD->addOperand(N); |
| 307 | |
| 308 | EXPECT_PRINTER_EQ("!0 = !{!1}", N->print(OS, &M)); |
| 309 | EXPECT_PRINTER_EQ("!1 = <temporary!> !{!2}", Temp->print(OS, &M)); |
| 310 | EXPECT_PRINTER_EQ("!2 = !{}", Arg->print(OS, &M)); |
| 311 | |
| 312 | // Cleanup. |
| 313 | Temp->replaceAllUsesWith(Arg); |
| 314 | } |
| 315 | |
Duncan P. N. Exon Smith | d6d70e7 | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 316 | TEST_F(MDNodeTest, PrintFromModule) { |
| 317 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7); |
| 318 | MDString *S = MDString::get(Context, "foo"); |
| 319 | MDNode *N0 = getNode(); |
| 320 | MDNode *N1 = getNode(N0); |
| 321 | MDNode *N2 = getNode(N0, N1); |
| 322 | |
| 323 | Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2}; |
| 324 | MDNode *N = MDNode::get(Context, Args); |
| 325 | Module M("test", Context); |
| 326 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("named"); |
| 327 | NMD->addOperand(N); |
| 328 | |
| 329 | std::string Expected; |
| 330 | { |
| 331 | raw_string_ostream OS(Expected); |
| 332 | OS << "!0 = !{"; |
| 333 | C->printAsOperand(OS); |
| 334 | OS << ", "; |
| 335 | S->printAsOperand(OS); |
| 336 | OS << ", null, !1, !2, !3}"; |
| 337 | } |
| 338 | |
| 339 | EXPECT_PRINTER_EQ(Expected, N->print(OS, &M)); |
| 340 | } |
| 341 | |
| 342 | TEST_F(MDNodeTest, PrintFromFunction) { |
| 343 | Module M("test", Context); |
| 344 | auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); |
| 345 | auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); |
| 346 | auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); |
| 347 | auto *BB0 = BasicBlock::Create(Context, "entry", F0); |
| 348 | auto *BB1 = BasicBlock::Create(Context, "entry", F1); |
| 349 | auto *R0 = ReturnInst::Create(Context, BB0); |
| 350 | auto *R1 = ReturnInst::Create(Context, BB1); |
| 351 | auto *N0 = MDNode::getDistinct(Context, None); |
| 352 | auto *N1 = MDNode::getDistinct(Context, None); |
| 353 | R0->setMetadata("md", N0); |
| 354 | R1->setMetadata("md", N1); |
| 355 | |
| 356 | EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M)); |
| 357 | EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M)); |
| 358 | } |
| 359 | |
| 360 | TEST_F(MDNodeTest, PrintFromMetadataAsValue) { |
| 361 | Module M("test", Context); |
| 362 | |
| 363 | auto *Intrinsic = |
| 364 | Function::Create(FunctionType::get(Type::getVoidTy(Context), |
| 365 | Type::getMetadataTy(Context), false), |
| 366 | GlobalValue::ExternalLinkage, "llvm.intrinsic", &M); |
| 367 | |
| 368 | auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); |
| 369 | auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); |
| 370 | auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); |
| 371 | auto *BB0 = BasicBlock::Create(Context, "entry", F0); |
| 372 | auto *BB1 = BasicBlock::Create(Context, "entry", F1); |
| 373 | auto *N0 = MDNode::getDistinct(Context, None); |
| 374 | auto *N1 = MDNode::getDistinct(Context, None); |
| 375 | auto *MAV0 = MetadataAsValue::get(Context, N0); |
| 376 | auto *MAV1 = MetadataAsValue::get(Context, N1); |
| 377 | CallInst::Create(Intrinsic, MAV0, "", BB0); |
| 378 | CallInst::Create(Intrinsic, MAV1, "", BB1); |
| 379 | |
| 380 | EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS)); |
| 381 | EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS)); |
| 382 | EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false)); |
| 383 | EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false)); |
| 384 | EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true)); |
| 385 | EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true)); |
| 386 | } |
| 387 | #undef EXPECT_PRINTER_EQ |
| 388 | |
Duncan P. N. Exon Smith | bcd960a | 2015-01-05 23:31:54 +0000 | [diff] [blame] | 389 | TEST_F(MDNodeTest, NullOperand) { |
| 390 | // metadata !{} |
| 391 | MDNode *Empty = MDNode::get(Context, None); |
| 392 | |
| 393 | // metadata !{metadata !{}} |
| 394 | Metadata *Ops[] = {Empty}; |
| 395 | MDNode *N = MDNode::get(Context, Ops); |
| 396 | ASSERT_EQ(Empty, N->getOperand(0)); |
| 397 | |
| 398 | // metadata !{metadata !{}} => metadata !{null} |
| 399 | N->replaceOperandWith(0, nullptr); |
| 400 | ASSERT_EQ(nullptr, N->getOperand(0)); |
| 401 | |
| 402 | // metadata !{null} |
| 403 | Ops[0] = nullptr; |
| 404 | MDNode *NullOp = MDNode::get(Context, Ops); |
| 405 | ASSERT_EQ(nullptr, NullOp->getOperand(0)); |
| 406 | EXPECT_EQ(N, NullOp); |
| 407 | } |
| 408 | |
Duncan P. N. Exon Smith | 136ea3f | 2015-01-07 21:35:38 +0000 | [diff] [blame] | 409 | TEST_F(MDNodeTest, DistinctOnUniquingCollision) { |
| 410 | // !{} |
| 411 | MDNode *Empty = MDNode::get(Context, None); |
| 412 | ASSERT_TRUE(Empty->isResolved()); |
| 413 | EXPECT_FALSE(Empty->isDistinct()); |
| 414 | |
| 415 | // !{!{}} |
| 416 | Metadata *Wrapped1Ops[] = {Empty}; |
| 417 | MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops); |
| 418 | ASSERT_EQ(Empty, Wrapped1->getOperand(0)); |
| 419 | ASSERT_TRUE(Wrapped1->isResolved()); |
| 420 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 421 | |
| 422 | // !{!{!{}}} |
| 423 | Metadata *Wrapped2Ops[] = {Wrapped1}; |
| 424 | MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops); |
| 425 | ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0)); |
| 426 | ASSERT_TRUE(Wrapped2->isResolved()); |
| 427 | EXPECT_FALSE(Wrapped2->isDistinct()); |
| 428 | |
| 429 | // !{!{!{}}} => !{!{}} |
| 430 | Wrapped2->replaceOperandWith(0, Empty); |
| 431 | ASSERT_EQ(Empty, Wrapped2->getOperand(0)); |
| 432 | EXPECT_TRUE(Wrapped2->isDistinct()); |
| 433 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 434 | } |
| 435 | |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 436 | TEST_F(MDNodeTest, getDistinct) { |
| 437 | // !{} |
| 438 | MDNode *Empty = MDNode::get(Context, None); |
| 439 | ASSERT_TRUE(Empty->isResolved()); |
| 440 | ASSERT_FALSE(Empty->isDistinct()); |
| 441 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 442 | |
| 443 | // distinct !{} |
| 444 | MDNode *Distinct1 = MDNode::getDistinct(Context, None); |
| 445 | MDNode *Distinct2 = MDNode::getDistinct(Context, None); |
| 446 | EXPECT_TRUE(Distinct1->isResolved()); |
| 447 | EXPECT_TRUE(Distinct2->isDistinct()); |
| 448 | EXPECT_NE(Empty, Distinct1); |
| 449 | EXPECT_NE(Empty, Distinct2); |
| 450 | EXPECT_NE(Distinct1, Distinct2); |
| 451 | |
| 452 | // !{} |
| 453 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 454 | } |
| 455 | |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 456 | TEST_F(MDNodeTest, isUniqued) { |
| 457 | MDNode *U = MDTuple::get(Context, None); |
| 458 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 459 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 460 | EXPECT_TRUE(U->isUniqued()); |
| 461 | EXPECT_FALSE(D->isUniqued()); |
| 462 | EXPECT_FALSE(T->isUniqued()); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | TEST_F(MDNodeTest, isDistinct) { |
| 466 | MDNode *U = MDTuple::get(Context, None); |
| 467 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 468 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 469 | EXPECT_FALSE(U->isDistinct()); |
| 470 | EXPECT_TRUE(D->isDistinct()); |
| 471 | EXPECT_FALSE(T->isDistinct()); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | TEST_F(MDNodeTest, isTemporary) { |
| 475 | MDNode *U = MDTuple::get(Context, None); |
| 476 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 477 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | de03a8b | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 478 | EXPECT_FALSE(U->isTemporary()); |
| 479 | EXPECT_FALSE(D->isTemporary()); |
| 480 | EXPECT_TRUE(T->isTemporary()); |
Duncan P. N. Exon Smith | d1474ee | 2015-01-12 18:41:26 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 483 | TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) { |
| 484 | // temporary !{} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 485 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 486 | ASSERT_FALSE(Temp->isResolved()); |
| 487 | |
| 488 | // distinct !{temporary !{}} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 489 | Metadata *Ops[] = {Temp.get()}; |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 490 | MDNode *Distinct = MDNode::getDistinct(Context, Ops); |
| 491 | EXPECT_TRUE(Distinct->isResolved()); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 492 | EXPECT_EQ(Temp.get(), Distinct->getOperand(0)); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 493 | |
| 494 | // temporary !{} => !{} |
| 495 | MDNode *Empty = MDNode::get(Context, None); |
| 496 | Temp->replaceAllUsesWith(Empty); |
Duncan P. N. Exon Smith | 5e5b850 | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 497 | EXPECT_EQ(Empty, Distinct->getOperand(0)); |
| 498 | } |
| 499 | |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 500 | TEST_F(MDNodeTest, handleChangedOperandRecursion) { |
| 501 | // !0 = !{} |
| 502 | MDNode *N0 = MDNode::get(Context, None); |
| 503 | |
| 504 | // !1 = !{!3, null} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 505 | auto Temp3 = MDTuple::getTemporary(Context, None); |
| 506 | Metadata *Ops1[] = {Temp3.get(), nullptr}; |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 507 | MDNode *N1 = MDNode::get(Context, Ops1); |
| 508 | |
| 509 | // !2 = !{!3, !0} |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 510 | Metadata *Ops2[] = {Temp3.get(), N0}; |
Duncan P. N. Exon Smith | 5f46189 | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 511 | MDNode *N2 = MDNode::get(Context, Ops2); |
| 512 | |
| 513 | // !3 = !{!2} |
| 514 | Metadata *Ops3[] = {N2}; |
| 515 | MDNode *N3 = MDNode::get(Context, Ops3); |
| 516 | Temp3->replaceAllUsesWith(N3); |
| 517 | |
| 518 | // !4 = !{!1} |
| 519 | Metadata *Ops4[] = {N1}; |
| 520 | MDNode *N4 = MDNode::get(Context, Ops4); |
| 521 | |
| 522 | // Confirm that the cycle prevented RAUW from getting dropped. |
| 523 | EXPECT_TRUE(N0->isResolved()); |
| 524 | EXPECT_FALSE(N1->isResolved()); |
| 525 | EXPECT_FALSE(N2->isResolved()); |
| 526 | EXPECT_FALSE(N3->isResolved()); |
| 527 | EXPECT_FALSE(N4->isResolved()); |
| 528 | |
| 529 | // Create a couple of distinct nodes to observe what's going on. |
| 530 | // |
| 531 | // !5 = distinct !{!2} |
| 532 | // !6 = distinct !{!3} |
| 533 | Metadata *Ops5[] = {N2}; |
| 534 | MDNode *N5 = MDNode::getDistinct(Context, Ops5); |
| 535 | Metadata *Ops6[] = {N3}; |
| 536 | MDNode *N6 = MDNode::getDistinct(Context, Ops6); |
| 537 | |
| 538 | // Mutate !2 to look like !1, causing a uniquing collision (and an RAUW). |
| 539 | // This will ripple up, with !3 colliding with !4, and RAUWing. Since !2 |
| 540 | // references !3, this can cause a re-entry of handleChangedOperand() when !3 |
| 541 | // is not ready for it. |
| 542 | // |
| 543 | // !2->replaceOperandWith(1, nullptr) |
| 544 | // !2: !{!3, !0} => !{!3, null} |
| 545 | // !2->replaceAllUsesWith(!1) |
| 546 | // !3: !{!2] => !{!1} |
| 547 | // !3->replaceAllUsesWith(!4) |
| 548 | N2->replaceOperandWith(1, nullptr); |
| 549 | |
| 550 | // If all has gone well, N2 and N3 will have been RAUW'ed and deleted from |
| 551 | // under us. Just check that the other nodes are sane. |
| 552 | // |
| 553 | // !1 = !{!4, null} |
| 554 | // !4 = !{!1} |
| 555 | // !5 = distinct !{!1} |
| 556 | // !6 = distinct !{!4} |
| 557 | EXPECT_EQ(N4, N1->getOperand(0)); |
| 558 | EXPECT_EQ(N1, N4->getOperand(0)); |
| 559 | EXPECT_EQ(N1, N5->getOperand(0)); |
| 560 | EXPECT_EQ(N4, N6->getOperand(0)); |
| 561 | } |
| 562 | |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 563 | TEST_F(MDNodeTest, replaceResolvedOperand) { |
| 564 | // Check code for replacing one resolved operand with another. If doing this |
| 565 | // directly (via replaceOperandWith()) becomes illegal, change the operand to |
| 566 | // a global value that gets RAUW'ed. |
| 567 | // |
| 568 | // Use a temporary node to keep N from being resolved. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 569 | auto Temp = MDTuple::getTemporary(Context, None); |
| 570 | Metadata *Ops[] = {nullptr, Temp.get()}; |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 571 | |
NAKAMURA Takumi | 2f8f054 | 2015-01-13 08:13:46 +0000 | [diff] [blame] | 572 | MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>()); |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 573 | MDNode *N = MDTuple::get(Context, Ops); |
| 574 | EXPECT_EQ(nullptr, N->getOperand(0)); |
| 575 | ASSERT_FALSE(N->isResolved()); |
| 576 | |
| 577 | // Check code for replacing resolved nodes. |
| 578 | N->replaceOperandWith(0, Empty); |
| 579 | EXPECT_EQ(Empty, N->getOperand(0)); |
| 580 | |
| 581 | // Check code for adding another unresolved operand. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 582 | N->replaceOperandWith(0, Temp.get()); |
| 583 | EXPECT_EQ(Temp.get(), N->getOperand(0)); |
Duncan P. N. Exon Smith | 845755c4 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 584 | |
| 585 | // Remove the references to Temp; required for teardown. |
| 586 | Temp->replaceAllUsesWith(nullptr); |
| 587 | } |
| 588 | |
Duncan P. N. Exon Smith | e335309 | 2015-01-19 22:24:52 +0000 | [diff] [blame] | 589 | TEST_F(MDNodeTest, replaceWithUniqued) { |
| 590 | auto *Empty = MDTuple::get(Context, None); |
| 591 | MDTuple *FirstUniqued; |
| 592 | { |
| 593 | Metadata *Ops[] = {Empty}; |
| 594 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 595 | EXPECT_TRUE(Temp->isTemporary()); |
| 596 | |
| 597 | // Don't expect a collision. |
| 598 | auto *Current = Temp.get(); |
| 599 | FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 600 | EXPECT_TRUE(FirstUniqued->isUniqued()); |
| 601 | EXPECT_TRUE(FirstUniqued->isResolved()); |
| 602 | EXPECT_EQ(Current, FirstUniqued); |
| 603 | } |
| 604 | { |
| 605 | Metadata *Ops[] = {Empty}; |
| 606 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 607 | EXPECT_TRUE(Temp->isTemporary()); |
| 608 | |
| 609 | // Should collide with Uniqued above this time. |
| 610 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 611 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 612 | EXPECT_TRUE(Uniqued->isResolved()); |
| 613 | EXPECT_EQ(FirstUniqued, Uniqued); |
| 614 | } |
| 615 | { |
| 616 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 617 | Metadata *Ops[] = {Unresolved.get()}; |
| 618 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 619 | EXPECT_TRUE(Temp->isTemporary()); |
| 620 | |
| 621 | // Shouldn't be resolved. |
| 622 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 623 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 624 | EXPECT_FALSE(Uniqued->isResolved()); |
| 625 | |
| 626 | // Should be a different node. |
| 627 | EXPECT_NE(FirstUniqued, Uniqued); |
| 628 | |
| 629 | // Should resolve when we update its node (note: be careful to avoid a |
| 630 | // collision with any other nodes above). |
| 631 | Uniqued->replaceOperandWith(0, nullptr); |
| 632 | EXPECT_TRUE(Uniqued->isResolved()); |
| 633 | } |
| 634 | } |
| 635 | |
Duncan P. N. Exon Smith | 014f1b8 | 2015-03-31 21:05:06 +0000 | [diff] [blame] | 636 | TEST_F(MDNodeTest, replaceWithUniquedResolvingOperand) { |
Duncan P. N. Exon Smith | cb33d6f | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 637 | // temp !{} |
| 638 | MDTuple *Op = MDTuple::getTemporary(Context, None).release(); |
| 639 | EXPECT_FALSE(Op->isResolved()); |
| 640 | |
| 641 | // temp !{temp !{}} |
| 642 | Metadata *Ops[] = {Op}; |
| 643 | MDTuple *N = MDTuple::getTemporary(Context, Ops).release(); |
| 644 | EXPECT_FALSE(N->isResolved()); |
| 645 | |
| 646 | // temp !{temp !{}} => !{temp !{}} |
| 647 | ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N))); |
| 648 | EXPECT_FALSE(N->isResolved()); |
| 649 | |
| 650 | // !{temp !{}} => !{!{}} |
| 651 | ASSERT_EQ(Op, MDNode::replaceWithUniqued(TempMDTuple(Op))); |
| 652 | EXPECT_TRUE(Op->isResolved()); |
| 653 | EXPECT_TRUE(N->isResolved()); |
| 654 | } |
| 655 | |
Duncan P. N. Exon Smith | 014f1b8 | 2015-03-31 21:05:06 +0000 | [diff] [blame] | 656 | TEST_F(MDNodeTest, replaceWithUniquedChangingOperand) { |
Duncan P. N. Exon Smith | cb33d6f | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 657 | // i1* @GV |
| 658 | Type *Ty = Type::getInt1PtrTy(Context); |
| 659 | std::unique_ptr<GlobalVariable> GV( |
| 660 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 661 | ConstantAsMetadata *Op = ConstantAsMetadata::get(GV.get()); |
| 662 | |
| 663 | // temp !{i1* @GV} |
| 664 | Metadata *Ops[] = {Op}; |
| 665 | MDTuple *N = MDTuple::getTemporary(Context, Ops).release(); |
| 666 | |
| 667 | // temp !{i1* @GV} => !{i1* @GV} |
| 668 | ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N))); |
| 669 | ASSERT_TRUE(N->isUniqued()); |
| 670 | |
| 671 | // !{i1* @GV} => !{null} |
| 672 | GV.reset(); |
| 673 | ASSERT_TRUE(N->isUniqued()); |
| 674 | Metadata *NullOps[] = {nullptr}; |
| 675 | ASSERT_EQ(N, MDTuple::get(Context, NullOps)); |
| 676 | } |
| 677 | |
Duncan P. N. Exon Smith | e335309 | 2015-01-19 22:24:52 +0000 | [diff] [blame] | 678 | TEST_F(MDNodeTest, replaceWithDistinct) { |
| 679 | { |
| 680 | auto *Empty = MDTuple::get(Context, None); |
| 681 | Metadata *Ops[] = {Empty}; |
| 682 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 683 | EXPECT_TRUE(Temp->isTemporary()); |
| 684 | |
| 685 | // Don't expect a collision. |
| 686 | auto *Current = Temp.get(); |
| 687 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 688 | EXPECT_TRUE(Distinct->isDistinct()); |
| 689 | EXPECT_TRUE(Distinct->isResolved()); |
| 690 | EXPECT_EQ(Current, Distinct); |
| 691 | } |
| 692 | { |
| 693 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 694 | Metadata *Ops[] = {Unresolved.get()}; |
| 695 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 696 | EXPECT_TRUE(Temp->isTemporary()); |
| 697 | |
| 698 | // Don't expect a collision. |
| 699 | auto *Current = Temp.get(); |
| 700 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 701 | EXPECT_TRUE(Distinct->isDistinct()); |
| 702 | EXPECT_TRUE(Distinct->isResolved()); |
| 703 | EXPECT_EQ(Current, Distinct); |
| 704 | |
| 705 | // Cleanup; required for teardown. |
| 706 | Unresolved->replaceAllUsesWith(nullptr); |
| 707 | } |
| 708 | } |
| 709 | |
Duncan P. N. Exon Smith | 4ee4a98 | 2015-02-10 19:13:46 +0000 | [diff] [blame] | 710 | TEST_F(MDNodeTest, replaceWithPermanent) { |
| 711 | Metadata *Ops[] = {nullptr}; |
| 712 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 713 | auto *T = Temp.get(); |
| 714 | |
| 715 | // U is a normal, uniqued node that references T. |
| 716 | auto *U = MDTuple::get(Context, T); |
| 717 | EXPECT_TRUE(U->isUniqued()); |
| 718 | |
| 719 | // Make Temp self-referencing. |
| 720 | Temp->replaceOperandWith(0, T); |
| 721 | |
| 722 | // Try to uniquify Temp. This should, despite the name in the API, give a |
| 723 | // 'distinct' node, since self-references aren't allowed to be uniqued. |
| 724 | // |
| 725 | // Since it's distinct, N should have the same address as when it was a |
| 726 | // temporary (i.e., be equal to T not U). |
| 727 | auto *N = MDNode::replaceWithPermanent(std::move(Temp)); |
| 728 | EXPECT_EQ(N, T); |
| 729 | EXPECT_TRUE(N->isDistinct()); |
| 730 | |
| 731 | // U should be the canonical unique node with N as the argument. |
| 732 | EXPECT_EQ(U, MDTuple::get(Context, N)); |
| 733 | EXPECT_TRUE(U->isUniqued()); |
| 734 | |
| 735 | // This temporary should collide with U when replaced, but it should still be |
| 736 | // uniqued. |
| 737 | EXPECT_EQ(U, MDNode::replaceWithPermanent(MDTuple::getTemporary(Context, N))); |
| 738 | EXPECT_TRUE(U->isUniqued()); |
| 739 | |
| 740 | // This temporary should become a new uniqued node. |
| 741 | auto Temp2 = MDTuple::getTemporary(Context, U); |
| 742 | auto *V = Temp2.get(); |
| 743 | EXPECT_EQ(V, MDNode::replaceWithPermanent(std::move(Temp2))); |
| 744 | EXPECT_TRUE(V->isUniqued()); |
| 745 | EXPECT_EQ(U, V->getOperand(0)); |
| 746 | } |
| 747 | |
Duncan P. N. Exon Smith | 8d53697 | 2015-01-22 21:36:45 +0000 | [diff] [blame] | 748 | TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) { |
| 749 | TrackingMDRef Ref; |
| 750 | EXPECT_EQ(nullptr, Ref.get()); |
| 751 | { |
| 752 | auto Temp = MDTuple::getTemporary(Context, None); |
| 753 | Ref.reset(Temp.get()); |
| 754 | EXPECT_EQ(Temp.get(), Ref.get()); |
| 755 | } |
| 756 | EXPECT_EQ(nullptr, Ref.get()); |
| 757 | } |
| 758 | |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 759 | typedef MetadataTest MDLocationTest; |
| 760 | |
| 761 | TEST_F(MDLocationTest, Overflow) { |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 762 | MDSubprogram *N = getSubprogram(); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 763 | { |
| 764 | MDLocation *L = MDLocation::get(Context, 2, 7, N); |
| 765 | EXPECT_EQ(2u, L->getLine()); |
| 766 | EXPECT_EQ(7u, L->getColumn()); |
| 767 | } |
Duncan P. N. Exon Smith | 2f5bb31 | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 768 | unsigned U16 = 1u << 16; |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 769 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 770 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 - 1, N); |
| 771 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | 2f5bb31 | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 772 | EXPECT_EQ(U16 - 1, L->getColumn()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 773 | } |
| 774 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 775 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16, N); |
| 776 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 777 | EXPECT_EQ(0u, L->getColumn()); |
| 778 | } |
| 779 | { |
Duncan P. N. Exon Smith | af677eb | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 780 | MDLocation *L = MDLocation::get(Context, UINT32_MAX, U16 + 1, N); |
| 781 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 782 | EXPECT_EQ(0u, L->getColumn()); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | TEST_F(MDLocationTest, getDistinct) { |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 787 | MDNode *N = getSubprogram(); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 788 | MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N); |
| 789 | EXPECT_TRUE(L0->isDistinct()); |
| 790 | MDLocation *L1 = MDLocation::get(Context, 2, 7, N); |
| 791 | EXPECT_FALSE(L1->isDistinct()); |
| 792 | EXPECT_EQ(L1, MDLocation::get(Context, 2, 7, N)); |
| 793 | } |
| 794 | |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 795 | TEST_F(MDLocationTest, getTemporary) { |
| 796 | MDNode *N = MDNode::get(Context, None); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 797 | auto L = MDLocation::getTemporary(Context, 2, 7, N); |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 798 | EXPECT_TRUE(L->isTemporary()); |
| 799 | EXPECT_FALSE(L->isResolved()); |
Duncan P. N. Exon Smith | 799e56a | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 802 | typedef MetadataTest GenericDebugNodeTest; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 803 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 804 | TEST_F(GenericDebugNodeTest, get) { |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 805 | StringRef Header = "header"; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 806 | auto *Empty = MDNode::get(Context, None); |
| 807 | Metadata *Ops1[] = {Empty}; |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 808 | auto *N = GenericDebugNode::get(Context, 15, Header, Ops1); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 809 | EXPECT_EQ(15u, N->getTag()); |
| 810 | EXPECT_EQ(2u, N->getNumOperands()); |
| 811 | EXPECT_EQ(Header, N->getHeader()); |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 812 | EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 813 | EXPECT_EQ(1u, N->getNumDwarfOperands()); |
| 814 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 815 | EXPECT_EQ(Empty, N->getOperand(1)); |
| 816 | ASSERT_TRUE(N->isUniqued()); |
| 817 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 818 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 819 | |
| 820 | N->replaceOperandWith(1, nullptr); |
| 821 | EXPECT_EQ(15u, N->getTag()); |
| 822 | EXPECT_EQ(Header, N->getHeader()); |
| 823 | EXPECT_EQ(nullptr, N->getDwarfOperand(0)); |
| 824 | ASSERT_TRUE(N->isUniqued()); |
| 825 | |
| 826 | Metadata *Ops2[] = {nullptr}; |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 827 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops2)); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 828 | |
| 829 | N->replaceDwarfOperandWith(0, Empty); |
| 830 | EXPECT_EQ(15u, N->getTag()); |
| 831 | EXPECT_EQ(Header, N->getHeader()); |
| 832 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 833 | ASSERT_TRUE(N->isUniqued()); |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 834 | EXPECT_EQ(N, GenericDebugNode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 835 | |
| 836 | TempGenericDebugNode Temp = N->clone(); |
| 837 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Duncan P. N. Exon Smith | e8b5e49 | 2015-01-22 22:47:44 +0000 | [diff] [blame] | 840 | TEST_F(GenericDebugNodeTest, getEmptyHeader) { |
Duncan P. N. Exon Smith | 2da09e4 | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 841 | // Canonicalize !"" to null. |
Duncan P. N. Exon Smith | 68ab023 | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 842 | auto *N = GenericDebugNode::get(Context, 15, StringRef(), None); |
| 843 | EXPECT_EQ(StringRef(), N->getHeader()); |
| 844 | EXPECT_EQ(nullptr, N->getOperand(0)); |
Duncan P. N. Exon Smith | 2da09e4 | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 847 | typedef MetadataTest MDSubrangeTest; |
| 848 | |
| 849 | TEST_F(MDSubrangeTest, get) { |
| 850 | auto *N = MDSubrange::get(Context, 5, 7); |
| 851 | EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); |
| 852 | EXPECT_EQ(5, N->getCount()); |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 853 | EXPECT_EQ(7, N->getLowerBound()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 854 | EXPECT_EQ(N, MDSubrange::get(Context, 5, 7)); |
| 855 | EXPECT_EQ(MDSubrange::get(Context, 5, 0), MDSubrange::get(Context, 5)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 856 | |
| 857 | TempMDSubrange Temp = N->clone(); |
| 858 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Duncan P. N. Exon Smith | 5c9a177 | 2015-02-18 23:17:51 +0000 | [diff] [blame] | 861 | TEST_F(MDSubrangeTest, getEmptyArray) { |
| 862 | auto *N = MDSubrange::get(Context, -1, 0); |
| 863 | EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); |
| 864 | EXPECT_EQ(-1, N->getCount()); |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 865 | EXPECT_EQ(0, N->getLowerBound()); |
Duncan P. N. Exon Smith | 5c9a177 | 2015-02-18 23:17:51 +0000 | [diff] [blame] | 866 | EXPECT_EQ(N, MDSubrange::get(Context, -1, 0)); |
| 867 | } |
| 868 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 869 | typedef MetadataTest MDEnumeratorTest; |
| 870 | |
| 871 | TEST_F(MDEnumeratorTest, get) { |
| 872 | auto *N = MDEnumerator::get(Context, 7, "name"); |
| 873 | EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag()); |
| 874 | EXPECT_EQ(7, N->getValue()); |
| 875 | EXPECT_EQ("name", N->getName()); |
| 876 | EXPECT_EQ(N, MDEnumerator::get(Context, 7, "name")); |
| 877 | |
| 878 | EXPECT_NE(N, MDEnumerator::get(Context, 8, "name")); |
| 879 | EXPECT_NE(N, MDEnumerator::get(Context, 7, "nam")); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 880 | |
| 881 | TempMDEnumerator Temp = N->clone(); |
| 882 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | typedef MetadataTest MDBasicTypeTest; |
| 886 | |
| 887 | TEST_F(MDBasicTypeTest, get) { |
| 888 | auto *N = |
| 889 | MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7); |
| 890 | EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag()); |
| 891 | EXPECT_EQ("special", N->getName()); |
| 892 | EXPECT_EQ(33u, N->getSizeInBits()); |
| 893 | EXPECT_EQ(26u, N->getAlignInBits()); |
| 894 | EXPECT_EQ(7u, N->getEncoding()); |
| 895 | EXPECT_EQ(0u, N->getLine()); |
| 896 | EXPECT_EQ(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 897 | 26, 7)); |
| 898 | |
| 899 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, |
| 900 | "special", 33, 26, 7)); |
| 901 | EXPECT_NE(N, |
| 902 | MDBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7)); |
| 903 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32, |
| 904 | 26, 7)); |
| 905 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 906 | 25, 7)); |
| 907 | EXPECT_NE(N, MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 908 | 26, 6)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 909 | |
| 910 | TempMDBasicType Temp = N->clone(); |
| 911 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 914 | TEST_F(MDBasicTypeTest, getWithLargeValues) { |
| 915 | auto *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "special", |
| 916 | UINT64_MAX, UINT64_MAX - 1, 7); |
| 917 | EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); |
| 918 | EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits()); |
| 919 | } |
| 920 | |
Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 921 | TEST_F(MDBasicTypeTest, getUnspecified) { |
| 922 | auto *N = |
| 923 | MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, "unspecified"); |
| 924 | EXPECT_EQ(dwarf::DW_TAG_unspecified_type, N->getTag()); |
| 925 | EXPECT_EQ("unspecified", N->getName()); |
| 926 | EXPECT_EQ(0u, N->getSizeInBits()); |
| 927 | EXPECT_EQ(0u, N->getAlignInBits()); |
| 928 | EXPECT_EQ(0u, N->getEncoding()); |
| 929 | EXPECT_EQ(0u, N->getLine()); |
| 930 | } |
| 931 | |
| 932 | typedef MetadataTest MDTypeTest; |
| 933 | |
| 934 | TEST_F(MDTypeTest, clone) { |
| 935 | // Check that MDType has a specialized clone that returns TempMDType. |
| 936 | MDType *N = MDBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32, |
| 937 | dwarf::DW_ATE_signed); |
| 938 | |
| 939 | TempMDType Temp = N->clone(); |
| 940 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
| 941 | } |
| 942 | |
| 943 | TEST_F(MDTypeTest, setFlags) { |
| 944 | // void (void) |
| 945 | Metadata *TypesOps[] = {nullptr}; |
| 946 | Metadata *Types = MDTuple::get(Context, TypesOps); |
| 947 | |
| 948 | MDType *D = MDSubroutineType::getDistinct(Context, 0u, Types); |
| 949 | EXPECT_EQ(0u, D->getFlags()); |
| 950 | D->setFlags(DIDescriptor::FlagRValueReference); |
| 951 | EXPECT_EQ(DIDescriptor::FlagRValueReference, D->getFlags()); |
| 952 | D->setFlags(0u); |
| 953 | EXPECT_EQ(0u, D->getFlags()); |
| 954 | |
| 955 | TempMDType T = MDSubroutineType::getTemporary(Context, 0u, Types); |
| 956 | EXPECT_EQ(0u, T->getFlags()); |
| 957 | T->setFlags(DIDescriptor::FlagRValueReference); |
| 958 | EXPECT_EQ(DIDescriptor::FlagRValueReference, T->getFlags()); |
| 959 | T->setFlags(0u); |
| 960 | EXPECT_EQ(0u, T->getFlags()); |
| 961 | } |
| 962 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 963 | typedef MetadataTest MDDerivedTypeTest; |
| 964 | |
| 965 | TEST_F(MDDerivedTypeTest, get) { |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 966 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 967 | MDScopeRef Scope = getSubprogramRef(); |
| 968 | MDTypeRef BaseType = getBasicType("basic"); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 969 | MDTuple *ExtraData = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 970 | |
| 971 | auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 972 | File, 1, Scope, BaseType, 2, 3, 4, 5, ExtraData); |
| 973 | EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag()); |
| 974 | EXPECT_EQ("something", N->getName()); |
| 975 | EXPECT_EQ(File, N->getFile()); |
| 976 | EXPECT_EQ(1u, N->getLine()); |
| 977 | EXPECT_EQ(Scope, N->getScope()); |
| 978 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 979 | EXPECT_EQ(2u, N->getSizeInBits()); |
| 980 | EXPECT_EQ(3u, N->getAlignInBits()); |
| 981 | EXPECT_EQ(4u, N->getOffsetInBits()); |
| 982 | EXPECT_EQ(5u, N->getFlags()); |
| 983 | EXPECT_EQ(ExtraData, N->getExtraData()); |
| 984 | EXPECT_EQ(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 985 | "something", File, 1, Scope, BaseType, 2, 3, |
| 986 | 4, 5, ExtraData)); |
| 987 | |
| 988 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_reference_type, |
| 989 | "something", File, 1, Scope, BaseType, 2, 3, |
| 990 | 4, 5, ExtraData)); |
| 991 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else", |
| 992 | File, 1, Scope, BaseType, 2, 3, 4, 5, |
| 993 | ExtraData)); |
| 994 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 995 | "something", getFile(), 1, Scope, BaseType, 2, |
| 996 | 3, 4, 5, ExtraData)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 997 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 998 | "something", File, 2, Scope, BaseType, 2, 3, |
| 999 | 4, 5, ExtraData)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1000 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1001 | "something", File, 1, getSubprogramRef(), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1002 | BaseType, 2, 3, 4, 5, ExtraData)); |
| 1003 | EXPECT_NE(N, MDDerivedType::get( |
| 1004 | Context, dwarf::DW_TAG_pointer_type, "something", File, 1, |
| 1005 | Scope, getBasicType("basic2"), 2, 3, 4, 5, ExtraData)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1006 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1007 | "something", File, 1, Scope, BaseType, 3, 3, |
| 1008 | 4, 5, ExtraData)); |
| 1009 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1010 | "something", File, 1, Scope, BaseType, 2, 2, |
| 1011 | 4, 5, ExtraData)); |
| 1012 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1013 | "something", File, 1, Scope, BaseType, 2, 3, |
| 1014 | 5, 5, ExtraData)); |
| 1015 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1016 | "something", File, 1, Scope, BaseType, 2, 3, |
| 1017 | 4, 4, ExtraData)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1018 | EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1019 | "something", File, 1, Scope, BaseType, 2, 3, |
| 1020 | 4, 5, getTuple())); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1021 | |
| 1022 | TempMDDerivedType Temp = N->clone(); |
| 1023 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1026 | TEST_F(MDDerivedTypeTest, getWithLargeValues) { |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1027 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1028 | MDScopeRef Scope = getSubprogramRef(); |
| 1029 | MDTypeRef BaseType = getBasicType("basic"); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1030 | MDTuple *ExtraData = getTuple(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1031 | |
| 1032 | auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", |
| 1033 | File, 1, Scope, BaseType, UINT64_MAX, |
| 1034 | UINT64_MAX - 1, UINT64_MAX - 2, 5, ExtraData); |
| 1035 | EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); |
| 1036 | EXPECT_EQ(UINT64_MAX - 1, N->getAlignInBits()); |
| 1037 | EXPECT_EQ(UINT64_MAX - 2, N->getOffsetInBits()); |
| 1038 | } |
| 1039 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1040 | typedef MetadataTest MDCompositeTypeTest; |
| 1041 | |
| 1042 | TEST_F(MDCompositeTypeTest, get) { |
| 1043 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1044 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1045 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1046 | unsigned Line = 1; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1047 | MDScopeRef Scope = getSubprogramRef(); |
| 1048 | MDTypeRef BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1049 | uint64_t SizeInBits = 2; |
| 1050 | uint64_t AlignInBits = 3; |
| 1051 | uint64_t OffsetInBits = 4; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1052 | unsigned Flags = 5; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1053 | MDTuple *Elements = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1054 | unsigned RuntimeLang = 6; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1055 | MDTypeRef VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1056 | MDTuple *TemplateParams = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1057 | StringRef Identifier = "some id"; |
| 1058 | |
| 1059 | auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1060 | BaseType, SizeInBits, AlignInBits, |
| 1061 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1062 | VTableHolder, TemplateParams, Identifier); |
| 1063 | EXPECT_EQ(Tag, N->getTag()); |
| 1064 | EXPECT_EQ(Name, N->getName()); |
| 1065 | EXPECT_EQ(File, N->getFile()); |
| 1066 | EXPECT_EQ(Line, N->getLine()); |
| 1067 | EXPECT_EQ(Scope, N->getScope()); |
| 1068 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 1069 | EXPECT_EQ(SizeInBits, N->getSizeInBits()); |
| 1070 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
| 1071 | EXPECT_EQ(OffsetInBits, N->getOffsetInBits()); |
| 1072 | EXPECT_EQ(Flags, N->getFlags()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1073 | EXPECT_EQ(Elements, N->getElements().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1074 | EXPECT_EQ(RuntimeLang, N->getRuntimeLang()); |
| 1075 | EXPECT_EQ(VTableHolder, N->getVTableHolder()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1076 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1077 | EXPECT_EQ(Identifier, N->getIdentifier()); |
| 1078 | |
| 1079 | EXPECT_EQ(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1080 | BaseType, SizeInBits, AlignInBits, |
| 1081 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1082 | VTableHolder, TemplateParams, Identifier)); |
| 1083 | |
| 1084 | EXPECT_NE(N, MDCompositeType::get(Context, Tag + 1, Name, File, Line, Scope, |
| 1085 | BaseType, SizeInBits, AlignInBits, |
| 1086 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1087 | VTableHolder, TemplateParams, Identifier)); |
| 1088 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, "abc", File, Line, Scope, |
| 1089 | BaseType, SizeInBits, AlignInBits, |
| 1090 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1091 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1092 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, getFile(), Line, Scope, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1093 | BaseType, SizeInBits, AlignInBits, |
| 1094 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1095 | VTableHolder, TemplateParams, Identifier)); |
| 1096 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line + 1, Scope, |
| 1097 | BaseType, SizeInBits, AlignInBits, |
| 1098 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1099 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1100 | EXPECT_NE(N, MDCompositeType::get( |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1101 | Context, Tag, Name, File, Line, getSubprogramRef(), BaseType, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1102 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, |
| 1103 | RuntimeLang, VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1104 | EXPECT_NE(N, MDCompositeType::get( |
| 1105 | Context, Tag, Name, File, Line, Scope, getBasicType("other"), |
| 1106 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, |
| 1107 | RuntimeLang, VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1108 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1109 | BaseType, SizeInBits + 1, AlignInBits, |
| 1110 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1111 | VTableHolder, TemplateParams, Identifier)); |
| 1112 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1113 | BaseType, SizeInBits, AlignInBits + 1, |
| 1114 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1115 | VTableHolder, TemplateParams, Identifier)); |
| 1116 | EXPECT_NE(N, MDCompositeType::get( |
| 1117 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1118 | AlignInBits, OffsetInBits + 1, Flags, Elements, RuntimeLang, |
| 1119 | VTableHolder, TemplateParams, Identifier)); |
| 1120 | EXPECT_NE(N, MDCompositeType::get( |
| 1121 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1122 | AlignInBits, OffsetInBits, Flags + 1, Elements, RuntimeLang, |
| 1123 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1124 | EXPECT_NE(N, MDCompositeType::get( |
| 1125 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1126 | AlignInBits, OffsetInBits, Flags, getTuple(), RuntimeLang, |
| 1127 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1128 | EXPECT_NE(N, MDCompositeType::get( |
| 1129 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1130 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang + 1, |
| 1131 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1132 | EXPECT_NE(N, MDCompositeType::get( |
| 1133 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1134 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 1135 | getCompositeType(), TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1136 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1137 | BaseType, SizeInBits, AlignInBits, |
| 1138 | OffsetInBits, Flags, Elements, RuntimeLang, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1139 | VTableHolder, getTuple(), Identifier)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1140 | EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1141 | BaseType, SizeInBits, AlignInBits, |
| 1142 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1143 | VTableHolder, TemplateParams, "other")); |
| 1144 | |
| 1145 | // Be sure that missing identifiers get null pointers. |
| 1146 | EXPECT_FALSE(MDCompositeType::get( |
| 1147 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1148 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 1149 | VTableHolder, TemplateParams, "")->getRawIdentifier()); |
| 1150 | EXPECT_FALSE(MDCompositeType::get( |
| 1151 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1152 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 1153 | VTableHolder, TemplateParams)->getRawIdentifier()); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1154 | |
| 1155 | TempMDCompositeType Temp = N->clone(); |
| 1156 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1159 | TEST_F(MDCompositeTypeTest, getWithLargeValues) { |
| 1160 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1161 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1162 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1163 | unsigned Line = 1; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1164 | MDScopeRef Scope = getSubprogramRef(); |
| 1165 | MDTypeRef BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1166 | uint64_t SizeInBits = UINT64_MAX; |
| 1167 | uint64_t AlignInBits = UINT64_MAX - 1; |
| 1168 | uint64_t OffsetInBits = UINT64_MAX - 2; |
| 1169 | unsigned Flags = 5; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1170 | MDTuple *Elements = getTuple(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1171 | unsigned RuntimeLang = 6; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1172 | MDTypeRef VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1173 | MDTuple *TemplateParams = getTuple(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1174 | StringRef Identifier = "some id"; |
| 1175 | |
| 1176 | auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1177 | BaseType, SizeInBits, AlignInBits, |
| 1178 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1179 | VTableHolder, TemplateParams, Identifier); |
| 1180 | EXPECT_EQ(SizeInBits, N->getSizeInBits()); |
| 1181 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
| 1182 | EXPECT_EQ(OffsetInBits, N->getOffsetInBits()); |
| 1183 | } |
| 1184 | |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1185 | TEST_F(MDCompositeTypeTest, replaceOperands) { |
| 1186 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1187 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1188 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1189 | unsigned Line = 1; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1190 | MDScopeRef Scope = getSubprogramRef(); |
| 1191 | MDTypeRef BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1192 | uint64_t SizeInBits = 2; |
| 1193 | uint64_t AlignInBits = 3; |
| 1194 | uint64_t OffsetInBits = 4; |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1195 | unsigned Flags = 5; |
| 1196 | unsigned RuntimeLang = 6; |
| 1197 | StringRef Identifier = "some id"; |
| 1198 | |
| 1199 | auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1200 | BaseType, SizeInBits, AlignInBits, |
| 1201 | OffsetInBits, Flags, nullptr, RuntimeLang, |
| 1202 | nullptr, nullptr, Identifier); |
| 1203 | |
| 1204 | auto *Elements = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1205 | EXPECT_EQ(nullptr, N->getElements().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1206 | N->replaceElements(Elements); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1207 | EXPECT_EQ(Elements, N->getElements().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1208 | N->replaceElements(nullptr); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1209 | EXPECT_EQ(nullptr, N->getElements().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1210 | |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1211 | MDTypeRef VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1212 | EXPECT_EQ(nullptr, N->getVTableHolder()); |
| 1213 | N->replaceVTableHolder(VTableHolder); |
| 1214 | EXPECT_EQ(VTableHolder, N->getVTableHolder()); |
| 1215 | N->replaceVTableHolder(nullptr); |
| 1216 | EXPECT_EQ(nullptr, N->getVTableHolder()); |
| 1217 | |
| 1218 | auto *TemplateParams = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1219 | EXPECT_EQ(nullptr, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1220 | N->replaceTemplateParams(TemplateParams); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1221 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1222 | N->replaceTemplateParams(nullptr); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1223 | EXPECT_EQ(nullptr, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | f51e00d | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1226 | typedef MetadataTest MDSubroutineTypeTest; |
| 1227 | |
| 1228 | TEST_F(MDSubroutineTypeTest, get) { |
| 1229 | unsigned Flags = 1; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1230 | MDTuple *TypeArray = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1231 | |
| 1232 | auto *N = MDSubroutineType::get(Context, Flags, TypeArray); |
| 1233 | EXPECT_EQ(dwarf::DW_TAG_subroutine_type, N->getTag()); |
| 1234 | EXPECT_EQ(Flags, N->getFlags()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1235 | EXPECT_EQ(TypeArray, N->getTypeArray().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1236 | EXPECT_EQ(N, MDSubroutineType::get(Context, Flags, TypeArray)); |
| 1237 | |
| 1238 | EXPECT_NE(N, MDSubroutineType::get(Context, Flags + 1, TypeArray)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1239 | EXPECT_NE(N, MDSubroutineType::get(Context, Flags, getTuple())); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1240 | |
| 1241 | TempMDSubroutineType Temp = N->clone(); |
| 1242 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | a9f0a8d | 2015-02-19 23:25:21 +0000 | [diff] [blame] | 1243 | |
| 1244 | // Test always-empty operands. |
| 1245 | EXPECT_EQ(nullptr, N->getScope()); |
| 1246 | EXPECT_EQ(nullptr, N->getFile()); |
| 1247 | EXPECT_EQ("", N->getName()); |
| 1248 | EXPECT_EQ(nullptr, N->getBaseType()); |
| 1249 | EXPECT_EQ(nullptr, N->getVTableHolder()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1250 | EXPECT_EQ(nullptr, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | a9f0a8d | 2015-02-19 23:25:21 +0000 | [diff] [blame] | 1251 | EXPECT_EQ("", N->getIdentifier()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | typedef MetadataTest MDFileTest; |
| 1255 | |
| 1256 | TEST_F(MDFileTest, get) { |
| 1257 | StringRef Filename = "file"; |
| 1258 | StringRef Directory = "dir"; |
| 1259 | auto *N = MDFile::get(Context, Filename, Directory); |
| 1260 | |
| 1261 | EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag()); |
| 1262 | EXPECT_EQ(Filename, N->getFilename()); |
| 1263 | EXPECT_EQ(Directory, N->getDirectory()); |
| 1264 | EXPECT_EQ(N, MDFile::get(Context, Filename, Directory)); |
| 1265 | |
| 1266 | EXPECT_NE(N, MDFile::get(Context, "other", Directory)); |
| 1267 | EXPECT_NE(N, MDFile::get(Context, Filename, "other")); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1268 | |
| 1269 | TempMDFile Temp = N->clone(); |
| 1270 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Duncan P. N. Exon Smith | 2c6a0a9 | 2015-02-28 21:47:02 +0000 | [diff] [blame] | 1273 | TEST_F(MDFileTest, ScopeGetFile) { |
| 1274 | // Ensure that MDScope::getFile() returns itself. |
| 1275 | MDScope *N = MDFile::get(Context, "file", "dir"); |
| 1276 | EXPECT_EQ(N, N->getFile()); |
| 1277 | } |
| 1278 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1279 | typedef MetadataTest MDCompileUnitTest; |
| 1280 | |
| 1281 | TEST_F(MDCompileUnitTest, get) { |
| 1282 | unsigned SourceLanguage = 1; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1283 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1284 | StringRef Producer = "some producer"; |
| 1285 | bool IsOptimized = false; |
| 1286 | StringRef Flags = "flag after flag"; |
| 1287 | unsigned RuntimeVersion = 2; |
| 1288 | StringRef SplitDebugFilename = "another/file"; |
| 1289 | unsigned EmissionKind = 3; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1290 | MDTuple *EnumTypes = getTuple(); |
| 1291 | MDTuple *RetainedTypes = getTuple(); |
| 1292 | MDTuple *Subprograms = getTuple(); |
| 1293 | MDTuple *GlobalVariables = getTuple(); |
| 1294 | MDTuple *ImportedEntities = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1295 | auto *N = MDCompileUnit::get( |
| 1296 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1297 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1298 | RetainedTypes, Subprograms, GlobalVariables, ImportedEntities); |
| 1299 | |
| 1300 | EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag()); |
| 1301 | EXPECT_EQ(SourceLanguage, N->getSourceLanguage()); |
| 1302 | EXPECT_EQ(File, N->getFile()); |
| 1303 | EXPECT_EQ(Producer, N->getProducer()); |
| 1304 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
| 1305 | EXPECT_EQ(Flags, N->getFlags()); |
| 1306 | EXPECT_EQ(RuntimeVersion, N->getRuntimeVersion()); |
| 1307 | EXPECT_EQ(SplitDebugFilename, N->getSplitDebugFilename()); |
| 1308 | EXPECT_EQ(EmissionKind, N->getEmissionKind()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1309 | EXPECT_EQ(EnumTypes, N->getEnumTypes().get()); |
| 1310 | EXPECT_EQ(RetainedTypes, N->getRetainedTypes().get()); |
| 1311 | EXPECT_EQ(Subprograms, N->getSubprograms().get()); |
| 1312 | EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get()); |
| 1313 | EXPECT_EQ(ImportedEntities, N->getImportedEntities().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1314 | EXPECT_EQ(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1315 | IsOptimized, Flags, RuntimeVersion, |
| 1316 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1317 | RetainedTypes, Subprograms, GlobalVariables, |
| 1318 | ImportedEntities)); |
| 1319 | |
| 1320 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage + 1, File, Producer, |
| 1321 | IsOptimized, Flags, RuntimeVersion, |
| 1322 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1323 | RetainedTypes, Subprograms, GlobalVariables, |
| 1324 | ImportedEntities)); |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1325 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, getFile(), Producer, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1326 | IsOptimized, Flags, RuntimeVersion, |
| 1327 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1328 | RetainedTypes, Subprograms, GlobalVariables, |
| 1329 | ImportedEntities)); |
| 1330 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, "other", |
| 1331 | IsOptimized, Flags, RuntimeVersion, |
| 1332 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1333 | RetainedTypes, Subprograms, GlobalVariables, |
| 1334 | ImportedEntities)); |
| 1335 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1336 | !IsOptimized, Flags, RuntimeVersion, |
| 1337 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1338 | RetainedTypes, Subprograms, GlobalVariables, |
| 1339 | ImportedEntities)); |
| 1340 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1341 | IsOptimized, "other", RuntimeVersion, |
| 1342 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1343 | RetainedTypes, Subprograms, GlobalVariables, |
| 1344 | ImportedEntities)); |
| 1345 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1346 | IsOptimized, Flags, RuntimeVersion + 1, |
| 1347 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1348 | RetainedTypes, Subprograms, GlobalVariables, |
| 1349 | ImportedEntities)); |
| 1350 | EXPECT_NE(N, |
| 1351 | MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1352 | IsOptimized, Flags, RuntimeVersion, "other", |
| 1353 | EmissionKind, EnumTypes, RetainedTypes, |
| 1354 | Subprograms, GlobalVariables, ImportedEntities)); |
| 1355 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1356 | IsOptimized, Flags, RuntimeVersion, |
| 1357 | SplitDebugFilename, EmissionKind + 1, |
| 1358 | EnumTypes, RetainedTypes, Subprograms, |
| 1359 | GlobalVariables, ImportedEntities)); |
| 1360 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1361 | IsOptimized, Flags, RuntimeVersion, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1362 | SplitDebugFilename, EmissionKind, getTuple(), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1363 | RetainedTypes, Subprograms, GlobalVariables, |
| 1364 | ImportedEntities)); |
| 1365 | EXPECT_NE(N, MDCompileUnit::get( |
| 1366 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1367 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1368 | getTuple(), Subprograms, GlobalVariables, ImportedEntities)); |
| 1369 | EXPECT_NE(N, MDCompileUnit::get(Context, SourceLanguage, File, Producer, |
| 1370 | IsOptimized, Flags, RuntimeVersion, |
| 1371 | SplitDebugFilename, EmissionKind, EnumTypes, |
| 1372 | RetainedTypes, getTuple(), GlobalVariables, |
| 1373 | ImportedEntities)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1374 | EXPECT_NE(N, MDCompileUnit::get( |
| 1375 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1376 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1377 | RetainedTypes, Subprograms, getTuple(), ImportedEntities)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1378 | EXPECT_NE(N, MDCompileUnit::get( |
| 1379 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1380 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1381 | RetainedTypes, Subprograms, GlobalVariables, getTuple())); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1382 | |
| 1383 | TempMDCompileUnit Temp = N->clone(); |
| 1384 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1387 | TEST_F(MDCompileUnitTest, replaceArrays) { |
| 1388 | unsigned SourceLanguage = 1; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1389 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1390 | StringRef Producer = "some producer"; |
| 1391 | bool IsOptimized = false; |
| 1392 | StringRef Flags = "flag after flag"; |
| 1393 | unsigned RuntimeVersion = 2; |
| 1394 | StringRef SplitDebugFilename = "another/file"; |
| 1395 | unsigned EmissionKind = 3; |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1396 | MDTuple *EnumTypes = MDTuple::getDistinct(Context, None); |
| 1397 | MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None); |
| 1398 | MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1399 | auto *N = MDCompileUnit::get( |
| 1400 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1401 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
| 1402 | RetainedTypes, nullptr, nullptr, ImportedEntities); |
| 1403 | |
| 1404 | auto *Subprograms = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1405 | EXPECT_EQ(nullptr, N->getSubprograms().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1406 | N->replaceSubprograms(Subprograms); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1407 | EXPECT_EQ(Subprograms, N->getSubprograms().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1408 | N->replaceSubprograms(nullptr); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1409 | EXPECT_EQ(nullptr, N->getSubprograms().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1410 | |
| 1411 | auto *GlobalVariables = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1412 | EXPECT_EQ(nullptr, N->getGlobalVariables().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1413 | N->replaceGlobalVariables(GlobalVariables); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1414 | EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1415 | N->replaceGlobalVariables(nullptr); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1416 | EXPECT_EQ(nullptr, N->getGlobalVariables().get()); |
Duncan P. N. Exon Smith | 94bbbf0 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1419 | typedef MetadataTest MDSubprogramTest; |
| 1420 | |
| 1421 | TEST_F(MDSubprogramTest, get) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1422 | MDScopeRef Scope = getCompositeType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1423 | StringRef Name = "name"; |
| 1424 | StringRef LinkageName = "linkage"; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1425 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1426 | unsigned Line = 2; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1427 | MDSubroutineType *Type = getSubroutineType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1428 | bool IsLocalToUnit = false; |
| 1429 | bool IsDefinition = true; |
| 1430 | unsigned ScopeLine = 3; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1431 | MDTypeRef ContainingType = getCompositeType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1432 | unsigned Virtuality = 4; |
| 1433 | unsigned VirtualIndex = 5; |
| 1434 | unsigned Flags = 6; |
| 1435 | bool IsOptimized = false; |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 1436 | llvm::Function *Function = getFunction("foo"); |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1437 | MDTuple *TemplateParams = getTuple(); |
| 1438 | MDSubprogram *Declaration = getSubprogram(); |
| 1439 | MDTuple *Variables = getTuple(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1440 | |
| 1441 | auto *N = MDSubprogram::get( |
| 1442 | Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 1443 | IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, |
| 1444 | IsOptimized, Function, TemplateParams, Declaration, Variables); |
| 1445 | |
| 1446 | EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag()); |
| 1447 | EXPECT_EQ(Scope, N->getScope()); |
| 1448 | EXPECT_EQ(Name, N->getName()); |
| 1449 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 1450 | EXPECT_EQ(File, N->getFile()); |
| 1451 | EXPECT_EQ(Line, N->getLine()); |
| 1452 | EXPECT_EQ(Type, N->getType()); |
| 1453 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 1454 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
| 1455 | EXPECT_EQ(ScopeLine, N->getScopeLine()); |
| 1456 | EXPECT_EQ(ContainingType, N->getContainingType()); |
| 1457 | EXPECT_EQ(Virtuality, N->getVirtuality()); |
| 1458 | EXPECT_EQ(VirtualIndex, N->getVirtualIndex()); |
| 1459 | EXPECT_EQ(Flags, N->getFlags()); |
| 1460 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
| 1461 | EXPECT_EQ(Function, N->getFunction()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1462 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1463 | EXPECT_EQ(Declaration, N->getDeclaration()); |
Duncan P. N. Exon Smith | 1134473 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1464 | EXPECT_EQ(Variables, N->getVariables().get()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1465 | EXPECT_EQ(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1466 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1467 | ContainingType, Virtuality, VirtualIndex, |
| 1468 | Flags, IsOptimized, Function, TemplateParams, |
| 1469 | Declaration, Variables)); |
| 1470 | |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1471 | EXPECT_NE(N, MDSubprogram::get(Context, getCompositeType(), Name, LinkageName, |
| 1472 | File, Line, Type, IsLocalToUnit, IsDefinition, |
| 1473 | ScopeLine, ContainingType, Virtuality, |
| 1474 | VirtualIndex, Flags, IsOptimized, Function, |
| 1475 | TemplateParams, Declaration, Variables)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1476 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, "other", LinkageName, File, |
| 1477 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1478 | ScopeLine, ContainingType, Virtuality, |
| 1479 | VirtualIndex, Flags, IsOptimized, Function, |
| 1480 | TemplateParams, Declaration, Variables)); |
| 1481 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, "other", File, Line, |
| 1482 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1483 | ContainingType, Virtuality, VirtualIndex, |
| 1484 | Flags, IsOptimized, Function, TemplateParams, |
| 1485 | Declaration, Variables)); |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1486 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, getFile(), |
| 1487 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1488 | ScopeLine, ContainingType, Virtuality, |
| 1489 | VirtualIndex, Flags, IsOptimized, Function, |
| 1490 | TemplateParams, Declaration, Variables)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1491 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, |
| 1492 | Line + 1, Type, IsLocalToUnit, IsDefinition, |
| 1493 | ScopeLine, ContainingType, Virtuality, |
| 1494 | VirtualIndex, Flags, IsOptimized, Function, |
| 1495 | TemplateParams, Declaration, Variables)); |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1496 | EXPECT_NE(N, MDSubprogram::get( |
| 1497 | Context, Scope, Name, LinkageName, File, Line, |
| 1498 | getSubroutineType(), IsLocalToUnit, IsDefinition, ScopeLine, |
| 1499 | ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized, |
| 1500 | Function, TemplateParams, Declaration, Variables)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1501 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1502 | Type, !IsLocalToUnit, IsDefinition, ScopeLine, |
| 1503 | ContainingType, Virtuality, VirtualIndex, |
| 1504 | Flags, IsOptimized, Function, TemplateParams, |
| 1505 | Declaration, Variables)); |
| 1506 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1507 | Type, IsLocalToUnit, !IsDefinition, ScopeLine, |
| 1508 | ContainingType, Virtuality, VirtualIndex, |
| 1509 | Flags, IsOptimized, Function, TemplateParams, |
| 1510 | Declaration, Variables)); |
| 1511 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1512 | Type, IsLocalToUnit, IsDefinition, |
| 1513 | ScopeLine + 1, ContainingType, Virtuality, |
| 1514 | VirtualIndex, Flags, IsOptimized, Function, |
| 1515 | TemplateParams, Declaration, Variables)); |
| 1516 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1517 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1518 | getCompositeType(), Virtuality, VirtualIndex, |
| 1519 | Flags, IsOptimized, Function, TemplateParams, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1520 | Declaration, Variables)); |
| 1521 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1522 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1523 | ContainingType, Virtuality + 1, VirtualIndex, |
| 1524 | Flags, IsOptimized, Function, TemplateParams, |
| 1525 | Declaration, Variables)); |
| 1526 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1527 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1528 | ContainingType, Virtuality, VirtualIndex + 1, |
| 1529 | Flags, IsOptimized, Function, TemplateParams, |
| 1530 | Declaration, Variables)); |
| 1531 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1532 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1533 | ContainingType, Virtuality, VirtualIndex, |
| 1534 | ~Flags, IsOptimized, Function, TemplateParams, |
| 1535 | Declaration, Variables)); |
| 1536 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1537 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1538 | ContainingType, Virtuality, VirtualIndex, |
| 1539 | Flags, !IsOptimized, Function, TemplateParams, |
| 1540 | Declaration, Variables)); |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 1541 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1542 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1543 | ContainingType, Virtuality, VirtualIndex, |
| 1544 | Flags, IsOptimized, getFunction("bar"), |
| 1545 | TemplateParams, Declaration, Variables)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1546 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1547 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1548 | ContainingType, Virtuality, VirtualIndex, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1549 | Flags, IsOptimized, Function, getTuple(), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1550 | Declaration, Variables)); |
| 1551 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1552 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1553 | ContainingType, Virtuality, VirtualIndex, |
| 1554 | Flags, IsOptimized, Function, TemplateParams, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1555 | getSubprogram(), Variables)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1556 | EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1557 | Type, IsLocalToUnit, IsDefinition, ScopeLine, |
| 1558 | ContainingType, Virtuality, VirtualIndex, |
| 1559 | Flags, IsOptimized, Function, TemplateParams, |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1560 | Declaration, getTuple())); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1561 | |
| 1562 | TempMDSubprogram Temp = N->clone(); |
| 1563 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1566 | TEST_F(MDSubprogramTest, replaceFunction) { |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1567 | MDScopeRef Scope = getCompositeType(); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1568 | StringRef Name = "name"; |
| 1569 | StringRef LinkageName = "linkage"; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1570 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1571 | unsigned Line = 2; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1572 | MDSubroutineType *Type = getSubroutineType(); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1573 | bool IsLocalToUnit = false; |
| 1574 | bool IsDefinition = true; |
| 1575 | unsigned ScopeLine = 3; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1576 | MDTypeRef ContainingType = getCompositeType(); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1577 | unsigned Virtuality = 4; |
| 1578 | unsigned VirtualIndex = 5; |
| 1579 | unsigned Flags = 6; |
| 1580 | bool IsOptimized = false; |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1581 | MDTuple *TemplateParams = getTuple(); |
| 1582 | MDSubprogram *Declaration = getSubprogram(); |
| 1583 | MDTuple *Variables = getTuple(); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1584 | |
| 1585 | auto *N = MDSubprogram::get( |
| 1586 | Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 1587 | IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, |
| 1588 | IsOptimized, nullptr, TemplateParams, Declaration, Variables); |
| 1589 | |
| 1590 | EXPECT_EQ(nullptr, N->getFunction()); |
| 1591 | |
| 1592 | std::unique_ptr<Function> F( |
| 1593 | Function::Create(FunctionType::get(Type::getVoidTy(Context), false), |
| 1594 | GlobalValue::ExternalLinkage)); |
| 1595 | N->replaceFunction(F.get()); |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 1596 | EXPECT_EQ(F.get(), N->getFunction()); |
Duncan P. N. Exon Smith | df52349 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 1597 | |
| 1598 | N->replaceFunction(nullptr); |
| 1599 | EXPECT_EQ(nullptr, N->getFunction()); |
| 1600 | } |
| 1601 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1602 | typedef MetadataTest MDLexicalBlockTest; |
| 1603 | |
| 1604 | TEST_F(MDLexicalBlockTest, get) { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1605 | MDLocalScope *Scope = getSubprogram(); |
| 1606 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1607 | unsigned Line = 5; |
| 1608 | unsigned Column = 8; |
| 1609 | |
| 1610 | auto *N = MDLexicalBlock::get(Context, Scope, File, Line, Column); |
| 1611 | |
| 1612 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 1613 | EXPECT_EQ(Scope, N->getScope()); |
| 1614 | EXPECT_EQ(File, N->getFile()); |
| 1615 | EXPECT_EQ(Line, N->getLine()); |
| 1616 | EXPECT_EQ(Column, N->getColumn()); |
| 1617 | EXPECT_EQ(N, MDLexicalBlock::get(Context, Scope, File, Line, Column)); |
| 1618 | |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1619 | EXPECT_NE(N, |
| 1620 | MDLexicalBlock::get(Context, getSubprogram(), File, Line, Column)); |
| 1621 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, getFile(), Line, Column)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1622 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line + 1, Column)); |
| 1623 | EXPECT_NE(N, MDLexicalBlock::get(Context, Scope, File, Line, Column + 1)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1624 | |
| 1625 | TempMDLexicalBlock Temp = N->clone(); |
| 1626 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | typedef MetadataTest MDLexicalBlockFileTest; |
| 1630 | |
| 1631 | TEST_F(MDLexicalBlockFileTest, get) { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1632 | MDLocalScope *Scope = getSubprogram(); |
| 1633 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1634 | unsigned Discriminator = 5; |
| 1635 | |
| 1636 | auto *N = MDLexicalBlockFile::get(Context, Scope, File, Discriminator); |
| 1637 | |
| 1638 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 1639 | EXPECT_EQ(Scope, N->getScope()); |
| 1640 | EXPECT_EQ(File, N->getFile()); |
| 1641 | EXPECT_EQ(Discriminator, N->getDiscriminator()); |
| 1642 | EXPECT_EQ(N, MDLexicalBlockFile::get(Context, Scope, File, Discriminator)); |
| 1643 | |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1644 | EXPECT_NE(N, MDLexicalBlockFile::get(Context, getSubprogram(), File, |
| 1645 | Discriminator)); |
| 1646 | EXPECT_NE(N, |
| 1647 | MDLexicalBlockFile::get(Context, Scope, getFile(), Discriminator)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1648 | EXPECT_NE(N, |
| 1649 | MDLexicalBlockFile::get(Context, Scope, File, Discriminator + 1)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1650 | |
| 1651 | TempMDLexicalBlockFile Temp = N->clone(); |
| 1652 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | typedef MetadataTest MDNamespaceTest; |
| 1656 | |
| 1657 | TEST_F(MDNamespaceTest, get) { |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1658 | MDScope *Scope = getFile(); |
| 1659 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1660 | StringRef Name = "namespace"; |
| 1661 | unsigned Line = 5; |
| 1662 | |
| 1663 | auto *N = MDNamespace::get(Context, Scope, File, Name, Line); |
| 1664 | |
| 1665 | EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag()); |
| 1666 | EXPECT_EQ(Scope, N->getScope()); |
| 1667 | EXPECT_EQ(File, N->getFile()); |
| 1668 | EXPECT_EQ(Name, N->getName()); |
| 1669 | EXPECT_EQ(Line, N->getLine()); |
| 1670 | EXPECT_EQ(N, MDNamespace::get(Context, Scope, File, Name, Line)); |
| 1671 | |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1672 | EXPECT_NE(N, MDNamespace::get(Context, getFile(), File, Name, Line)); |
| 1673 | EXPECT_NE(N, MDNamespace::get(Context, Scope, getFile(), Name, Line)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1674 | EXPECT_NE(N, MDNamespace::get(Context, Scope, File, "other", Line)); |
| 1675 | EXPECT_NE(N, MDNamespace::get(Context, Scope, File, Name, Line + 1)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1676 | |
| 1677 | TempMDNamespace Temp = N->clone(); |
| 1678 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | typedef MetadataTest MDTemplateTypeParameterTest; |
| 1682 | |
| 1683 | TEST_F(MDTemplateTypeParameterTest, get) { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1684 | StringRef Name = "template"; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1685 | MDTypeRef Type = getBasicType("basic"); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1686 | |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1687 | auto *N = MDTemplateTypeParameter::get(Context, Name, Type); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1688 | |
| 1689 | EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1690 | EXPECT_EQ(Name, N->getName()); |
| 1691 | EXPECT_EQ(Type, N->getType()); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1692 | EXPECT_EQ(N, MDTemplateTypeParameter::get(Context, Name, Type)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1693 | |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1694 | EXPECT_NE(N, MDTemplateTypeParameter::get(Context, "other", Type)); |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1695 | EXPECT_NE(N, |
| 1696 | MDTemplateTypeParameter::get(Context, Name, getBasicType("other"))); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1697 | |
| 1698 | TempMDTemplateTypeParameter Temp = N->clone(); |
| 1699 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | typedef MetadataTest MDTemplateValueParameterTest; |
| 1703 | |
| 1704 | TEST_F(MDTemplateValueParameterTest, get) { |
| 1705 | unsigned Tag = dwarf::DW_TAG_template_value_parameter; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1706 | StringRef Name = "template"; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1707 | MDTypeRef Type = getBasicType("basic"); |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1708 | Metadata *Value = getConstantAsMetadata(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1709 | |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1710 | auto *N = MDTemplateValueParameter::get(Context, Tag, Name, Type, Value); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1711 | EXPECT_EQ(Tag, N->getTag()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1712 | EXPECT_EQ(Name, N->getName()); |
| 1713 | EXPECT_EQ(Type, N->getType()); |
| 1714 | EXPECT_EQ(Value, N->getValue()); |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1715 | EXPECT_EQ(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, Value)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1716 | |
| 1717 | EXPECT_NE(N, MDTemplateValueParameter::get( |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 1718 | Context, dwarf::DW_TAG_GNU_template_template_param, Name, |
| 1719 | Type, Value)); |
| 1720 | EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, "other", Type, |
Duncan P. N. Exon Smith | bd33d37 | 2015-02-10 01:59:57 +0000 | [diff] [blame] | 1721 | Value)); |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1722 | EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, |
| 1723 | getBasicType("other"), Value)); |
| 1724 | EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, |
| 1725 | getConstantAsMetadata())); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1726 | |
| 1727 | TempMDTemplateValueParameter Temp = N->clone(); |
| 1728 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | typedef MetadataTest MDGlobalVariableTest; |
| 1732 | |
| 1733 | TEST_F(MDGlobalVariableTest, get) { |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1734 | MDScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1735 | StringRef Name = "name"; |
| 1736 | StringRef LinkageName = "linkage"; |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1737 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1738 | unsigned Line = 5; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1739 | MDTypeRef Type = getDerivedType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1740 | bool IsLocalToUnit = false; |
| 1741 | bool IsDefinition = true; |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 1742 | Constant *Variable = getConstant(); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1743 | MDDerivedType *StaticDataMemberDeclaration = |
| 1744 | cast<MDDerivedType>(getDerivedType()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1745 | |
| 1746 | auto *N = MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, |
| 1747 | Type, IsLocalToUnit, IsDefinition, Variable, |
| 1748 | StaticDataMemberDeclaration); |
| 1749 | EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag()); |
| 1750 | EXPECT_EQ(Scope, N->getScope()); |
| 1751 | EXPECT_EQ(Name, N->getName()); |
| 1752 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 1753 | EXPECT_EQ(File, N->getFile()); |
| 1754 | EXPECT_EQ(Line, N->getLine()); |
| 1755 | EXPECT_EQ(Type, N->getType()); |
| 1756 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 1757 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
| 1758 | EXPECT_EQ(Variable, N->getVariable()); |
| 1759 | EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration()); |
| 1760 | EXPECT_EQ(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1761 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1762 | Variable, StaticDataMemberDeclaration)); |
| 1763 | |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1764 | EXPECT_NE(N, |
| 1765 | MDGlobalVariable::get(Context, getSubprogram(), Name, LinkageName, |
| 1766 | File, Line, Type, IsLocalToUnit, IsDefinition, |
| 1767 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1768 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, "other", LinkageName, File, |
| 1769 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1770 | Variable, StaticDataMemberDeclaration)); |
| 1771 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, "other", File, Line, |
| 1772 | Type, IsLocalToUnit, IsDefinition, |
| 1773 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1774 | EXPECT_NE(N, |
| 1775 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, getFile(), |
| 1776 | Line, Type, IsLocalToUnit, IsDefinition, |
| 1777 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1778 | EXPECT_NE(N, |
| 1779 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1780 | Line + 1, Type, IsLocalToUnit, IsDefinition, |
| 1781 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1782 | EXPECT_NE(N, |
| 1783 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, |
| 1784 | getDerivedType(), IsLocalToUnit, IsDefinition, |
| 1785 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1786 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1787 | Line, Type, !IsLocalToUnit, IsDefinition, |
| 1788 | Variable, StaticDataMemberDeclaration)); |
| 1789 | EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 1790 | Line, Type, IsLocalToUnit, !IsDefinition, |
| 1791 | Variable, StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 7ad0bd5 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 1792 | EXPECT_NE(N, |
| 1793 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, |
| 1794 | Type, IsLocalToUnit, IsDefinition, |
| 1795 | getConstant(), StaticDataMemberDeclaration)); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1796 | EXPECT_NE(N, |
| 1797 | MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, |
| 1798 | Type, IsLocalToUnit, IsDefinition, Variable, |
| 1799 | cast<MDDerivedType>(getDerivedType()))); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1800 | |
| 1801 | TempMDGlobalVariable Temp = N->clone(); |
| 1802 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | typedef MetadataTest MDLocalVariableTest; |
| 1806 | |
| 1807 | TEST_F(MDLocalVariableTest, get) { |
| 1808 | unsigned Tag = dwarf::DW_TAG_arg_variable; |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1809 | MDLocalScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1810 | StringRef Name = "name"; |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1811 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1812 | unsigned Line = 5; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1813 | MDTypeRef Type = getDerivedType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1814 | unsigned Arg = 6; |
| 1815 | unsigned Flags = 7; |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1816 | MDLocation *InlinedAt = |
| 1817 | MDLocation::getDistinct(Context, 10, 20, getSubprogram()); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1818 | |
| 1819 | auto *N = MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1820 | Arg, Flags, InlinedAt); |
| 1821 | EXPECT_EQ(Tag, N->getTag()); |
| 1822 | EXPECT_EQ(Scope, N->getScope()); |
| 1823 | EXPECT_EQ(Name, N->getName()); |
| 1824 | EXPECT_EQ(File, N->getFile()); |
| 1825 | EXPECT_EQ(Line, N->getLine()); |
| 1826 | EXPECT_EQ(Type, N->getType()); |
| 1827 | EXPECT_EQ(Arg, N->getArg()); |
| 1828 | EXPECT_EQ(Flags, N->getFlags()); |
| 1829 | EXPECT_EQ(InlinedAt, N->getInlinedAt()); |
| 1830 | EXPECT_EQ(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1831 | Arg, Flags, InlinedAt)); |
| 1832 | |
| 1833 | EXPECT_NE(N, MDLocalVariable::get(Context, dwarf::DW_TAG_auto_variable, Scope, |
| 1834 | Name, File, Line, Type, Arg, Flags, |
| 1835 | InlinedAt)); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1836 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, getSubprogram(), Name, File, |
| 1837 | Line, Type, Arg, Flags, InlinedAt)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1838 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, "other", File, Line, |
| 1839 | Type, Arg, Flags, InlinedAt)); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1840 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, getFile(), Line, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1841 | Type, Arg, Flags, InlinedAt)); |
| 1842 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line + 1, |
| 1843 | Type, Arg, Flags, InlinedAt)); |
| 1844 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1845 | getDerivedType(), Arg, Flags, InlinedAt)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1846 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1847 | Arg + 1, Flags, InlinedAt)); |
| 1848 | EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type, |
| 1849 | Arg, ~Flags, InlinedAt)); |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 1850 | EXPECT_NE(N, MDLocalVariable::get( |
| 1851 | Context, Tag, Scope, Name, File, Line, Type, Arg, Flags, |
| 1852 | MDLocation::getDistinct(Context, 10, 20, getSubprogram()))); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1853 | |
| 1854 | TempMDLocalVariable Temp = N->clone(); |
| 1855 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | b353849 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1856 | |
| 1857 | auto *Inlined = N->withoutInline(); |
| 1858 | EXPECT_NE(N, Inlined); |
| 1859 | EXPECT_EQ(N->getTag(), Inlined->getTag()); |
| 1860 | EXPECT_EQ(N->getScope(), Inlined->getScope()); |
| 1861 | EXPECT_EQ(N->getName(), Inlined->getName()); |
| 1862 | EXPECT_EQ(N->getFile(), Inlined->getFile()); |
| 1863 | EXPECT_EQ(N->getLine(), Inlined->getLine()); |
| 1864 | EXPECT_EQ(N->getType(), Inlined->getType()); |
| 1865 | EXPECT_EQ(N->getArg(), Inlined->getArg()); |
| 1866 | EXPECT_EQ(N->getFlags(), Inlined->getFlags()); |
| 1867 | EXPECT_EQ(nullptr, Inlined->getInlinedAt()); |
| 1868 | EXPECT_EQ(N, Inlined->withInline(cast<MDLocation>(InlinedAt))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | typedef MetadataTest MDExpressionTest; |
| 1872 | |
| 1873 | TEST_F(MDExpressionTest, get) { |
| 1874 | uint64_t Elements[] = {2, 6, 9, 78, 0}; |
| 1875 | auto *N = MDExpression::get(Context, Elements); |
| 1876 | EXPECT_EQ(makeArrayRef(Elements), N->getElements()); |
| 1877 | EXPECT_EQ(N, MDExpression::get(Context, Elements)); |
Duncan P. N. Exon Smith | dddc537 | 2015-02-10 01:36:46 +0000 | [diff] [blame] | 1878 | |
| 1879 | EXPECT_EQ(5u, N->getNumElements()); |
| 1880 | EXPECT_EQ(2u, N->getElement(0)); |
| 1881 | EXPECT_EQ(6u, N->getElement(1)); |
| 1882 | EXPECT_EQ(9u, N->getElement(2)); |
| 1883 | EXPECT_EQ(78u, N->getElement(3)); |
| 1884 | EXPECT_EQ(0u, N->getElement(4)); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1885 | |
| 1886 | TempMDExpression Temp = N->clone(); |
| 1887 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Duncan P. N. Exon Smith | 193a4fd | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 1890 | TEST_F(MDExpressionTest, isValid) { |
| 1891 | #define EXPECT_VALID(...) \ |
| 1892 | do { \ |
| 1893 | uint64_t Elements[] = {__VA_ARGS__}; \ |
| 1894 | EXPECT_TRUE(MDExpression::get(Context, Elements)->isValid()); \ |
| 1895 | } while (false) |
| 1896 | #define EXPECT_INVALID(...) \ |
| 1897 | do { \ |
| 1898 | uint64_t Elements[] = {__VA_ARGS__}; \ |
| 1899 | EXPECT_FALSE(MDExpression::get(Context, Elements)->isValid()); \ |
| 1900 | } while (false) |
| 1901 | |
| 1902 | // Empty expression should be valid. |
| 1903 | EXPECT_TRUE(MDExpression::get(Context, None)); |
| 1904 | |
| 1905 | // Valid constructions. |
| 1906 | EXPECT_VALID(dwarf::DW_OP_plus, 6); |
| 1907 | EXPECT_VALID(dwarf::DW_OP_deref); |
| 1908 | EXPECT_VALID(dwarf::DW_OP_bit_piece, 3, 7); |
| 1909 | EXPECT_VALID(dwarf::DW_OP_plus, 6, dwarf::DW_OP_deref); |
| 1910 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6); |
| 1911 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_bit_piece, 3, 7); |
| 1912 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus, 6, dwarf::DW_OP_bit_piece, 3, 7); |
| 1913 | |
| 1914 | // Invalid constructions. |
| 1915 | EXPECT_INVALID(~0u); |
| 1916 | EXPECT_INVALID(dwarf::DW_OP_plus); |
| 1917 | EXPECT_INVALID(dwarf::DW_OP_bit_piece); |
| 1918 | EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3); |
| 1919 | EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_plus, 3); |
| 1920 | EXPECT_INVALID(dwarf::DW_OP_bit_piece, 3, 7, dwarf::DW_OP_deref); |
| 1921 | |
| 1922 | #undef EXPECT_VALID |
| 1923 | #undef EXPECT_INVALID |
| 1924 | } |
| 1925 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1926 | typedef MetadataTest MDObjCPropertyTest; |
| 1927 | |
| 1928 | TEST_F(MDObjCPropertyTest, get) { |
| 1929 | StringRef Name = "name"; |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1930 | MDFile *File = getFile(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1931 | unsigned Line = 5; |
| 1932 | StringRef GetterName = "getter"; |
| 1933 | StringRef SetterName = "setter"; |
| 1934 | unsigned Attributes = 7; |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1935 | MDType *Type = cast<MDBasicType>(getBasicType("basic")); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1936 | |
| 1937 | auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1938 | SetterName, Attributes, Type); |
| 1939 | |
| 1940 | EXPECT_EQ(dwarf::DW_TAG_APPLE_property, N->getTag()); |
| 1941 | EXPECT_EQ(Name, N->getName()); |
| 1942 | EXPECT_EQ(File, N->getFile()); |
| 1943 | EXPECT_EQ(Line, N->getLine()); |
| 1944 | EXPECT_EQ(GetterName, N->getGetterName()); |
| 1945 | EXPECT_EQ(SetterName, N->getSetterName()); |
| 1946 | EXPECT_EQ(Attributes, N->getAttributes()); |
| 1947 | EXPECT_EQ(Type, N->getType()); |
| 1948 | EXPECT_EQ(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1949 | SetterName, Attributes, Type)); |
| 1950 | |
| 1951 | EXPECT_NE(N, MDObjCProperty::get(Context, "other", File, Line, GetterName, |
| 1952 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1953 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, getFile(), Line, GetterName, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1954 | SetterName, Attributes, Type)); |
| 1955 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line + 1, GetterName, |
| 1956 | SetterName, Attributes, Type)); |
| 1957 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, "other", |
| 1958 | SetterName, Attributes, Type)); |
| 1959 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1960 | "other", Attributes, Type)); |
| 1961 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1962 | SetterName, Attributes + 1, Type)); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1963 | EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName, |
| 1964 | SetterName, Attributes, |
| 1965 | cast<MDBasicType>(getBasicType("other")))); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1966 | |
| 1967 | TempMDObjCProperty Temp = N->clone(); |
| 1968 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | typedef MetadataTest MDImportedEntityTest; |
| 1972 | |
| 1973 | TEST_F(MDImportedEntityTest, get) { |
| 1974 | unsigned Tag = dwarf::DW_TAG_imported_module; |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1975 | MDScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1976 | DebugNodeRef Entity = getCompositeType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1977 | unsigned Line = 5; |
| 1978 | StringRef Name = "name"; |
| 1979 | |
| 1980 | auto *N = MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name); |
| 1981 | |
| 1982 | EXPECT_EQ(Tag, N->getTag()); |
| 1983 | EXPECT_EQ(Scope, N->getScope()); |
| 1984 | EXPECT_EQ(Entity, N->getEntity()); |
| 1985 | EXPECT_EQ(Line, N->getLine()); |
| 1986 | EXPECT_EQ(Name, N->getName()); |
| 1987 | EXPECT_EQ(N, MDImportedEntity::get(Context, Tag, Scope, Entity, Line, Name)); |
| 1988 | |
| 1989 | EXPECT_NE(N, |
| 1990 | MDImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration, |
| 1991 | Scope, Entity, Line, Name)); |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1992 | EXPECT_NE(N, MDImportedEntity::get(Context, Tag, getSubprogram(), Entity, |
| 1993 | Line, Name)); |
| 1994 | EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, getCompositeType(), |
| 1995 | Line, Name)); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1996 | EXPECT_NE(N, |
| 1997 | MDImportedEntity::get(Context, Tag, Scope, Entity, Line + 1, Name)); |
| 1998 | EXPECT_NE(N, |
| 1999 | MDImportedEntity::get(Context, Tag, Scope, Entity, Line, "other")); |
Duncan P. N. Exon Smith | 6873fea | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2000 | |
| 2001 | TempMDImportedEntity Temp = N->clone(); |
| 2002 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2005 | typedef MetadataTest MetadataAsValueTest; |
| 2006 | |
| 2007 | TEST_F(MetadataAsValueTest, MDNode) { |
| 2008 | MDNode *N = MDNode::get(Context, None); |
| 2009 | auto *V = MetadataAsValue::get(Context, N); |
| 2010 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2011 | EXPECT_EQ(N, V->getMetadata()); |
| 2012 | |
| 2013 | auto *V2 = MetadataAsValue::get(Context, N); |
| 2014 | EXPECT_EQ(V, V2); |
| 2015 | } |
| 2016 | |
| 2017 | TEST_F(MetadataAsValueTest, MDNodeMDNode) { |
| 2018 | MDNode *N = MDNode::get(Context, None); |
| 2019 | Metadata *Ops[] = {N}; |
| 2020 | MDNode *N2 = MDNode::get(Context, Ops); |
| 2021 | auto *V = MetadataAsValue::get(Context, N2); |
| 2022 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2023 | EXPECT_EQ(N2, V->getMetadata()); |
| 2024 | |
| 2025 | auto *V2 = MetadataAsValue::get(Context, N2); |
| 2026 | EXPECT_EQ(V, V2); |
| 2027 | |
| 2028 | auto *V3 = MetadataAsValue::get(Context, N); |
| 2029 | EXPECT_TRUE(V3->getType()->isMetadataTy()); |
| 2030 | EXPECT_NE(V, V3); |
| 2031 | EXPECT_EQ(N, V3->getMetadata()); |
| 2032 | } |
| 2033 | |
| 2034 | TEST_F(MetadataAsValueTest, MDNodeConstant) { |
| 2035 | auto *C = ConstantInt::getTrue(Context); |
| 2036 | auto *MD = ConstantAsMetadata::get(C); |
| 2037 | Metadata *Ops[] = {MD}; |
| 2038 | auto *N = MDNode::get(Context, Ops); |
| 2039 | |
| 2040 | auto *V = MetadataAsValue::get(Context, MD); |
| 2041 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2042 | EXPECT_EQ(MD, V->getMetadata()); |
| 2043 | |
| 2044 | auto *V2 = MetadataAsValue::get(Context, N); |
| 2045 | EXPECT_EQ(MD, V2->getMetadata()); |
| 2046 | EXPECT_EQ(V, V2); |
| 2047 | } |
| 2048 | |
Duncan P. N. Exon Smith | 121eeff | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 2049 | typedef MetadataTest ValueAsMetadataTest; |
| 2050 | |
| 2051 | TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) { |
| 2052 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2053 | std::unique_ptr<GlobalVariable> GV0( |
| 2054 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2055 | auto *MD = ValueAsMetadata::get(GV0.get()); |
| 2056 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 2057 | ASSERT_TRUE(GV0->use_empty()); |
| 2058 | |
| 2059 | std::unique_ptr<GlobalVariable> GV1( |
| 2060 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2061 | GV0->replaceAllUsesWith(GV1.get()); |
| 2062 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 2063 | } |
| 2064 | |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2065 | TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) { |
| 2066 | // Create a constant. |
| 2067 | ConstantAsMetadata *CI = ConstantAsMetadata::get( |
| 2068 | ConstantInt::get(getGlobalContext(), APInt(8, 0))); |
| 2069 | |
| 2070 | // Create a temporary to prevent nodes from resolving. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2071 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2072 | |
| 2073 | // When the first operand of N1 gets reset to nullptr, it'll collide with N2. |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2074 | Metadata *Ops1[] = {CI, CI, Temp.get()}; |
| 2075 | Metadata *Ops2[] = {nullptr, CI, Temp.get()}; |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2076 | |
| 2077 | auto *N1 = MDTuple::get(Context, Ops1); |
| 2078 | auto *N2 = MDTuple::get(Context, Ops2); |
| 2079 | ASSERT_NE(N1, N2); |
| 2080 | |
| 2081 | // Tell metadata that the constant is getting deleted. |
| 2082 | // |
| 2083 | // After this, N1 will be invalid, so don't touch it. |
| 2084 | ValueAsMetadata::handleDeletion(CI->getValue()); |
| 2085 | EXPECT_EQ(nullptr, N2->getOperand(0)); |
| 2086 | EXPECT_EQ(nullptr, N2->getOperand(1)); |
Duncan P. N. Exon Smith | 7d82313 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2087 | EXPECT_EQ(Temp.get(), N2->getOperand(2)); |
Duncan P. N. Exon Smith | 4a4f785 | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2088 | |
| 2089 | // Clean up Temp for teardown. |
| 2090 | Temp->replaceAllUsesWith(nullptr); |
| 2091 | } |
| 2092 | |
Duncan P. N. Exon Smith | 121eeff | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 2093 | typedef MetadataTest TrackingMDRefTest; |
| 2094 | |
| 2095 | TEST_F(TrackingMDRefTest, UpdatesOnRAUW) { |
| 2096 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2097 | std::unique_ptr<GlobalVariable> GV0( |
| 2098 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2099 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV0.get())); |
| 2100 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 2101 | ASSERT_TRUE(GV0->use_empty()); |
| 2102 | |
| 2103 | std::unique_ptr<GlobalVariable> GV1( |
| 2104 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2105 | GV0->replaceAllUsesWith(GV1.get()); |
| 2106 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 2107 | |
| 2108 | // Reset it, so we don't inadvertently test deletion. |
| 2109 | MD.reset(); |
| 2110 | } |
| 2111 | |
| 2112 | TEST_F(TrackingMDRefTest, UpdatesOnDeletion) { |
| 2113 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2114 | std::unique_ptr<GlobalVariable> GV( |
| 2115 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2116 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV.get())); |
| 2117 | EXPECT_TRUE(MD->getValue() == GV.get()); |
| 2118 | ASSERT_TRUE(GV->use_empty()); |
| 2119 | |
| 2120 | GV.reset(); |
| 2121 | EXPECT_TRUE(!MD); |
| 2122 | } |
| 2123 | |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2124 | TEST(NamedMDNodeTest, Search) { |
Jeffrey Yasskin | bd8a759 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 2125 | LLVMContext Context; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2126 | ConstantAsMetadata *C = |
| 2127 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 1)); |
| 2128 | ConstantAsMetadata *C2 = |
| 2129 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 2)); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2130 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2131 | Metadata *const V = C; |
| 2132 | Metadata *const V2 = C2; |
Jay Foad | 5514afe | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 2133 | MDNode *n = MDNode::get(Context, V); |
| 2134 | MDNode *n2 = MDNode::get(Context, V2); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2135 | |
Jeffrey Yasskin | 3d73d1a | 2010-03-13 01:39:20 +0000 | [diff] [blame] | 2136 | Module M("MyModule", Context); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2137 | const char *Name = "llvm.NMD1"; |
Dan Gohman | 2637cc1 | 2010-07-21 23:38:33 +0000 | [diff] [blame] | 2138 | NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name); |
| 2139 | NMD->addOperand(n); |
| 2140 | NMD->addOperand(n2); |
| 2141 | |
Chris Lattner | be354a6 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 2142 | std::string Str; |
| 2143 | raw_string_ostream oss(Str); |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2144 | NMD->print(oss); |
Chris Lattner | 1e6e367 | 2009-12-31 02:12:13 +0000 | [diff] [blame] | 2145 | EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n", |
Devang Patel | 0924b33 | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2146 | oss.str().c_str()); |
| 2147 | } |
Nick Lewycky | 49f8919 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2148 | } |