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