Duncan P. N. Exon Smith | 0784a4d | 2015-02-02 18:20:15 +0000 | [diff] [blame] | 1 | //===- unittests/IR/MetadataTest.cpp - Metadata unit tests ----------------===// |
Nick Lewycky | 21cc446 | 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 | |
Chandler Carruth | 3c0d607 | 2017-06-06 11:06:56 +0000 | [diff] [blame] | 10 | #include "llvm/IR/Metadata.h" |
Duncan P. N. Exon Smith | 698be08 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 12 | #include "llvm/IR/Constants.h" |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 13 | #include "llvm/IR/DebugInfo.h" |
Duncan P. N. Exon Smith | ca8d3bf | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 14 | #include "llvm/IR/DebugInfoMetadata.h" |
Duncan P. N. Exon Smith | a9d82a5 | 2015-02-18 20:32:57 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Function.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Instructions.h" |
| 17 | #include "llvm/IR/LLVMContext.h" |
| 18 | #include "llvm/IR/Module.h" |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 19 | #include "llvm/IR/ModuleSlotTracker.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Type.h" |
Duncan P. N. Exon Smith | ef477f3 | 2015-04-24 21:53:27 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 5a88dda | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 5a88dda | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 23 | #include "gtest/gtest.h" |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
| 26 | namespace { |
| 27 | |
Duncan P. N. Exon Smith | 641414a | 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 | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 65 | class MetadataTest : public testing::Test { |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 66 | public: |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 67 | MetadataTest() : M("test", Context), Counter(0) {} |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 68 | |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 69 | protected: |
| 70 | LLVMContext Context; |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 71 | Module M; |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 72 | int Counter; |
| 73 | |
Duncan P. N. Exon Smith | 2ebd1ef | 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 | c4eafd2 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 80 | |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 81 | MDTuple *getTuple() { return MDTuple::getDistinct(Context, None); } |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 82 | DISubroutineType *getSubroutineType() { |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 83 | return DISubroutineType::getDistinct(Context, DINode::FlagZero, 0, |
| 84 | getNode(nullptr)); |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 85 | } |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 86 | DISubprogram *getSubprogram() { |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 87 | return DISubprogram::getDistinct( |
| 88 | Context, nullptr, "", "", nullptr, 0, nullptr, 0, nullptr, 0, 0, |
| 89 | DINode::FlagZero, DISubprogram::SPFlagZero, nullptr); |
Duncan P. N. Exon Smith | c4eafd2 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 90 | } |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 91 | DIFile *getFile() { |
| 92 | return DIFile::getDistinct(Context, "file.c", "/path/to/dir"); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 93 | } |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 94 | DICompileUnit *getUnit() { |
Peter Collingbourne | 76221cb | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 95 | return DICompileUnit::getDistinct( |
| 96 | Context, 1, getFile(), "clang", false, "-g", 2, "", |
| 97 | DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(), |
David Blaikie | cf8a4a5 | 2018-08-16 21:29:55 +0000 | [diff] [blame] | 98 | getTuple(), getTuple(), 0, true, false, |
David Blaikie | ecc582a | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 99 | DICompileUnit::DebugNameTableKind::Default, false); |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 100 | } |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 101 | DIType *getBasicType(StringRef Name) { |
| 102 | return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 103 | } |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 104 | DIType *getDerivedType() { |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 105 | return DIDerivedType::getDistinct( |
| 106 | Context, dwarf::DW_TAG_pointer_type, "", nullptr, 0, nullptr, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 107 | getBasicType("basictype"), 1, 2, 0, None, DINode::FlagZero); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 108 | } |
Duncan P. N. Exon Smith | e2e6412 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 109 | Constant *getConstant() { |
| 110 | return ConstantInt::get(Type::getInt32Ty(Context), Counter++); |
| 111 | } |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 112 | ConstantAsMetadata *getConstantAsMetadata() { |
Duncan P. N. Exon Smith | e2e6412 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 113 | return ConstantAsMetadata::get(getConstant()); |
Duncan P. N. Exon Smith | a9902da | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 114 | } |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 115 | DIType *getCompositeType() { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 116 | return DICompositeType::getDistinct( |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 117 | Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr, nullptr, |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 118 | 32, 32, 0, DINode::FlagZero, nullptr, 0, nullptr, nullptr, ""); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 119 | } |
Duncan P. N. Exon Smith | e2e6412 | 2015-04-11 20:27:40 +0000 | [diff] [blame] | 120 | Function *getFunction(StringRef Name) { |
| 121 | return cast<Function>(M.getOrInsertFunction( |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 122 | Name, FunctionType::get(Type::getVoidTy(Context), None, false))); |
| 123 | } |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 124 | }; |
| 125 | typedef MetadataTest MDStringTest; |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 126 | |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 127 | // Test that construction of MDString with different value produces different |
| 128 | // MDString objects, even with the same string pointer and nulls in the string. |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 129 | TEST_F(MDStringTest, CreateDifferent) { |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 130 | char x[3] = { 'f', 0, 'A' }; |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 131 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 132 | x[2] = 'B'; |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 133 | MDString *s2 = MDString::get(Context, StringRef(&x[0], 3)); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 134 | EXPECT_NE(s1, s2); |
| 135 | } |
| 136 | |
| 137 | // Test that creation of MDStrings with the same string contents produces the |
| 138 | // same MDString object, even with different pointers. |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 139 | TEST_F(MDStringTest, CreateSame) { |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 140 | char x[4] = { 'a', 'b', 'c', 'X' }; |
| 141 | char y[4] = { 'a', 'b', 'c', 'Y' }; |
| 142 | |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 143 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 144 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 145 | EXPECT_EQ(s1, s2); |
| 146 | } |
| 147 | |
| 148 | // Test that MDString prints out the string we fed it. |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 149 | TEST_F(MDStringTest, PrintingSimple) { |
Florian Hahn | 8080935 | 2018-11-25 19:38:02 +0000 | [diff] [blame] | 150 | char str[14] = "testing 1 2 3"; |
| 151 | MDString *s = MDString::get(Context, StringRef(&str[0], 13)); |
| 152 | strncpy(str, "aaaaaaaaaaaaa", 14); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 153 | |
Chris Lattner | 0c47a41 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 154 | std::string Str; |
| 155 | raw_string_ostream oss(Str); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 156 | s->print(oss); |
Duncan P. N. Exon Smith | 02a8d1b | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 157 | EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str()); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Test printing of MDString with non-printable characters. |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 161 | TEST_F(MDStringTest, PrintingComplex) { |
Jeffrey Yasskin | cda2a14 | 2011-08-30 20:53:29 +0000 | [diff] [blame] | 162 | char str[5] = {0, '\n', '"', '\\', (char)-1}; |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 163 | MDString *s = MDString::get(Context, StringRef(str+0, 5)); |
Chris Lattner | 0c47a41 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 164 | std::string Str; |
| 165 | raw_string_ostream oss(Str); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 166 | s->print(oss); |
Duncan P. N. Exon Smith | 02a8d1b | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 167 | EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str()); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 170 | typedef MetadataTest MDNodeTest; |
| 171 | |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 172 | // Test the two constructors, and containing other Constants. |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 173 | TEST_F(MDNodeTest, Simple) { |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 174 | char x[3] = { 'a', 'b', 'c' }; |
| 175 | char y[3] = { '1', '2', '3' }; |
| 176 | |
Owen Anderson | 5d0bf1b | 2009-07-31 21:38:10 +0000 | [diff] [blame] | 177 | MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); |
| 178 | MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); |
Mehdi Amini | 8be7707 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 179 | ConstantAsMetadata *CI = |
| 180 | ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0))); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 181 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 182 | std::vector<Metadata *> V; |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 183 | V.push_back(s1); |
| 184 | V.push_back(CI); |
| 185 | V.push_back(s2); |
| 186 | |
Jay Foad | ec9186bc | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 187 | MDNode *n1 = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 188 | Metadata *const c1 = n1; |
Jay Foad | ec9186bc | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 189 | MDNode *n2 = MDNode::get(Context, c1); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 190 | Metadata *const c2 = n2; |
Jay Foad | ec9186bc | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 191 | MDNode *n3 = MDNode::get(Context, V); |
Duncan Sands | 4000afe | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 192 | MDNode *n4 = MDNode::getIfExists(Context, V); |
| 193 | MDNode *n5 = MDNode::getIfExists(Context, c1); |
| 194 | MDNode *n6 = MDNode::getIfExists(Context, c2); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 195 | EXPECT_NE(n1, n2); |
Devang Patel | 5f4ac84 | 2009-09-03 01:39:20 +0000 | [diff] [blame] | 196 | EXPECT_EQ(n1, n3); |
Duncan Sands | 4000afe | 2012-03-31 08:20:11 +0000 | [diff] [blame] | 197 | EXPECT_EQ(n4, n1); |
| 198 | EXPECT_EQ(n5, n2); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 199 | EXPECT_EQ(n6, (Metadata *)nullptr); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 200 | |
Chris Lattner | 5d0cacd | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 201 | EXPECT_EQ(3u, n1->getNumOperands()); |
| 202 | EXPECT_EQ(s1, n1->getOperand(0)); |
| 203 | EXPECT_EQ(CI, n1->getOperand(1)); |
| 204 | EXPECT_EQ(s2, n1->getOperand(2)); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 205 | |
Chris Lattner | 5d0cacd | 2009-12-31 01:22:29 +0000 | [diff] [blame] | 206 | EXPECT_EQ(1u, n2->getNumOperands()); |
| 207 | EXPECT_EQ(n1, n2->getOperand(0)); |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 208 | } |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 209 | |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 210 | TEST_F(MDNodeTest, Delete) { |
Mehdi Amini | 8be7707 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 211 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 1); |
| 212 | Instruction *I = new BitCastInst(C, Type::getInt32Ty(Context)); |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 213 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 214 | Metadata *const V = LocalAsMetadata::get(I); |
Jay Foad | ec9186bc | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 215 | MDNode *n = MDNode::get(Context, V); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 216 | TrackingMDRef wvh(n); |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 217 | |
| 218 | EXPECT_EQ(n, wvh); |
| 219 | |
Reid Kleckner | 816047d | 2017-05-18 17:24:10 +0000 | [diff] [blame] | 220 | I->deleteValue(); |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 221 | } |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 222 | |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 223 | TEST_F(MDNodeTest, SelfReference) { |
Duncan P. N. Exon Smith | 9e2c0f9 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 224 | // !0 = !{!0} |
| 225 | // !1 = !{!0} |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 226 | { |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 227 | auto Temp = MDNode::getTemporary(Context, None); |
| 228 | Metadata *Args[] = {Temp.get()}; |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 229 | MDNode *Self = MDNode::get(Context, Args); |
| 230 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 231 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 232 | |
| 233 | // Self-references should be distinct, so MDNode::get() should grab a |
| 234 | // uniqued node that references Self, not Self. |
| 235 | Args[0] = Self; |
| 236 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 237 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 238 | EXPECT_NE(Self, Ref1); |
| 239 | EXPECT_EQ(Ref1, Ref2); |
| 240 | } |
| 241 | |
Duncan P. N. Exon Smith | 9e2c0f9 | 2014-12-16 07:45:05 +0000 | [diff] [blame] | 242 | // !0 = !{!0, !{}} |
| 243 | // !1 = !{!0, !{}} |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 244 | { |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 245 | auto Temp = MDNode::getTemporary(Context, None); |
| 246 | Metadata *Args[] = {Temp.get(), MDNode::get(Context, None)}; |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 247 | MDNode *Self = MDNode::get(Context, Args); |
| 248 | Self->replaceOperandWith(0, Self); |
Duncan P. N. Exon Smith | 7280d8c | 2014-12-07 19:52:06 +0000 | [diff] [blame] | 249 | ASSERT_EQ(Self, Self->getOperand(0)); |
| 250 | |
| 251 | // Self-references should be distinct, so MDNode::get() should grab a |
| 252 | // uniqued node that references Self, not Self itself. |
| 253 | Args[0] = Self; |
| 254 | MDNode *Ref1 = MDNode::get(Context, Args); |
| 255 | MDNode *Ref2 = MDNode::get(Context, Args); |
| 256 | EXPECT_NE(Self, Ref1); |
| 257 | EXPECT_EQ(Ref1, Ref2); |
| 258 | } |
| 259 | } |
| 260 | |
Duncan P. N. Exon Smith | 2ebd1ef | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 261 | TEST_F(MDNodeTest, Print) { |
| 262 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7); |
| 263 | MDString *S = MDString::get(Context, "foo"); |
| 264 | MDNode *N0 = getNode(); |
| 265 | MDNode *N1 = getNode(N0); |
| 266 | MDNode *N2 = getNode(N0, N1); |
| 267 | |
| 268 | Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2}; |
| 269 | MDNode *N = MDNode::get(Context, Args); |
| 270 | |
| 271 | std::string Expected; |
| 272 | { |
| 273 | raw_string_ostream OS(Expected); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 274 | OS << "<" << (void *)N << "> = !{"; |
Duncan P. N. Exon Smith | 2ebd1ef | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 275 | C->printAsOperand(OS); |
| 276 | OS << ", "; |
Duncan P. N. Exon Smith | 02a8d1b | 2014-12-16 07:40:31 +0000 | [diff] [blame] | 277 | S->printAsOperand(OS); |
Duncan P. N. Exon Smith | 2ebd1ef | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 278 | OS << ", null"; |
| 279 | MDNode *Nodes[] = {N0, N1, N2}; |
| 280 | for (auto *Node : Nodes) |
| 281 | OS << ", <" << (void *)Node << ">"; |
Duncan P. N. Exon Smith | 344ea29 | 2015-02-25 22:46:38 +0000 | [diff] [blame] | 282 | OS << "}"; |
Duncan P. N. Exon Smith | 2ebd1ef | 2014-12-16 07:09:37 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | std::string Actual; |
| 286 | { |
| 287 | raw_string_ostream OS(Actual); |
| 288 | N->print(OS); |
| 289 | } |
| 290 | |
| 291 | EXPECT_EQ(Expected, Actual); |
| 292 | } |
| 293 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 294 | #define EXPECT_PRINTER_EQ(EXPECTED, PRINT) \ |
| 295 | do { \ |
| 296 | std::string Actual_; \ |
| 297 | raw_string_ostream OS(Actual_); \ |
| 298 | PRINT; \ |
| 299 | OS.flush(); \ |
| 300 | std::string Expected_(EXPECTED); \ |
| 301 | EXPECT_EQ(Expected_, Actual_); \ |
| 302 | } while (false) |
| 303 | |
Duncan P. N. Exon Smith | bee74a3 | 2015-03-16 21:21:10 +0000 | [diff] [blame] | 304 | TEST_F(MDNodeTest, PrintTemporary) { |
| 305 | MDNode *Arg = getNode(); |
| 306 | TempMDNode Temp = MDNode::getTemporary(Context, Arg); |
| 307 | MDNode *N = getNode(Temp.get()); |
| 308 | Module M("test", Context); |
| 309 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("named"); |
| 310 | NMD->addOperand(N); |
| 311 | |
| 312 | EXPECT_PRINTER_EQ("!0 = !{!1}", N->print(OS, &M)); |
| 313 | EXPECT_PRINTER_EQ("!1 = <temporary!> !{!2}", Temp->print(OS, &M)); |
| 314 | EXPECT_PRINTER_EQ("!2 = !{}", Arg->print(OS, &M)); |
| 315 | |
| 316 | // Cleanup. |
| 317 | Temp->replaceAllUsesWith(Arg); |
| 318 | } |
| 319 | |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 320 | TEST_F(MDNodeTest, PrintFromModule) { |
| 321 | Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7); |
| 322 | MDString *S = MDString::get(Context, "foo"); |
| 323 | MDNode *N0 = getNode(); |
| 324 | MDNode *N1 = getNode(N0); |
| 325 | MDNode *N2 = getNode(N0, N1); |
| 326 | |
| 327 | Metadata *Args[] = {ConstantAsMetadata::get(C), S, nullptr, N0, N1, N2}; |
| 328 | MDNode *N = MDNode::get(Context, Args); |
| 329 | Module M("test", Context); |
| 330 | NamedMDNode *NMD = M.getOrInsertNamedMetadata("named"); |
| 331 | NMD->addOperand(N); |
| 332 | |
| 333 | std::string Expected; |
| 334 | { |
| 335 | raw_string_ostream OS(Expected); |
| 336 | OS << "!0 = !{"; |
| 337 | C->printAsOperand(OS); |
| 338 | OS << ", "; |
| 339 | S->printAsOperand(OS); |
| 340 | OS << ", null, !1, !2, !3}"; |
| 341 | } |
| 342 | |
| 343 | EXPECT_PRINTER_EQ(Expected, N->print(OS, &M)); |
| 344 | } |
| 345 | |
| 346 | TEST_F(MDNodeTest, PrintFromFunction) { |
| 347 | Module M("test", Context); |
| 348 | auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); |
| 349 | auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); |
| 350 | auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); |
| 351 | auto *BB0 = BasicBlock::Create(Context, "entry", F0); |
| 352 | auto *BB1 = BasicBlock::Create(Context, "entry", F1); |
| 353 | auto *R0 = ReturnInst::Create(Context, BB0); |
| 354 | auto *R1 = ReturnInst::Create(Context, BB1); |
| 355 | auto *N0 = MDNode::getDistinct(Context, None); |
| 356 | auto *N1 = MDNode::getDistinct(Context, None); |
| 357 | R0->setMetadata("md", N0); |
| 358 | R1->setMetadata("md", N1); |
| 359 | |
| 360 | EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M)); |
| 361 | EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M)); |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 362 | |
| 363 | ModuleSlotTracker MST(&M); |
| 364 | EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, MST)); |
| 365 | EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, MST)); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | TEST_F(MDNodeTest, PrintFromMetadataAsValue) { |
| 369 | Module M("test", Context); |
| 370 | |
| 371 | auto *Intrinsic = |
| 372 | Function::Create(FunctionType::get(Type::getVoidTy(Context), |
| 373 | Type::getMetadataTy(Context), false), |
| 374 | GlobalValue::ExternalLinkage, "llvm.intrinsic", &M); |
| 375 | |
| 376 | auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); |
| 377 | auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); |
| 378 | auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); |
| 379 | auto *BB0 = BasicBlock::Create(Context, "entry", F0); |
| 380 | auto *BB1 = BasicBlock::Create(Context, "entry", F1); |
| 381 | auto *N0 = MDNode::getDistinct(Context, None); |
| 382 | auto *N1 = MDNode::getDistinct(Context, None); |
| 383 | auto *MAV0 = MetadataAsValue::get(Context, N0); |
| 384 | auto *MAV1 = MetadataAsValue::get(Context, N1); |
| 385 | CallInst::Create(Intrinsic, MAV0, "", BB0); |
| 386 | CallInst::Create(Intrinsic, MAV1, "", BB1); |
| 387 | |
| 388 | EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS)); |
| 389 | EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS)); |
| 390 | EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false)); |
| 391 | EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false)); |
| 392 | EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true)); |
| 393 | EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true)); |
Duncan P. N. Exon Smith | 2a5fda9 | 2015-06-27 00:38:26 +0000 | [diff] [blame] | 394 | |
| 395 | ModuleSlotTracker MST(&M); |
| 396 | EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS, MST)); |
| 397 | EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS, MST)); |
| 398 | EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false, MST)); |
| 399 | EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false, MST)); |
| 400 | EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true, MST)); |
| 401 | EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true, MST)); |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 402 | } |
David Stenberg | 11ef6e1 | 2018-11-02 11:46:24 +0000 | [diff] [blame] | 403 | |
| 404 | TEST_F(MDNodeTest, PrintWithDroppedCallOperand) { |
| 405 | Module M("test", Context); |
| 406 | |
| 407 | auto *FTy = FunctionType::get(Type::getVoidTy(Context), false); |
| 408 | auto *F0 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F0", &M); |
| 409 | auto *F1 = Function::Create(FTy, GlobalValue::ExternalLinkage, "F1", &M); |
| 410 | auto *BB0 = BasicBlock::Create(Context, "entry", F0); |
| 411 | |
| 412 | CallInst *CI0 = CallInst::Create(F1, "", BB0); |
| 413 | CI0->dropAllReferences(); |
| 414 | |
| 415 | auto *R0 = ReturnInst::Create(Context, BB0); |
| 416 | auto *N0 = MDNode::getDistinct(Context, None); |
| 417 | R0->setMetadata("md", N0); |
| 418 | |
| 419 | // Printing the metadata node would previously result in a failed assertion |
| 420 | // due to the call instruction's dropped function operand. |
| 421 | ModuleSlotTracker MST(&M); |
| 422 | EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, MST)); |
| 423 | } |
Duncan P. N. Exon Smith | f9f505e | 2015-03-14 20:19:36 +0000 | [diff] [blame] | 424 | #undef EXPECT_PRINTER_EQ |
| 425 | |
Duncan P. N. Exon Smith | 97d1c07 | 2015-01-05 23:31:54 +0000 | [diff] [blame] | 426 | TEST_F(MDNodeTest, NullOperand) { |
| 427 | // metadata !{} |
| 428 | MDNode *Empty = MDNode::get(Context, None); |
| 429 | |
| 430 | // metadata !{metadata !{}} |
| 431 | Metadata *Ops[] = {Empty}; |
| 432 | MDNode *N = MDNode::get(Context, Ops); |
| 433 | ASSERT_EQ(Empty, N->getOperand(0)); |
| 434 | |
| 435 | // metadata !{metadata !{}} => metadata !{null} |
| 436 | N->replaceOperandWith(0, nullptr); |
| 437 | ASSERT_EQ(nullptr, N->getOperand(0)); |
| 438 | |
| 439 | // metadata !{null} |
| 440 | Ops[0] = nullptr; |
| 441 | MDNode *NullOp = MDNode::get(Context, Ops); |
| 442 | ASSERT_EQ(nullptr, NullOp->getOperand(0)); |
| 443 | EXPECT_EQ(N, NullOp); |
| 444 | } |
| 445 | |
Duncan P. N. Exon Smith | ee06e12 | 2015-01-07 21:35:38 +0000 | [diff] [blame] | 446 | TEST_F(MDNodeTest, DistinctOnUniquingCollision) { |
| 447 | // !{} |
| 448 | MDNode *Empty = MDNode::get(Context, None); |
| 449 | ASSERT_TRUE(Empty->isResolved()); |
| 450 | EXPECT_FALSE(Empty->isDistinct()); |
| 451 | |
| 452 | // !{!{}} |
| 453 | Metadata *Wrapped1Ops[] = {Empty}; |
| 454 | MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops); |
| 455 | ASSERT_EQ(Empty, Wrapped1->getOperand(0)); |
| 456 | ASSERT_TRUE(Wrapped1->isResolved()); |
| 457 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 458 | |
| 459 | // !{!{!{}}} |
| 460 | Metadata *Wrapped2Ops[] = {Wrapped1}; |
| 461 | MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops); |
| 462 | ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0)); |
| 463 | ASSERT_TRUE(Wrapped2->isResolved()); |
| 464 | EXPECT_FALSE(Wrapped2->isDistinct()); |
| 465 | |
| 466 | // !{!{!{}}} => !{!{}} |
| 467 | Wrapped2->replaceOperandWith(0, Empty); |
| 468 | ASSERT_EQ(Empty, Wrapped2->getOperand(0)); |
| 469 | EXPECT_TRUE(Wrapped2->isDistinct()); |
| 470 | EXPECT_FALSE(Wrapped1->isDistinct()); |
| 471 | } |
| 472 | |
Duncan P. N. Exon Smith | 8fa25a1 | 2016-08-03 18:19:43 +0000 | [diff] [blame] | 473 | TEST_F(MDNodeTest, UniquedOnDeletedOperand) { |
| 474 | // temp !{} |
| 475 | TempMDTuple T = MDTuple::getTemporary(Context, None); |
| 476 | |
| 477 | // !{temp !{}} |
| 478 | Metadata *Ops[] = {T.get()}; |
| 479 | MDTuple *N = MDTuple::get(Context, Ops); |
| 480 | |
| 481 | // !{temp !{}} => !{null} |
| 482 | T.reset(); |
| 483 | ASSERT_TRUE(N->isUniqued()); |
| 484 | Metadata *NullOps[] = {nullptr}; |
| 485 | ASSERT_EQ(N, MDTuple::get(Context, NullOps)); |
| 486 | } |
| 487 | |
| 488 | TEST_F(MDNodeTest, DistinctOnDeletedValueOperand) { |
| 489 | // i1* @GV |
| 490 | Type *Ty = Type::getInt1PtrTy(Context); |
| 491 | std::unique_ptr<GlobalVariable> GV( |
| 492 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 493 | ConstantAsMetadata *Op = ConstantAsMetadata::get(GV.get()); |
| 494 | |
| 495 | // !{i1* @GV} |
| 496 | Metadata *Ops[] = {Op}; |
| 497 | MDTuple *N = MDTuple::get(Context, Ops); |
| 498 | |
| 499 | // !{i1* @GV} => !{null} |
| 500 | GV.reset(); |
| 501 | ASSERT_TRUE(N->isDistinct()); |
| 502 | ASSERT_EQ(nullptr, N->getOperand(0)); |
| 503 | Metadata *NullOps[] = {nullptr}; |
| 504 | ASSERT_NE(N, MDTuple::get(Context, NullOps)); |
| 505 | } |
| 506 | |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 507 | TEST_F(MDNodeTest, getDistinct) { |
| 508 | // !{} |
| 509 | MDNode *Empty = MDNode::get(Context, None); |
| 510 | ASSERT_TRUE(Empty->isResolved()); |
| 511 | ASSERT_FALSE(Empty->isDistinct()); |
| 512 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 513 | |
| 514 | // distinct !{} |
| 515 | MDNode *Distinct1 = MDNode::getDistinct(Context, None); |
| 516 | MDNode *Distinct2 = MDNode::getDistinct(Context, None); |
| 517 | EXPECT_TRUE(Distinct1->isResolved()); |
| 518 | EXPECT_TRUE(Distinct2->isDistinct()); |
| 519 | EXPECT_NE(Empty, Distinct1); |
| 520 | EXPECT_NE(Empty, Distinct2); |
| 521 | EXPECT_NE(Distinct1, Distinct2); |
| 522 | |
| 523 | // !{} |
| 524 | ASSERT_EQ(Empty, MDNode::get(Context, None)); |
| 525 | } |
| 526 | |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 527 | TEST_F(MDNodeTest, isUniqued) { |
| 528 | MDNode *U = MDTuple::get(Context, None); |
| 529 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 530 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 531 | EXPECT_TRUE(U->isUniqued()); |
| 532 | EXPECT_FALSE(D->isUniqued()); |
| 533 | EXPECT_FALSE(T->isUniqued()); |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | TEST_F(MDNodeTest, isDistinct) { |
| 537 | MDNode *U = MDTuple::get(Context, None); |
| 538 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 539 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 540 | EXPECT_FALSE(U->isDistinct()); |
| 541 | EXPECT_TRUE(D->isDistinct()); |
| 542 | EXPECT_FALSE(T->isDistinct()); |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | TEST_F(MDNodeTest, isTemporary) { |
| 546 | MDNode *U = MDTuple::get(Context, None); |
| 547 | MDNode *D = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 548 | auto T = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 1d72e18 | 2015-01-19 18:45:35 +0000 | [diff] [blame] | 549 | EXPECT_FALSE(U->isTemporary()); |
| 550 | EXPECT_FALSE(D->isTemporary()); |
| 551 | EXPECT_TRUE(T->isTemporary()); |
Duncan P. N. Exon Smith | 28184c1 | 2015-01-12 18:41:26 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 554 | TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) { |
| 555 | // temporary !{} |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 556 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 557 | ASSERT_FALSE(Temp->isResolved()); |
| 558 | |
| 559 | // distinct !{temporary !{}} |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 560 | Metadata *Ops[] = {Temp.get()}; |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 561 | MDNode *Distinct = MDNode::getDistinct(Context, Ops); |
| 562 | EXPECT_TRUE(Distinct->isResolved()); |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 563 | EXPECT_EQ(Temp.get(), Distinct->getOperand(0)); |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 564 | |
| 565 | // temporary !{} => !{} |
| 566 | MDNode *Empty = MDNode::get(Context, None); |
| 567 | Temp->replaceAllUsesWith(Empty); |
Duncan P. N. Exon Smith | 727176d | 2015-01-07 22:24:46 +0000 | [diff] [blame] | 568 | EXPECT_EQ(Empty, Distinct->getOperand(0)); |
| 569 | } |
| 570 | |
Duncan P. N. Exon Smith | 728315a | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 571 | TEST_F(MDNodeTest, handleChangedOperandRecursion) { |
| 572 | // !0 = !{} |
| 573 | MDNode *N0 = MDNode::get(Context, None); |
| 574 | |
| 575 | // !1 = !{!3, null} |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 576 | auto Temp3 = MDTuple::getTemporary(Context, None); |
| 577 | Metadata *Ops1[] = {Temp3.get(), nullptr}; |
Duncan P. N. Exon Smith | 728315a | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 578 | MDNode *N1 = MDNode::get(Context, Ops1); |
| 579 | |
| 580 | // !2 = !{!3, !0} |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 581 | Metadata *Ops2[] = {Temp3.get(), N0}; |
Duncan P. N. Exon Smith | 728315a | 2015-01-12 19:22:04 +0000 | [diff] [blame] | 582 | MDNode *N2 = MDNode::get(Context, Ops2); |
| 583 | |
| 584 | // !3 = !{!2} |
| 585 | Metadata *Ops3[] = {N2}; |
| 586 | MDNode *N3 = MDNode::get(Context, Ops3); |
| 587 | Temp3->replaceAllUsesWith(N3); |
| 588 | |
| 589 | // !4 = !{!1} |
| 590 | Metadata *Ops4[] = {N1}; |
| 591 | MDNode *N4 = MDNode::get(Context, Ops4); |
| 592 | |
| 593 | // Confirm that the cycle prevented RAUW from getting dropped. |
| 594 | EXPECT_TRUE(N0->isResolved()); |
| 595 | EXPECT_FALSE(N1->isResolved()); |
| 596 | EXPECT_FALSE(N2->isResolved()); |
| 597 | EXPECT_FALSE(N3->isResolved()); |
| 598 | EXPECT_FALSE(N4->isResolved()); |
| 599 | |
| 600 | // Create a couple of distinct nodes to observe what's going on. |
| 601 | // |
| 602 | // !5 = distinct !{!2} |
| 603 | // !6 = distinct !{!3} |
| 604 | Metadata *Ops5[] = {N2}; |
| 605 | MDNode *N5 = MDNode::getDistinct(Context, Ops5); |
| 606 | Metadata *Ops6[] = {N3}; |
| 607 | MDNode *N6 = MDNode::getDistinct(Context, Ops6); |
| 608 | |
| 609 | // Mutate !2 to look like !1, causing a uniquing collision (and an RAUW). |
| 610 | // This will ripple up, with !3 colliding with !4, and RAUWing. Since !2 |
| 611 | // references !3, this can cause a re-entry of handleChangedOperand() when !3 |
| 612 | // is not ready for it. |
| 613 | // |
| 614 | // !2->replaceOperandWith(1, nullptr) |
| 615 | // !2: !{!3, !0} => !{!3, null} |
| 616 | // !2->replaceAllUsesWith(!1) |
| 617 | // !3: !{!2] => !{!1} |
| 618 | // !3->replaceAllUsesWith(!4) |
| 619 | N2->replaceOperandWith(1, nullptr); |
| 620 | |
| 621 | // If all has gone well, N2 and N3 will have been RAUW'ed and deleted from |
| 622 | // under us. Just check that the other nodes are sane. |
| 623 | // |
| 624 | // !1 = !{!4, null} |
| 625 | // !4 = !{!1} |
| 626 | // !5 = distinct !{!1} |
| 627 | // !6 = distinct !{!4} |
| 628 | EXPECT_EQ(N4, N1->getOperand(0)); |
| 629 | EXPECT_EQ(N1, N4->getOperand(0)); |
| 630 | EXPECT_EQ(N1, N5->getOperand(0)); |
| 631 | EXPECT_EQ(N4, N6->getOperand(0)); |
| 632 | } |
| 633 | |
Duncan P. N. Exon Smith | 698be08 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 634 | TEST_F(MDNodeTest, replaceResolvedOperand) { |
| 635 | // Check code for replacing one resolved operand with another. If doing this |
| 636 | // directly (via replaceOperandWith()) becomes illegal, change the operand to |
| 637 | // a global value that gets RAUW'ed. |
| 638 | // |
| 639 | // Use a temporary node to keep N from being resolved. |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 640 | auto Temp = MDTuple::getTemporary(Context, None); |
| 641 | Metadata *Ops[] = {nullptr, Temp.get()}; |
Duncan P. N. Exon Smith | 698be08 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 642 | |
NAKAMURA Takumi | 16a6d38 | 2015-01-13 08:13:46 +0000 | [diff] [blame] | 643 | MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>()); |
Duncan P. N. Exon Smith | 698be08 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 644 | MDNode *N = MDTuple::get(Context, Ops); |
| 645 | EXPECT_EQ(nullptr, N->getOperand(0)); |
| 646 | ASSERT_FALSE(N->isResolved()); |
| 647 | |
| 648 | // Check code for replacing resolved nodes. |
| 649 | N->replaceOperandWith(0, Empty); |
| 650 | EXPECT_EQ(Empty, N->getOperand(0)); |
| 651 | |
| 652 | // Check code for adding another unresolved operand. |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 653 | N->replaceOperandWith(0, Temp.get()); |
| 654 | EXPECT_EQ(Temp.get(), N->getOperand(0)); |
Duncan P. N. Exon Smith | 698be08 | 2015-01-13 00:46:34 +0000 | [diff] [blame] | 655 | |
| 656 | // Remove the references to Temp; required for teardown. |
| 657 | Temp->replaceAllUsesWith(nullptr); |
| 658 | } |
| 659 | |
Duncan P. N. Exon Smith | 37c7ccc | 2015-01-19 22:24:52 +0000 | [diff] [blame] | 660 | TEST_F(MDNodeTest, replaceWithUniqued) { |
| 661 | auto *Empty = MDTuple::get(Context, None); |
| 662 | MDTuple *FirstUniqued; |
| 663 | { |
| 664 | Metadata *Ops[] = {Empty}; |
| 665 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 666 | EXPECT_TRUE(Temp->isTemporary()); |
| 667 | |
| 668 | // Don't expect a collision. |
| 669 | auto *Current = Temp.get(); |
| 670 | FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 671 | EXPECT_TRUE(FirstUniqued->isUniqued()); |
| 672 | EXPECT_TRUE(FirstUniqued->isResolved()); |
| 673 | EXPECT_EQ(Current, FirstUniqued); |
| 674 | } |
| 675 | { |
| 676 | Metadata *Ops[] = {Empty}; |
| 677 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 678 | EXPECT_TRUE(Temp->isTemporary()); |
| 679 | |
| 680 | // Should collide with Uniqued above this time. |
| 681 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 682 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 683 | EXPECT_TRUE(Uniqued->isResolved()); |
| 684 | EXPECT_EQ(FirstUniqued, Uniqued); |
| 685 | } |
| 686 | { |
| 687 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 688 | Metadata *Ops[] = {Unresolved.get()}; |
| 689 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 690 | EXPECT_TRUE(Temp->isTemporary()); |
| 691 | |
| 692 | // Shouldn't be resolved. |
| 693 | auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp)); |
| 694 | EXPECT_TRUE(Uniqued->isUniqued()); |
| 695 | EXPECT_FALSE(Uniqued->isResolved()); |
| 696 | |
| 697 | // Should be a different node. |
| 698 | EXPECT_NE(FirstUniqued, Uniqued); |
| 699 | |
| 700 | // Should resolve when we update its node (note: be careful to avoid a |
| 701 | // collision with any other nodes above). |
| 702 | Uniqued->replaceOperandWith(0, nullptr); |
| 703 | EXPECT_TRUE(Uniqued->isResolved()); |
| 704 | } |
| 705 | } |
| 706 | |
Duncan P. N. Exon Smith | 34dea0f | 2015-03-31 21:05:06 +0000 | [diff] [blame] | 707 | TEST_F(MDNodeTest, replaceWithUniquedResolvingOperand) { |
Duncan P. N. Exon Smith | f067a68 | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 708 | // temp !{} |
| 709 | MDTuple *Op = MDTuple::getTemporary(Context, None).release(); |
| 710 | EXPECT_FALSE(Op->isResolved()); |
| 711 | |
| 712 | // temp !{temp !{}} |
| 713 | Metadata *Ops[] = {Op}; |
| 714 | MDTuple *N = MDTuple::getTemporary(Context, Ops).release(); |
| 715 | EXPECT_FALSE(N->isResolved()); |
| 716 | |
| 717 | // temp !{temp !{}} => !{temp !{}} |
| 718 | ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N))); |
| 719 | EXPECT_FALSE(N->isResolved()); |
| 720 | |
| 721 | // !{temp !{}} => !{!{}} |
| 722 | ASSERT_EQ(Op, MDNode::replaceWithUniqued(TempMDTuple(Op))); |
| 723 | EXPECT_TRUE(Op->isResolved()); |
| 724 | EXPECT_TRUE(N->isResolved()); |
| 725 | } |
| 726 | |
Duncan P. N. Exon Smith | 8fa25a1 | 2016-08-03 18:19:43 +0000 | [diff] [blame] | 727 | TEST_F(MDNodeTest, replaceWithUniquedDeletedOperand) { |
Duncan P. N. Exon Smith | f067a68 | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 728 | // i1* @GV |
| 729 | Type *Ty = Type::getInt1PtrTy(Context); |
| 730 | std::unique_ptr<GlobalVariable> GV( |
| 731 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 732 | ConstantAsMetadata *Op = ConstantAsMetadata::get(GV.get()); |
| 733 | |
| 734 | // temp !{i1* @GV} |
| 735 | Metadata *Ops[] = {Op}; |
| 736 | MDTuple *N = MDTuple::getTemporary(Context, Ops).release(); |
| 737 | |
| 738 | // temp !{i1* @GV} => !{i1* @GV} |
| 739 | ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N))); |
| 740 | ASSERT_TRUE(N->isUniqued()); |
| 741 | |
| 742 | // !{i1* @GV} => !{null} |
| 743 | GV.reset(); |
Duncan P. N. Exon Smith | 8fa25a1 | 2016-08-03 18:19:43 +0000 | [diff] [blame] | 744 | ASSERT_TRUE(N->isDistinct()); |
| 745 | ASSERT_EQ(nullptr, N->getOperand(0)); |
Duncan P. N. Exon Smith | f067a68 | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 746 | Metadata *NullOps[] = {nullptr}; |
Duncan P. N. Exon Smith | 8fa25a1 | 2016-08-03 18:19:43 +0000 | [diff] [blame] | 747 | ASSERT_NE(N, MDTuple::get(Context, NullOps)); |
| 748 | } |
| 749 | |
| 750 | TEST_F(MDNodeTest, replaceWithUniquedChangedOperand) { |
| 751 | // i1* @GV |
| 752 | Type *Ty = Type::getInt1PtrTy(Context); |
| 753 | std::unique_ptr<GlobalVariable> GV( |
| 754 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 755 | ConstantAsMetadata *Op = ConstantAsMetadata::get(GV.get()); |
| 756 | |
| 757 | // temp !{i1* @GV} |
| 758 | Metadata *Ops[] = {Op}; |
| 759 | MDTuple *N = MDTuple::getTemporary(Context, Ops).release(); |
| 760 | |
| 761 | // temp !{i1* @GV} => !{i1* @GV} |
| 762 | ASSERT_EQ(N, MDNode::replaceWithUniqued(TempMDTuple(N))); |
| 763 | ASSERT_TRUE(N->isUniqued()); |
| 764 | |
| 765 | // !{i1* @GV} => !{i1* @GV2} |
| 766 | std::unique_ptr<GlobalVariable> GV2( |
| 767 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 768 | GV->replaceAllUsesWith(GV2.get()); |
| 769 | ASSERT_TRUE(N->isUniqued()); |
| 770 | Metadata *NullOps[] = {ConstantAsMetadata::get(GV2.get())}; |
Duncan P. N. Exon Smith | f067a68 | 2015-03-31 20:50:50 +0000 | [diff] [blame] | 771 | ASSERT_EQ(N, MDTuple::get(Context, NullOps)); |
| 772 | } |
| 773 | |
Duncan P. N. Exon Smith | 37c7ccc | 2015-01-19 22:24:52 +0000 | [diff] [blame] | 774 | TEST_F(MDNodeTest, replaceWithDistinct) { |
| 775 | { |
| 776 | auto *Empty = MDTuple::get(Context, None); |
| 777 | Metadata *Ops[] = {Empty}; |
| 778 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 779 | EXPECT_TRUE(Temp->isTemporary()); |
| 780 | |
| 781 | // Don't expect a collision. |
| 782 | auto *Current = Temp.get(); |
| 783 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 784 | EXPECT_TRUE(Distinct->isDistinct()); |
| 785 | EXPECT_TRUE(Distinct->isResolved()); |
| 786 | EXPECT_EQ(Current, Distinct); |
| 787 | } |
| 788 | { |
| 789 | auto Unresolved = MDTuple::getTemporary(Context, None); |
| 790 | Metadata *Ops[] = {Unresolved.get()}; |
| 791 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 792 | EXPECT_TRUE(Temp->isTemporary()); |
| 793 | |
| 794 | // Don't expect a collision. |
| 795 | auto *Current = Temp.get(); |
| 796 | auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp)); |
| 797 | EXPECT_TRUE(Distinct->isDistinct()); |
| 798 | EXPECT_TRUE(Distinct->isResolved()); |
| 799 | EXPECT_EQ(Current, Distinct); |
| 800 | |
| 801 | // Cleanup; required for teardown. |
| 802 | Unresolved->replaceAllUsesWith(nullptr); |
| 803 | } |
| 804 | } |
| 805 | |
Duncan P. N. Exon Smith | 027898a | 2015-02-10 19:13:46 +0000 | [diff] [blame] | 806 | TEST_F(MDNodeTest, replaceWithPermanent) { |
| 807 | Metadata *Ops[] = {nullptr}; |
| 808 | auto Temp = MDTuple::getTemporary(Context, Ops); |
| 809 | auto *T = Temp.get(); |
| 810 | |
| 811 | // U is a normal, uniqued node that references T. |
| 812 | auto *U = MDTuple::get(Context, T); |
| 813 | EXPECT_TRUE(U->isUniqued()); |
| 814 | |
| 815 | // Make Temp self-referencing. |
| 816 | Temp->replaceOperandWith(0, T); |
| 817 | |
| 818 | // Try to uniquify Temp. This should, despite the name in the API, give a |
| 819 | // 'distinct' node, since self-references aren't allowed to be uniqued. |
| 820 | // |
| 821 | // Since it's distinct, N should have the same address as when it was a |
| 822 | // temporary (i.e., be equal to T not U). |
| 823 | auto *N = MDNode::replaceWithPermanent(std::move(Temp)); |
| 824 | EXPECT_EQ(N, T); |
| 825 | EXPECT_TRUE(N->isDistinct()); |
| 826 | |
| 827 | // U should be the canonical unique node with N as the argument. |
| 828 | EXPECT_EQ(U, MDTuple::get(Context, N)); |
| 829 | EXPECT_TRUE(U->isUniqued()); |
| 830 | |
| 831 | // This temporary should collide with U when replaced, but it should still be |
| 832 | // uniqued. |
| 833 | EXPECT_EQ(U, MDNode::replaceWithPermanent(MDTuple::getTemporary(Context, N))); |
| 834 | EXPECT_TRUE(U->isUniqued()); |
| 835 | |
| 836 | // This temporary should become a new uniqued node. |
| 837 | auto Temp2 = MDTuple::getTemporary(Context, U); |
| 838 | auto *V = Temp2.get(); |
| 839 | EXPECT_EQ(V, MDNode::replaceWithPermanent(std::move(Temp2))); |
| 840 | EXPECT_TRUE(V->isUniqued()); |
| 841 | EXPECT_EQ(U, V->getOperand(0)); |
| 842 | } |
| 843 | |
Duncan P. N. Exon Smith | 0033461 | 2015-01-22 21:36:45 +0000 | [diff] [blame] | 844 | TEST_F(MDNodeTest, deleteTemporaryWithTrackingRef) { |
| 845 | TrackingMDRef Ref; |
| 846 | EXPECT_EQ(nullptr, Ref.get()); |
| 847 | { |
| 848 | auto Temp = MDTuple::getTemporary(Context, None); |
| 849 | Ref.reset(Temp.get()); |
| 850 | EXPECT_EQ(Temp.get(), Ref.get()); |
| 851 | } |
| 852 | EXPECT_EQ(nullptr, Ref.get()); |
| 853 | } |
| 854 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 855 | typedef MetadataTest DILocationTest; |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 856 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 857 | TEST_F(DILocationTest, Overflow) { |
| 858 | DISubprogram *N = getSubprogram(); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 859 | { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 860 | DILocation *L = DILocation::get(Context, 2, 7, N); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 861 | EXPECT_EQ(2u, L->getLine()); |
| 862 | EXPECT_EQ(7u, L->getColumn()); |
| 863 | } |
Duncan P. N. Exon Smith | fb7514f | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 864 | unsigned U16 = 1u << 16; |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 865 | { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 866 | DILocation *L = DILocation::get(Context, UINT32_MAX, U16 - 1, N); |
Duncan P. N. Exon Smith | 8713d99 | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 867 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | fb7514f | 2015-01-16 17:33:08 +0000 | [diff] [blame] | 868 | EXPECT_EQ(U16 - 1, L->getColumn()); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 869 | } |
| 870 | { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 871 | DILocation *L = DILocation::get(Context, UINT32_MAX, U16, N); |
Duncan P. N. Exon Smith | 8713d99 | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 872 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 873 | EXPECT_EQ(0u, L->getColumn()); |
| 874 | } |
| 875 | { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 876 | DILocation *L = DILocation::get(Context, UINT32_MAX, U16 + 1, N); |
Duncan P. N. Exon Smith | 8713d99 | 2015-02-06 22:50:13 +0000 | [diff] [blame] | 877 | EXPECT_EQ(UINT32_MAX, L->getLine()); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 878 | EXPECT_EQ(0u, L->getColumn()); |
| 879 | } |
| 880 | } |
| 881 | |
Adrian Prantl | 59c0c36 | 2018-08-24 23:30:57 +0000 | [diff] [blame] | 882 | TEST_F(DILocationTest, Merge) { |
| 883 | DISubprogram *N = getSubprogram(); |
| 884 | DIScope *S = DILexicalBlock::get(Context, N, getFile(), 3, 4); |
| 885 | |
| 886 | { |
| 887 | // Identical. |
| 888 | auto *A = DILocation::get(Context, 2, 7, N); |
| 889 | auto *B = DILocation::get(Context, 2, 7, N); |
| 890 | auto *M = DILocation::getMergedLocation(A, B); |
| 891 | EXPECT_EQ(2u, M->getLine()); |
| 892 | EXPECT_EQ(7u, M->getColumn()); |
| 893 | EXPECT_EQ(N, M->getScope()); |
| 894 | } |
| 895 | |
| 896 | { |
| 897 | // Identical, different scopes. |
| 898 | auto *A = DILocation::get(Context, 2, 7, N); |
| 899 | auto *B = DILocation::get(Context, 2, 7, S); |
| 900 | auto *M = DILocation::getMergedLocation(A, B); |
| 901 | EXPECT_EQ(0u, M->getLine()); // FIXME: Should this be 2? |
| 902 | EXPECT_EQ(0u, M->getColumn()); // FIXME: Should this be 7? |
| 903 | EXPECT_EQ(N, M->getScope()); |
| 904 | } |
| 905 | |
| 906 | { |
| 907 | // Different lines, same scopes. |
| 908 | auto *A = DILocation::get(Context, 1, 6, N); |
| 909 | auto *B = DILocation::get(Context, 2, 7, N); |
| 910 | auto *M = DILocation::getMergedLocation(A, B); |
| 911 | EXPECT_EQ(0u, M->getLine()); |
| 912 | EXPECT_EQ(0u, M->getColumn()); |
| 913 | EXPECT_EQ(N, M->getScope()); |
| 914 | } |
| 915 | |
| 916 | { |
| 917 | // Twisty locations, all different, same function. |
| 918 | auto *A = DILocation::get(Context, 1, 6, N); |
| 919 | auto *B = DILocation::get(Context, 2, 7, S); |
| 920 | auto *M = DILocation::getMergedLocation(A, B); |
| 921 | EXPECT_EQ(0u, M->getLine()); |
| 922 | EXPECT_EQ(0u, M->getColumn()); |
| 923 | EXPECT_EQ(N, M->getScope()); |
| 924 | } |
| 925 | |
| 926 | { |
| 927 | // Different function, same inlined-at. |
| 928 | auto *F = getFile(); |
| 929 | auto *SP1 = DISubprogram::getDistinct(Context, F, "a", "a", F, 0, nullptr, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 930 | 0, nullptr, 0, 0, DINode::FlagZero, |
| 931 | DISubprogram::SPFlagZero, nullptr); |
Adrian Prantl | 59c0c36 | 2018-08-24 23:30:57 +0000 | [diff] [blame] | 932 | auto *SP2 = DISubprogram::getDistinct(Context, F, "b", "b", F, 0, nullptr, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 933 | 0, nullptr, 0, 0, DINode::FlagZero, |
| 934 | DISubprogram::SPFlagZero, nullptr); |
Adrian Prantl | 59c0c36 | 2018-08-24 23:30:57 +0000 | [diff] [blame] | 935 | |
| 936 | auto *I = DILocation::get(Context, 2, 7, N); |
| 937 | auto *A = DILocation::get(Context, 1, 6, SP1, I); |
| 938 | auto *B = DILocation::get(Context, 2, 7, SP2, I); |
| 939 | auto *M = DILocation::getMergedLocation(A, B); |
| 940 | EXPECT_EQ(0u, M->getLine()); |
| 941 | EXPECT_EQ(0u, M->getColumn()); |
| 942 | EXPECT_TRUE(isa<DILocalScope>(M->getScope())); |
| 943 | EXPECT_EQ(I, M->getInlinedAt()); |
| 944 | } |
| 945 | |
| 946 | { |
| 947 | // Completely different. |
| 948 | auto *I = DILocation::get(Context, 2, 7, N); |
| 949 | auto *A = DILocation::get(Context, 1, 6, S, I); |
| 950 | auto *B = DILocation::get(Context, 2, 7, getSubprogram()); |
| 951 | auto *M = DILocation::getMergedLocation(A, B); |
| 952 | EXPECT_EQ(0u, M->getLine()); |
| 953 | EXPECT_EQ(0u, M->getColumn()); |
| 954 | EXPECT_TRUE(isa<DILocalScope>(M->getScope())); |
| 955 | EXPECT_EQ(S, M->getScope()); |
| 956 | EXPECT_EQ(nullptr, M->getInlinedAt()); |
| 957 | } |
| 958 | } |
| 959 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 960 | TEST_F(DILocationTest, getDistinct) { |
Duncan P. N. Exon Smith | c4eafd2 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 961 | MDNode *N = getSubprogram(); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 962 | DILocation *L0 = DILocation::getDistinct(Context, 2, 7, N); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 963 | EXPECT_TRUE(L0->isDistinct()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 964 | DILocation *L1 = DILocation::get(Context, 2, 7, N); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 965 | EXPECT_FALSE(L1->isDistinct()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 966 | EXPECT_EQ(L1, DILocation::get(Context, 2, 7, N)); |
Duncan P. N. Exon Smith | d640962 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 969 | TEST_F(DILocationTest, getTemporary) { |
Duncan P. N. Exon Smith | a7852bf | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 970 | MDNode *N = MDNode::get(Context, None); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 971 | auto L = DILocation::getTemporary(Context, 2, 7, N); |
Duncan P. N. Exon Smith | a7852bf | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 972 | EXPECT_TRUE(L->isTemporary()); |
| 973 | EXPECT_FALSE(L->isResolved()); |
Duncan P. N. Exon Smith | a7852bf | 2015-01-19 20:37:44 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Teresa Johnson | fda49fd | 2015-12-07 15:05:44 +0000 | [diff] [blame] | 976 | TEST_F(DILocationTest, cloneTemporary) { |
| 977 | MDNode *N = MDNode::get(Context, None); |
| 978 | auto L = DILocation::getTemporary(Context, 2, 7, N); |
| 979 | EXPECT_TRUE(L->isTemporary()); |
| 980 | auto L2 = L->clone(); |
| 981 | EXPECT_TRUE(L2->isTemporary()); |
| 982 | } |
| 983 | |
Mircea Trofin | 001ab10 | 2018-12-21 22:48:50 +0000 | [diff] [blame] | 984 | TEST_F(DILocationTest, discriminatorEncoding) { |
| 985 | EXPECT_EQ(0U, DILocation::encodeDiscriminator(0, 0, 0).getValue()); |
| 986 | |
| 987 | // Encode base discriminator as a component: lsb is 0, then the value. |
| 988 | // The other components are all absent, so we leave all the other bits 0. |
| 989 | EXPECT_EQ(2U, DILocation::encodeDiscriminator(1, 0, 0).getValue()); |
| 990 | |
| 991 | // Base discriminator component is empty, so lsb is 1. Next component is not |
| 992 | // empty, so its lsb is 0, then its value (1). Next component is empty. |
| 993 | // So the bit pattern is 101. |
| 994 | EXPECT_EQ(5U, DILocation::encodeDiscriminator(0, 1, 0).getValue()); |
| 995 | |
| 996 | // First 2 components are empty, so the bit pattern is 11. Then the |
| 997 | // next component - ending up with 1011. |
| 998 | EXPECT_EQ(0xbU, DILocation::encodeDiscriminator(0, 0, 1).getValue()); |
| 999 | |
| 1000 | // The bit pattern for the first 2 components is 11. The next bit is 0, |
| 1001 | // because the last component is not empty. We have 29 bits usable for |
| 1002 | // encoding, but we cap it at 12 bits uniformously for all components. We |
| 1003 | // encode the last component over 14 bits. |
| 1004 | EXPECT_EQ(0xfffbU, DILocation::encodeDiscriminator(0, 0, 0xfff).getValue()); |
| 1005 | |
| 1006 | EXPECT_EQ(0x102U, DILocation::encodeDiscriminator(1, 1, 0).getValue()); |
| 1007 | |
| 1008 | EXPECT_EQ(0x13eU, DILocation::encodeDiscriminator(0x1f, 1, 0).getValue()); |
| 1009 | |
| 1010 | EXPECT_EQ(0x87feU, DILocation::encodeDiscriminator(0x1ff, 1, 0).getValue()); |
| 1011 | |
| 1012 | EXPECT_EQ(0x1f3eU, DILocation::encodeDiscriminator(0x1f, 0x1f, 0).getValue()); |
| 1013 | |
| 1014 | EXPECT_EQ(0x3ff3eU, |
| 1015 | DILocation::encodeDiscriminator(0x1f, 0x1ff, 0).getValue()); |
| 1016 | |
| 1017 | EXPECT_EQ(0x1ff87feU, |
| 1018 | DILocation::encodeDiscriminator(0x1ff, 0x1ff, 0).getValue()); |
| 1019 | |
| 1020 | EXPECT_EQ(0xfff9f3eU, |
| 1021 | DILocation::encodeDiscriminator(0x1f, 0x1f, 0xfff).getValue()); |
| 1022 | |
| 1023 | EXPECT_EQ(0xffc3ff3eU, |
| 1024 | DILocation::encodeDiscriminator(0x1f, 0x1ff, 0x1ff).getValue()); |
| 1025 | |
| 1026 | EXPECT_EQ(0xffcf87feU, |
| 1027 | DILocation::encodeDiscriminator(0x1ff, 0x1f, 0x1ff).getValue()); |
| 1028 | |
| 1029 | EXPECT_EQ(0xe1ff87feU, |
| 1030 | DILocation::encodeDiscriminator(0x1ff, 0x1ff, 7).getValue()); |
| 1031 | } |
| 1032 | |
| 1033 | TEST_F(DILocationTest, discriminatorEncodingNegativeTests) { |
| 1034 | EXPECT_EQ(None, DILocation::encodeDiscriminator(0, 0, 0x1000)); |
| 1035 | EXPECT_EQ(None, DILocation::encodeDiscriminator(0x1000, 0, 0)); |
| 1036 | EXPECT_EQ(None, DILocation::encodeDiscriminator(0, 0x1000, 0)); |
| 1037 | EXPECT_EQ(None, DILocation::encodeDiscriminator(0, 0, 0x1000)); |
| 1038 | EXPECT_EQ(None, DILocation::encodeDiscriminator(0x1ff, 0x1ff, 8)); |
| 1039 | EXPECT_EQ(None, |
| 1040 | DILocation::encodeDiscriminator(std::numeric_limits<uint32_t>::max(), |
| 1041 | std::numeric_limits<uint32_t>::max(), |
| 1042 | 0)); |
| 1043 | } |
| 1044 | |
| 1045 | TEST_F(DILocationTest, discriminatorSpecialCases) { |
| 1046 | // We don't test getCopyIdentifier here because the only way |
| 1047 | // to set it is by constructing an encoded discriminator using |
| 1048 | // encodeDiscriminator, which is already tested. |
| 1049 | auto L1 = DILocation::get(Context, 1, 2, getSubprogram()); |
| 1050 | EXPECT_EQ(0U, L1->getBaseDiscriminator()); |
| 1051 | EXPECT_EQ(1U, L1->getDuplicationFactor()); |
| 1052 | |
| 1053 | auto L2 = L1->setBaseDiscriminator(1).getValue(); |
| 1054 | EXPECT_EQ(0U, L1->getBaseDiscriminator()); |
| 1055 | EXPECT_EQ(1U, L1->getDuplicationFactor()); |
| 1056 | |
| 1057 | EXPECT_EQ(1U, L2->getBaseDiscriminator()); |
| 1058 | EXPECT_EQ(1U, L2->getDuplicationFactor()); |
| 1059 | |
| 1060 | auto L3 = L2->cloneWithDuplicationFactor(2).getValue(); |
| 1061 | EXPECT_EQ(1U, L3->getBaseDiscriminator()); |
| 1062 | EXPECT_EQ(2U, L3->getDuplicationFactor()); |
| 1063 | |
| 1064 | auto L4 = L3->cloneWithDuplicationFactor(4).getValue(); |
| 1065 | EXPECT_EQ(1U, L4->getBaseDiscriminator()); |
| 1066 | EXPECT_EQ(8U, L4->getDuplicationFactor()); |
| 1067 | |
| 1068 | auto L5 = L4->setBaseDiscriminator(2).getValue(); |
| 1069 | EXPECT_EQ(2U, L5->getBaseDiscriminator()); |
| 1070 | EXPECT_EQ(1U, L5->getDuplicationFactor()); |
| 1071 | |
| 1072 | // Check extreme cases |
| 1073 | auto L6 = L1->setBaseDiscriminator(0xfff).getValue(); |
| 1074 | EXPECT_EQ(0xfffU, L6->getBaseDiscriminator()); |
| 1075 | EXPECT_EQ( |
| 1076 | 0xfffU, |
| 1077 | L6->cloneWithDuplicationFactor(0xfff).getValue()->getDuplicationFactor()); |
| 1078 | |
| 1079 | // Check we return None for unencodable cases. |
| 1080 | EXPECT_EQ(None, L4->setBaseDiscriminator(0x1000)); |
| 1081 | EXPECT_EQ(None, L4->cloneWithDuplicationFactor(0x1000)); |
| 1082 | } |
| 1083 | |
| 1084 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1085 | typedef MetadataTest GenericDINodeTest; |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1086 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1087 | TEST_F(GenericDINodeTest, get) { |
Duncan P. N. Exon Smith | a791aea | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 1088 | StringRef Header = "header"; |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1089 | auto *Empty = MDNode::get(Context, None); |
| 1090 | Metadata *Ops1[] = {Empty}; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1091 | auto *N = GenericDINode::get(Context, 15, Header, Ops1); |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1092 | EXPECT_EQ(15u, N->getTag()); |
| 1093 | EXPECT_EQ(2u, N->getNumOperands()); |
| 1094 | EXPECT_EQ(Header, N->getHeader()); |
Duncan P. N. Exon Smith | a791aea | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 1095 | EXPECT_EQ(MDString::get(Context, Header), N->getOperand(0)); |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1096 | EXPECT_EQ(1u, N->getNumDwarfOperands()); |
| 1097 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 1098 | EXPECT_EQ(Empty, N->getOperand(1)); |
| 1099 | ASSERT_TRUE(N->isUniqued()); |
| 1100 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1101 | EXPECT_EQ(N, GenericDINode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1102 | |
| 1103 | N->replaceOperandWith(1, nullptr); |
| 1104 | EXPECT_EQ(15u, N->getTag()); |
| 1105 | EXPECT_EQ(Header, N->getHeader()); |
| 1106 | EXPECT_EQ(nullptr, N->getDwarfOperand(0)); |
| 1107 | ASSERT_TRUE(N->isUniqued()); |
| 1108 | |
| 1109 | Metadata *Ops2[] = {nullptr}; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1110 | EXPECT_EQ(N, GenericDINode::get(Context, 15, Header, Ops2)); |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1111 | |
| 1112 | N->replaceDwarfOperandWith(0, Empty); |
| 1113 | EXPECT_EQ(15u, N->getTag()); |
| 1114 | EXPECT_EQ(Header, N->getHeader()); |
| 1115 | EXPECT_EQ(Empty, N->getDwarfOperand(0)); |
| 1116 | ASSERT_TRUE(N->isUniqued()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1117 | EXPECT_EQ(N, GenericDINode::get(Context, 15, Header, Ops1)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1118 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1119 | TempGenericDINode Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1120 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 0a9f921 | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1123 | TEST_F(GenericDINodeTest, getEmptyHeader) { |
Duncan P. N. Exon Smith | 62475af | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 1124 | // Canonicalize !"" to null. |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1125 | auto *N = GenericDINode::get(Context, 15, StringRef(), None); |
Duncan P. N. Exon Smith | a791aea | 2015-01-22 23:10:55 +0000 | [diff] [blame] | 1126 | EXPECT_EQ(StringRef(), N->getHeader()); |
| 1127 | EXPECT_EQ(nullptr, N->getOperand(0)); |
Duncan P. N. Exon Smith | 62475af | 2015-01-20 00:58:46 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1130 | typedef MetadataTest DISubrangeTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1131 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1132 | TEST_F(DISubrangeTest, get) { |
| 1133 | auto *N = DISubrange::get(Context, 5, 7); |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1134 | auto Count = N->getCount(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1135 | EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1136 | ASSERT_TRUE(Count); |
| 1137 | ASSERT_TRUE(Count.is<ConstantInt*>()); |
| 1138 | EXPECT_EQ(5, Count.get<ConstantInt*>()->getSExtValue()); |
Duncan P. N. Exon Smith | 329f821 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 1139 | EXPECT_EQ(7, N->getLowerBound()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1140 | EXPECT_EQ(N, DISubrange::get(Context, 5, 7)); |
| 1141 | EXPECT_EQ(DISubrange::get(Context, 5, 0), DISubrange::get(Context, 5)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1142 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1143 | TempDISubrange Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1144 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1147 | TEST_F(DISubrangeTest, getEmptyArray) { |
| 1148 | auto *N = DISubrange::get(Context, -1, 0); |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1149 | auto Count = N->getCount(); |
Duncan P. N. Exon Smith | c2c5e48 | 2015-02-18 23:17:51 +0000 | [diff] [blame] | 1150 | EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1151 | ASSERT_TRUE(Count); |
| 1152 | ASSERT_TRUE(Count.is<ConstantInt*>()); |
| 1153 | EXPECT_EQ(-1, Count.get<ConstantInt*>()->getSExtValue()); |
Duncan P. N. Exon Smith | 329f821 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 1154 | EXPECT_EQ(0, N->getLowerBound()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1155 | EXPECT_EQ(N, DISubrange::get(Context, -1, 0)); |
Duncan P. N. Exon Smith | c2c5e48 | 2015-02-18 23:17:51 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Sander de Smalen | 959cee7 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 1158 | TEST_F(DISubrangeTest, getVariableCount) { |
| 1159 | DILocalScope *Scope = getSubprogram(); |
| 1160 | DIFile *File = getFile(); |
| 1161 | DIType *Type = getDerivedType(); |
| 1162 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(7); |
| 1163 | auto *VlaExpr = DILocalVariable::get(Context, Scope, "vla_expr", File, 8, |
| 1164 | Type, 2, Flags, 8); |
| 1165 | |
| 1166 | auto *N = DISubrange::get(Context, VlaExpr, 0); |
| 1167 | auto Count = N->getCount(); |
| 1168 | ASSERT_TRUE(Count); |
| 1169 | ASSERT_TRUE(Count.is<DIVariable*>()); |
| 1170 | EXPECT_EQ(VlaExpr, Count.get<DIVariable*>()); |
| 1171 | ASSERT_TRUE(isa<DIVariable>(N->getRawCountNode())); |
| 1172 | EXPECT_EQ(0, N->getLowerBound()); |
| 1173 | EXPECT_EQ("vla_expr", Count.get<DIVariable*>()->getName()); |
| 1174 | EXPECT_EQ(N, DISubrange::get(Context, VlaExpr, 0)); |
| 1175 | } |
| 1176 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1177 | typedef MetadataTest DIEnumeratorTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1178 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1179 | TEST_F(DIEnumeratorTest, get) { |
Momchil Velikov | 0c69bf4 | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 1180 | auto *N = DIEnumerator::get(Context, 7, false, "name"); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1181 | EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag()); |
| 1182 | EXPECT_EQ(7, N->getValue()); |
Momchil Velikov | 9e8a425 | 2018-02-14 13:11:56 +0000 | [diff] [blame] | 1183 | EXPECT_FALSE(N->isUnsigned()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1184 | EXPECT_EQ("name", N->getName()); |
Momchil Velikov | 0c69bf4 | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 1185 | EXPECT_EQ(N, DIEnumerator::get(Context, 7, false, "name")); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1186 | |
Momchil Velikov | 0c69bf4 | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 1187 | EXPECT_NE(N, DIEnumerator::get(Context, 7, true, "name")); |
| 1188 | EXPECT_NE(N, DIEnumerator::get(Context, 8, false, "name")); |
| 1189 | EXPECT_NE(N, DIEnumerator::get(Context, 7, false, "nam")); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1190 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1191 | TempDIEnumerator Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1192 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1195 | typedef MetadataTest DIBasicTypeTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1196 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1197 | TEST_F(DIBasicTypeTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1198 | auto *N = |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1199 | DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7, |
| 1200 | DINode::FlagZero); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1201 | EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag()); |
| 1202 | EXPECT_EQ("special", N->getName()); |
| 1203 | EXPECT_EQ(33u, N->getSizeInBits()); |
| 1204 | EXPECT_EQ(26u, N->getAlignInBits()); |
| 1205 | EXPECT_EQ(7u, N->getEncoding()); |
| 1206 | EXPECT_EQ(0u, N->getLine()); |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1207 | EXPECT_EQ(DINode::FlagZero, N->getFlags()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1208 | EXPECT_EQ(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1209 | 26, 7, DINode::FlagZero)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1210 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1211 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1212 | "special", 33, 26, 7, DINode::FlagZero)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1213 | EXPECT_NE(N, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1214 | DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7, |
| 1215 | DINode::FlagZero)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1216 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1217 | 26, 7, DINode::FlagZero)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1218 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1219 | 25, 7, DINode::FlagZero)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1220 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1221 | 26, 6, DINode::FlagZero)); |
| 1222 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 1223 | 26, 7, DINode::FlagBigEndian)); |
| 1224 | EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, |
| 1225 | 26, 7, DINode::FlagLittleEndian)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1226 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1227 | TempDIBasicType Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1228 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1231 | TEST_F(DIBasicTypeTest, getWithLargeValues) { |
| 1232 | auto *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1233 | UINT64_MAX, UINT32_MAX - 1, 7, DINode::FlagZero); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1234 | EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); |
Victor Leschuk | 58be60c | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 1235 | EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits()); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1238 | TEST_F(DIBasicTypeTest, getUnspecified) { |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1239 | auto *N = |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1240 | DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, "unspecified"); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1241 | EXPECT_EQ(dwarf::DW_TAG_unspecified_type, N->getTag()); |
| 1242 | EXPECT_EQ("unspecified", N->getName()); |
| 1243 | EXPECT_EQ(0u, N->getSizeInBits()); |
| 1244 | EXPECT_EQ(0u, N->getAlignInBits()); |
| 1245 | EXPECT_EQ(0u, N->getEncoding()); |
| 1246 | EXPECT_EQ(0u, N->getLine()); |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1247 | EXPECT_EQ(DINode::FlagZero, N->getFlags()); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1250 | typedef MetadataTest DITypeTest; |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1251 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1252 | TEST_F(DITypeTest, clone) { |
| 1253 | // Check that DIType has a specialized clone that returns TempDIType. |
| 1254 | DIType *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32, |
Adrian Prantl | c4d1909 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 1255 | dwarf::DW_ATE_signed, DINode::FlagZero); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1256 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1257 | TempDIType Temp = N->clone(); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1258 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
| 1259 | } |
| 1260 | |
Roman Tereshin | a82bdae | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 1261 | TEST_F(DITypeTest, cloneWithFlags) { |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1262 | // void (void) |
| 1263 | Metadata *TypesOps[] = {nullptr}; |
| 1264 | Metadata *Types = MDTuple::get(Context, TypesOps); |
| 1265 | |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1266 | DIType *D = |
| 1267 | DISubroutineType::getDistinct(Context, DINode::FlagZero, 0, Types); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1268 | EXPECT_EQ(DINode::FlagZero, D->getFlags()); |
Roman Tereshin | a82bdae | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 1269 | TempDIType D2 = D->cloneWithFlags(DINode::FlagRValueReference); |
| 1270 | EXPECT_EQ(DINode::FlagRValueReference, D2->getFlags()); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1271 | EXPECT_EQ(DINode::FlagZero, D->getFlags()); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1272 | |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1273 | TempDIType T = |
| 1274 | DISubroutineType::getTemporary(Context, DINode::FlagZero, 0, Types); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1275 | EXPECT_EQ(DINode::FlagZero, T->getFlags()); |
Roman Tereshin | a82bdae | 2018-06-01 23:15:09 +0000 | [diff] [blame] | 1276 | TempDIType T2 = T->cloneWithFlags(DINode::FlagRValueReference); |
| 1277 | EXPECT_EQ(DINode::FlagRValueReference, T2->getFlags()); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1278 | EXPECT_EQ(DINode::FlagZero, T->getFlags()); |
Duncan P. N. Exon Smith | 853cd26 | 2015-03-03 16:45:34 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1281 | typedef MetadataTest DIDerivedTypeTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1282 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1283 | TEST_F(DIDerivedTypeTest, get) { |
| 1284 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1285 | DIScope *Scope = getSubprogram(); |
| 1286 | DIType *BaseType = getBasicType("basic"); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1287 | MDTuple *ExtraData = getTuple(); |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1288 | unsigned DWARFAddressSpace = 8; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1289 | DINode::DIFlags Flags5 = static_cast<DINode::DIFlags>(5); |
| 1290 | DINode::DIFlags Flags4 = static_cast<DINode::DIFlags>(4); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1291 | |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1292 | auto *N = |
| 1293 | DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something", File, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1294 | 1, Scope, BaseType, 2, 3, 4, DWARFAddressSpace, Flags5, |
| 1295 | ExtraData); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1296 | EXPECT_EQ(dwarf::DW_TAG_pointer_type, N->getTag()); |
| 1297 | EXPECT_EQ("something", N->getName()); |
| 1298 | EXPECT_EQ(File, N->getFile()); |
| 1299 | EXPECT_EQ(1u, N->getLine()); |
| 1300 | EXPECT_EQ(Scope, N->getScope()); |
| 1301 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 1302 | EXPECT_EQ(2u, N->getSizeInBits()); |
| 1303 | EXPECT_EQ(3u, N->getAlignInBits()); |
| 1304 | EXPECT_EQ(4u, N->getOffsetInBits()); |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1305 | EXPECT_EQ(DWARFAddressSpace, N->getDWARFAddressSpace().getValue()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1306 | EXPECT_EQ(5u, N->getFlags()); |
| 1307 | EXPECT_EQ(ExtraData, N->getExtraData()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1308 | EXPECT_EQ(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1309 | "something", File, 1, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1310 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1311 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1312 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_reference_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1313 | "something", File, 1, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1314 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1315 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "else", |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1316 | File, 1, Scope, BaseType, 2, 3, |
| 1317 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1318 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1319 | "something", getFile(), 1, Scope, BaseType, 2, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1320 | 3, 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1321 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1322 | "something", File, 2, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1323 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1324 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1325 | "something", File, 1, getSubprogram(), |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1326 | BaseType, 2, 3, 4, DWARFAddressSpace, Flags5, |
| 1327 | ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1328 | EXPECT_NE(N, DIDerivedType::get( |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1329 | Context, dwarf::DW_TAG_pointer_type, "something", File, 1, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1330 | Scope, getBasicType("basic2"), 2, 3, 4, DWARFAddressSpace, |
| 1331 | Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1332 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1333 | "something", File, 1, Scope, BaseType, 3, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1334 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1335 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1336 | "something", File, 1, Scope, BaseType, 2, 2, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1337 | 4, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1338 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1339 | "something", File, 1, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1340 | 5, DWARFAddressSpace, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1341 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1342 | "something", File, 1, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1343 | 4, DWARFAddressSpace + 1, Flags5, ExtraData)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1344 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1345 | "something", File, 1, Scope, BaseType, 2, 3, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1346 | 4, DWARFAddressSpace, Flags4, ExtraData)); |
| 1347 | EXPECT_NE(N, DIDerivedType::get(Context, dwarf::DW_TAG_pointer_type, |
| 1348 | "something", File, 1, Scope, BaseType, 2, 3, |
| 1349 | 4, DWARFAddressSpace, Flags5, getTuple())); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1350 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1351 | TempDIDerivedType Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1352 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1355 | TEST_F(DIDerivedTypeTest, getWithLargeValues) { |
| 1356 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1357 | DIScope *Scope = getSubprogram(); |
| 1358 | DIType *BaseType = getBasicType("basic"); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1359 | MDTuple *ExtraData = getTuple(); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1360 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1361 | |
Leny Kholodov | 01dd3d9 | 2016-09-06 17:03:02 +0000 | [diff] [blame] | 1362 | auto *N = DIDerivedType::get( |
| 1363 | Context, dwarf::DW_TAG_pointer_type, "something", File, 1, Scope, |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1364 | BaseType, UINT64_MAX, UINT32_MAX - 1, UINT64_MAX - 2, UINT32_MAX - 3, |
| 1365 | Flags, ExtraData); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1366 | EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); |
Victor Leschuk | 58be60c | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 1367 | EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits()); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1368 | EXPECT_EQ(UINT64_MAX - 2, N->getOffsetInBits()); |
Konstantin Zhuravlyov | 2cee5cc | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 1369 | EXPECT_EQ(UINT32_MAX - 3, N->getDWARFAddressSpace().getValue()); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1372 | typedef MetadataTest DICompositeTypeTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1373 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1374 | TEST_F(DICompositeTypeTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1375 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1376 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1377 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1378 | unsigned Line = 1; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1379 | DIScope *Scope = getSubprogram(); |
| 1380 | DIType *BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1381 | uint64_t SizeInBits = 2; |
Victor Leschuk | 58be60c | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 1382 | uint32_t AlignInBits = 3; |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1383 | uint64_t OffsetInBits = 4; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1384 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1385 | MDTuple *Elements = getTuple(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1386 | unsigned RuntimeLang = 6; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1387 | DIType *VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1388 | MDTuple *TemplateParams = getTuple(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1389 | StringRef Identifier = "some id"; |
| 1390 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1391 | auto *N = DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1392 | BaseType, SizeInBits, AlignInBits, |
| 1393 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1394 | VTableHolder, TemplateParams, Identifier); |
| 1395 | EXPECT_EQ(Tag, N->getTag()); |
| 1396 | EXPECT_EQ(Name, N->getName()); |
| 1397 | EXPECT_EQ(File, N->getFile()); |
| 1398 | EXPECT_EQ(Line, N->getLine()); |
| 1399 | EXPECT_EQ(Scope, N->getScope()); |
| 1400 | EXPECT_EQ(BaseType, N->getBaseType()); |
| 1401 | EXPECT_EQ(SizeInBits, N->getSizeInBits()); |
| 1402 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
| 1403 | EXPECT_EQ(OffsetInBits, N->getOffsetInBits()); |
| 1404 | EXPECT_EQ(Flags, N->getFlags()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1405 | EXPECT_EQ(Elements, N->getElements().get()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1406 | EXPECT_EQ(RuntimeLang, N->getRuntimeLang()); |
| 1407 | EXPECT_EQ(VTableHolder, N->getVTableHolder()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1408 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1409 | EXPECT_EQ(Identifier, N->getIdentifier()); |
| 1410 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1411 | EXPECT_EQ(N, DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1412 | BaseType, SizeInBits, AlignInBits, |
| 1413 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1414 | VTableHolder, TemplateParams, Identifier)); |
| 1415 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1416 | EXPECT_NE(N, DICompositeType::get(Context, Tag + 1, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1417 | BaseType, SizeInBits, AlignInBits, |
| 1418 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1419 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1420 | EXPECT_NE(N, DICompositeType::get(Context, Tag, "abc", File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1421 | BaseType, SizeInBits, AlignInBits, |
| 1422 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1423 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1424 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, getFile(), Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1425 | BaseType, SizeInBits, AlignInBits, |
| 1426 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1427 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1428 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, File, Line + 1, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1429 | BaseType, SizeInBits, AlignInBits, |
| 1430 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1431 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1432 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1433 | Context, Tag, Name, File, Line, getSubprogram(), BaseType, |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1434 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, |
| 1435 | RuntimeLang, VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1436 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | e009b6f | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 1437 | Context, Tag, Name, File, Line, Scope, getBasicType("other"), |
| 1438 | SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, |
| 1439 | RuntimeLang, VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1440 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1441 | BaseType, SizeInBits + 1, AlignInBits, |
| 1442 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1443 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1444 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1445 | BaseType, SizeInBits, AlignInBits + 1, |
| 1446 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1447 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1448 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1449 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1450 | AlignInBits, OffsetInBits + 1, Flags, Elements, RuntimeLang, |
| 1451 | VTableHolder, TemplateParams, Identifier)); |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1452 | DINode::DIFlags FlagsPOne = static_cast<DINode::DIFlags>(Flags + 1); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1453 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1454 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1455 | AlignInBits, OffsetInBits, FlagsPOne, Elements, RuntimeLang, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1456 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1457 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1458 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1459 | AlignInBits, OffsetInBits, Flags, getTuple(), RuntimeLang, |
| 1460 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1461 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1462 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1463 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang + 1, |
| 1464 | VTableHolder, TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1465 | EXPECT_NE(N, DICompositeType::get( |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1466 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, |
| 1467 | AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, |
| 1468 | getCompositeType(), TemplateParams, Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1469 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1470 | BaseType, SizeInBits, AlignInBits, |
| 1471 | OffsetInBits, Flags, Elements, RuntimeLang, |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1472 | VTableHolder, getTuple(), Identifier)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1473 | EXPECT_NE(N, DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1474 | BaseType, SizeInBits, AlignInBits, |
| 1475 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1476 | VTableHolder, TemplateParams, "other")); |
| 1477 | |
| 1478 | // Be sure that missing identifiers get null pointers. |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1479 | EXPECT_FALSE(DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1480 | BaseType, SizeInBits, AlignInBits, |
| 1481 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1482 | VTableHolder, TemplateParams, "") |
| 1483 | ->getRawIdentifier()); |
| 1484 | EXPECT_FALSE(DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
| 1485 | BaseType, SizeInBits, AlignInBits, |
| 1486 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1487 | VTableHolder, TemplateParams) |
| 1488 | ->getRawIdentifier()); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1489 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1490 | TempDICompositeType Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1491 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1494 | TEST_F(DICompositeTypeTest, getWithLargeValues) { |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1495 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1496 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1497 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1498 | unsigned Line = 1; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1499 | DIScope *Scope = getSubprogram(); |
| 1500 | DIType *BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1501 | uint64_t SizeInBits = UINT64_MAX; |
Victor Leschuk | 58be60c | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 1502 | uint32_t AlignInBits = UINT32_MAX - 1; |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1503 | uint64_t OffsetInBits = UINT64_MAX - 2; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1504 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1505 | MDTuple *Elements = getTuple(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1506 | unsigned RuntimeLang = 6; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1507 | DIType *VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1508 | MDTuple *TemplateParams = getTuple(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1509 | StringRef Identifier = "some id"; |
| 1510 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1511 | auto *N = DICompositeType::get(Context, Tag, Name, File, Line, Scope, |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1512 | BaseType, SizeInBits, AlignInBits, |
| 1513 | OffsetInBits, Flags, Elements, RuntimeLang, |
| 1514 | VTableHolder, TemplateParams, Identifier); |
| 1515 | EXPECT_EQ(SizeInBits, N->getSizeInBits()); |
| 1516 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
| 1517 | EXPECT_EQ(OffsetInBits, N->getOffsetInBits()); |
| 1518 | } |
| 1519 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1520 | TEST_F(DICompositeTypeTest, replaceOperands) { |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1521 | unsigned Tag = dwarf::DW_TAG_structure_type; |
| 1522 | StringRef Name = "some name"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1523 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1524 | unsigned Line = 1; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1525 | DIScope *Scope = getSubprogram(); |
| 1526 | DIType *BaseType = getCompositeType(); |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1527 | uint64_t SizeInBits = 2; |
Victor Leschuk | 58be60c | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 1528 | uint32_t AlignInBits = 3; |
Duncan P. N. Exon Smith | 8a76ab6 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 1529 | uint64_t OffsetInBits = 4; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1530 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1531 | unsigned RuntimeLang = 6; |
| 1532 | StringRef Identifier = "some id"; |
| 1533 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1534 | auto *N = DICompositeType::get( |
| 1535 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, |
| 1536 | OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1537 | |
| 1538 | auto *Elements = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1539 | EXPECT_EQ(nullptr, N->getElements().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1540 | N->replaceElements(Elements); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1541 | EXPECT_EQ(Elements, N->getElements().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1542 | N->replaceElements(nullptr); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1543 | EXPECT_EQ(nullptr, N->getElements().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1544 | |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1545 | DIType *VTableHolder = getCompositeType(); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1546 | EXPECT_EQ(nullptr, N->getVTableHolder()); |
| 1547 | N->replaceVTableHolder(VTableHolder); |
| 1548 | EXPECT_EQ(VTableHolder, N->getVTableHolder()); |
Adrian Prantl | d6200f6 | 2017-11-08 22:04:43 +0000 | [diff] [blame] | 1549 | // As an extension, the containing type can be anything. This is |
| 1550 | // used by Rust to associate vtables with their concrete type. |
| 1551 | DIType *BasicType = getBasicType("basic"); |
| 1552 | N->replaceVTableHolder(BasicType); |
| 1553 | EXPECT_EQ(BasicType, N->getVTableHolder()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1554 | N->replaceVTableHolder(nullptr); |
| 1555 | EXPECT_EQ(nullptr, N->getVTableHolder()); |
| 1556 | |
| 1557 | auto *TemplateParams = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1558 | EXPECT_EQ(nullptr, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1559 | N->replaceTemplateParams(TemplateParams); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1560 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1561 | N->replaceTemplateParams(nullptr); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1562 | EXPECT_EQ(nullptr, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 668aca9 | 2015-02-18 20:47:52 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
Adrian Prantl | 04aa650 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 1565 | TEST_F(DICompositeTypeTest, variant_part) { |
| 1566 | unsigned Tag = dwarf::DW_TAG_variant_part; |
| 1567 | StringRef Name = "some name"; |
| 1568 | DIFile *File = getFile(); |
| 1569 | unsigned Line = 1; |
| 1570 | DIScope *Scope = getSubprogram(); |
| 1571 | DIType *BaseType = getCompositeType(); |
| 1572 | uint64_t SizeInBits = 2; |
| 1573 | uint32_t AlignInBits = 3; |
| 1574 | uint64_t OffsetInBits = 4; |
| 1575 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); |
| 1576 | unsigned RuntimeLang = 6; |
| 1577 | StringRef Identifier = "some id"; |
| 1578 | DIDerivedType *Discriminator = cast<DIDerivedType>(getDerivedType()); |
| 1579 | DIDerivedType *Discriminator2 = cast<DIDerivedType>(getDerivedType()); |
| 1580 | |
| 1581 | EXPECT_NE(Discriminator, Discriminator2); |
| 1582 | |
| 1583 | auto *N = DICompositeType::get( |
| 1584 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, |
| 1585 | OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, |
| 1586 | Discriminator); |
| 1587 | |
| 1588 | // Test the hashing. |
| 1589 | auto *Same = DICompositeType::get( |
| 1590 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, |
| 1591 | OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, |
| 1592 | Discriminator); |
| 1593 | auto *Other = DICompositeType::get( |
| 1594 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, |
| 1595 | OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, |
| 1596 | Discriminator2); |
| 1597 | auto *NoDisc = DICompositeType::get( |
| 1598 | Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, |
| 1599 | OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, |
| 1600 | nullptr); |
| 1601 | |
| 1602 | EXPECT_EQ(N, Same); |
| 1603 | EXPECT_NE(Same, Other); |
| 1604 | EXPECT_NE(Same, NoDisc); |
| 1605 | EXPECT_NE(Other, NoDisc); |
| 1606 | |
| 1607 | EXPECT_EQ(N->getDiscriminator(), Discriminator); |
| 1608 | } |
| 1609 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1610 | typedef MetadataTest DISubroutineTypeTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1611 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1612 | TEST_F(DISubroutineTypeTest, get) { |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1613 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(1); |
| 1614 | DINode::DIFlags FlagsPOne = static_cast<DINode::DIFlags>(Flags + 1); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1615 | MDTuple *TypeArray = getTuple(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1616 | |
Reid Kleckner | 3d3aca2 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1617 | auto *N = DISubroutineType::get(Context, Flags, 0, TypeArray); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1618 | EXPECT_EQ(dwarf::DW_TAG_subroutine_type, N->getTag()); |
| 1619 | EXPECT_EQ(Flags, N->getFlags()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1620 | EXPECT_EQ(TypeArray, N->getTypeArray().get()); |
Reid Kleckner | 3d3aca2 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1621 | EXPECT_EQ(N, DISubroutineType::get(Context, Flags, 0, TypeArray)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1622 | |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1623 | EXPECT_NE(N, DISubroutineType::get(Context, FlagsPOne, 0, TypeArray)); |
Reid Kleckner | 3d3aca2 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 1624 | EXPECT_NE(N, DISubroutineType::get(Context, Flags, 0, getTuple())); |
| 1625 | |
| 1626 | // Test the hashing of calling conventions. |
| 1627 | auto *Fast = DISubroutineType::get( |
| 1628 | Context, Flags, dwarf::DW_CC_BORLAND_msfastcall, TypeArray); |
| 1629 | auto *Std = DISubroutineType::get(Context, Flags, |
| 1630 | dwarf::DW_CC_BORLAND_stdcall, TypeArray); |
| 1631 | EXPECT_EQ(Fast, |
| 1632 | DISubroutineType::get(Context, Flags, |
| 1633 | dwarf::DW_CC_BORLAND_msfastcall, TypeArray)); |
| 1634 | EXPECT_EQ(Std, DISubroutineType::get( |
| 1635 | Context, Flags, dwarf::DW_CC_BORLAND_stdcall, TypeArray)); |
| 1636 | |
| 1637 | EXPECT_NE(N, Fast); |
| 1638 | EXPECT_NE(N, Std); |
| 1639 | EXPECT_NE(Fast, Std); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1640 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1641 | TempDISubroutineType Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1642 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | aeb422f | 2015-02-19 23:25:21 +0000 | [diff] [blame] | 1643 | |
| 1644 | // Test always-empty operands. |
| 1645 | EXPECT_EQ(nullptr, N->getScope()); |
| 1646 | EXPECT_EQ(nullptr, N->getFile()); |
| 1647 | EXPECT_EQ("", N->getName()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1650 | typedef MetadataTest DIFileTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1651 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1652 | TEST_F(DIFileTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1653 | StringRef Filename = "file"; |
| 1654 | StringRef Directory = "dir"; |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1655 | DIFile::ChecksumKind CSKind = DIFile::ChecksumKind::CSK_MD5; |
| 1656 | StringRef ChecksumString = "000102030405060708090a0b0c0d0e0f"; |
| 1657 | DIFile::ChecksumInfo<StringRef> Checksum(CSKind, ChecksumString); |
Scott Linder | 5e4b515 | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 1658 | StringRef Source = "source"; |
| 1659 | auto *N = DIFile::get(Context, Filename, Directory, Checksum, Source); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1660 | |
| 1661 | EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag()); |
| 1662 | EXPECT_EQ(Filename, N->getFilename()); |
| 1663 | EXPECT_EQ(Directory, N->getDirectory()); |
Amjad Aboud | 4e2e80b | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 1664 | EXPECT_EQ(Checksum, N->getChecksum()); |
Scott Linder | 5e4b515 | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 1665 | EXPECT_EQ(Source, N->getSource()); |
| 1666 | EXPECT_EQ(N, DIFile::get(Context, Filename, Directory, Checksum, Source)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1667 | |
Scott Linder | 5e4b515 | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 1668 | EXPECT_NE(N, DIFile::get(Context, "other", Directory, Checksum, Source)); |
| 1669 | EXPECT_NE(N, DIFile::get(Context, Filename, "other", Checksum, Source)); |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1670 | DIFile::ChecksumInfo<StringRef> OtherChecksum(DIFile::ChecksumKind::CSK_SHA1, ChecksumString); |
Reid Kleckner | 3796a45 | 2017-09-19 18:14:45 +0000 | [diff] [blame] | 1671 | EXPECT_NE( |
Scott Linder | 4863252 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 1672 | N, DIFile::get(Context, Filename, Directory, OtherChecksum)); |
Scott Linder | 5e4b515 | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 1673 | StringRef OtherSource = "other"; |
| 1674 | EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum, OtherSource)); |
| 1675 | EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum)); |
Amjad Aboud | 4e2e80b | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 1676 | EXPECT_NE(N, DIFile::get(Context, Filename, Directory)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1677 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1678 | TempDIFile Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1679 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1682 | TEST_F(DIFileTest, ScopeGetFile) { |
| 1683 | // Ensure that DIScope::getFile() returns itself. |
| 1684 | DIScope *N = DIFile::get(Context, "file", "dir"); |
Duncan P. N. Exon Smith | 5bcf130 | 2015-02-28 21:47:02 +0000 | [diff] [blame] | 1685 | EXPECT_EQ(N, N->getFile()); |
| 1686 | } |
| 1687 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1688 | typedef MetadataTest DICompileUnitTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1689 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1690 | TEST_F(DICompileUnitTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1691 | unsigned SourceLanguage = 1; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1692 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1693 | StringRef Producer = "some producer"; |
| 1694 | bool IsOptimized = false; |
| 1695 | StringRef Flags = "flag after flag"; |
| 1696 | unsigned RuntimeVersion = 2; |
| 1697 | StringRef SplitDebugFilename = "another/file"; |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1698 | auto EmissionKind = DICompileUnit::FullDebug; |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1699 | MDTuple *EnumTypes = getTuple(); |
| 1700 | MDTuple *RetainedTypes = getTuple(); |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1701 | MDTuple *GlobalVariables = getTuple(); |
| 1702 | MDTuple *ImportedEntities = getTuple(); |
Adrian Prantl | 5df8499 | 2015-09-22 23:42:47 +0000 | [diff] [blame] | 1703 | uint64_t DWOId = 0x10000000c0ffee; |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1704 | MDTuple *Macros = getTuple(); |
Duncan P. N. Exon Smith | c61bc48 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1705 | auto *N = DICompileUnit::getDistinct( |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1706 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1707 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
Dehao Chen | fe46230 | 2017-02-01 22:45:09 +0000 | [diff] [blame] | 1708 | RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true, |
David Blaikie | ecc582a | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 1709 | false, DICompileUnit::DebugNameTableKind::Default, false); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1710 | |
| 1711 | EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag()); |
| 1712 | EXPECT_EQ(SourceLanguage, N->getSourceLanguage()); |
| 1713 | EXPECT_EQ(File, N->getFile()); |
| 1714 | EXPECT_EQ(Producer, N->getProducer()); |
| 1715 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
| 1716 | EXPECT_EQ(Flags, N->getFlags()); |
| 1717 | EXPECT_EQ(RuntimeVersion, N->getRuntimeVersion()); |
| 1718 | EXPECT_EQ(SplitDebugFilename, N->getSplitDebugFilename()); |
| 1719 | EXPECT_EQ(EmissionKind, N->getEmissionKind()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1720 | EXPECT_EQ(EnumTypes, N->getEnumTypes().get()); |
| 1721 | EXPECT_EQ(RetainedTypes, N->getRetainedTypes().get()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1722 | EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get()); |
| 1723 | EXPECT_EQ(ImportedEntities, N->getImportedEntities().get()); |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1724 | EXPECT_EQ(Macros, N->getMacros().get()); |
Adrian Prantl | 849c760 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1725 | EXPECT_EQ(DWOId, N->getDWOId()); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1726 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1727 | TempDICompileUnit Temp = N->clone(); |
Duncan P. N. Exon Smith | c61bc48 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1728 | EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag()); |
| 1729 | EXPECT_EQ(SourceLanguage, Temp->getSourceLanguage()); |
| 1730 | EXPECT_EQ(File, Temp->getFile()); |
| 1731 | EXPECT_EQ(Producer, Temp->getProducer()); |
| 1732 | EXPECT_EQ(IsOptimized, Temp->isOptimized()); |
| 1733 | EXPECT_EQ(Flags, Temp->getFlags()); |
| 1734 | EXPECT_EQ(RuntimeVersion, Temp->getRuntimeVersion()); |
| 1735 | EXPECT_EQ(SplitDebugFilename, Temp->getSplitDebugFilename()); |
| 1736 | EXPECT_EQ(EmissionKind, Temp->getEmissionKind()); |
| 1737 | EXPECT_EQ(EnumTypes, Temp->getEnumTypes().get()); |
| 1738 | EXPECT_EQ(RetainedTypes, Temp->getRetainedTypes().get()); |
Duncan P. N. Exon Smith | c61bc48 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1739 | EXPECT_EQ(GlobalVariables, Temp->getGlobalVariables().get()); |
| 1740 | EXPECT_EQ(ImportedEntities, Temp->getImportedEntities().get()); |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1741 | EXPECT_EQ(Macros, Temp->getMacros().get()); |
Duncan P. N. Exon Smith | c61bc48 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1742 | EXPECT_EQ(DWOId, Temp->getDWOId()); |
| 1743 | |
| 1744 | auto *TempAddress = Temp.get(); |
| 1745 | auto *Clone = MDNode::replaceWithPermanent(std::move(Temp)); |
| 1746 | EXPECT_TRUE(Clone->isDistinct()); |
| 1747 | EXPECT_EQ(TempAddress, Clone); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1750 | TEST_F(DICompileUnitTest, replaceArrays) { |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1751 | unsigned SourceLanguage = 1; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1752 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1753 | StringRef Producer = "some producer"; |
| 1754 | bool IsOptimized = false; |
| 1755 | StringRef Flags = "flag after flag"; |
| 1756 | unsigned RuntimeVersion = 2; |
| 1757 | StringRef SplitDebugFilename = "another/file"; |
Adrian Prantl | 39bb84a | 2016-03-31 23:56:58 +0000 | [diff] [blame] | 1758 | auto EmissionKind = DICompileUnit::FullDebug; |
Duncan P. N. Exon Smith | b943370 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 1759 | MDTuple *EnumTypes = MDTuple::getDistinct(Context, None); |
| 1760 | MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None); |
| 1761 | MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None); |
Adrian Prantl | 849c760 | 2015-05-21 20:37:30 +0000 | [diff] [blame] | 1762 | uint64_t DWOId = 0xc0ffee; |
Duncan P. N. Exon Smith | c61bc48 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1763 | auto *N = DICompileUnit::getDistinct( |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1764 | Context, SourceLanguage, File, Producer, IsOptimized, Flags, |
| 1765 | RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes, |
Peter Collingbourne | 76221cb | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 1766 | RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false, |
David Blaikie | ecc582a | 2018-11-13 20:08:10 +0000 | [diff] [blame] | 1767 | DICompileUnit::DebugNameTableKind::Default, false); |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1768 | |
| 1769 | auto *GlobalVariables = MDTuple::getDistinct(Context, None); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1770 | EXPECT_EQ(nullptr, N->getGlobalVariables().get()); |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1771 | N->replaceGlobalVariables(GlobalVariables); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1772 | EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get()); |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1773 | N->replaceGlobalVariables(nullptr); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1774 | EXPECT_EQ(nullptr, N->getGlobalVariables().get()); |
Amjad Aboud | 7db3980 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1775 | |
| 1776 | auto *Macros = MDTuple::getDistinct(Context, None); |
| 1777 | EXPECT_EQ(nullptr, N->getMacros().get()); |
| 1778 | N->replaceMacros(Macros); |
| 1779 | EXPECT_EQ(Macros, N->getMacros().get()); |
| 1780 | N->replaceMacros(nullptr); |
| 1781 | EXPECT_EQ(nullptr, N->getMacros().get()); |
Duncan P. N. Exon Smith | 70ee038 | 2015-02-18 20:36:09 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1784 | typedef MetadataTest DISubprogramTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1785 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1786 | TEST_F(DISubprogramTest, get) { |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1787 | DIScope *Scope = getCompositeType(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1788 | StringRef Name = "name"; |
| 1789 | StringRef LinkageName = "linkage"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1790 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1791 | unsigned Line = 2; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1792 | DISubroutineType *Type = getSubroutineType(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1793 | bool IsLocalToUnit = false; |
| 1794 | bool IsDefinition = true; |
| 1795 | unsigned ScopeLine = 3; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 1796 | DIType *ContainingType = getCompositeType(); |
Davide Italiano | 0149731 | 2016-04-13 20:17:42 +0000 | [diff] [blame] | 1797 | unsigned Virtuality = 2; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1798 | unsigned VirtualIndex = 5; |
Reid Kleckner | bd79db2 | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1799 | int ThisAdjustment = -3; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 1800 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(6); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1801 | bool IsOptimized = false; |
Duncan P. N. Exon Smith | bd38c8d | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 1802 | MDTuple *TemplateParams = getTuple(); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1803 | DISubprogram *Declaration = getSubprogram(); |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1804 | MDTuple *RetainedNodes = getTuple(); |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1805 | MDTuple *ThrownTypes = getTuple(); |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1806 | DICompileUnit *Unit = getUnit(); |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1807 | DISubprogram::DISPFlags SPFlags = |
| 1808 | static_cast<DISubprogram::DISPFlags>(Virtuality); |
| 1809 | assert(!IsLocalToUnit && IsDefinition && !IsOptimized && |
| 1810 | "bools and SPFlags have to match"); |
| 1811 | SPFlags |= DISubprogram::SPFlagDefinition; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1812 | |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1813 | auto *N = DISubprogram::get( |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1814 | Context, Scope, Name, LinkageName, File, Line, Type, ScopeLine, |
| 1815 | ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, |
| 1816 | TemplateParams, Declaration, RetainedNodes, ThrownTypes); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1817 | |
| 1818 | EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag()); |
| 1819 | EXPECT_EQ(Scope, N->getScope()); |
| 1820 | EXPECT_EQ(Name, N->getName()); |
| 1821 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 1822 | EXPECT_EQ(File, N->getFile()); |
| 1823 | EXPECT_EQ(Line, N->getLine()); |
| 1824 | EXPECT_EQ(Type, N->getType()); |
| 1825 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 1826 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
| 1827 | EXPECT_EQ(ScopeLine, N->getScopeLine()); |
| 1828 | EXPECT_EQ(ContainingType, N->getContainingType()); |
| 1829 | EXPECT_EQ(Virtuality, N->getVirtuality()); |
| 1830 | EXPECT_EQ(VirtualIndex, N->getVirtualIndex()); |
Reid Kleckner | bd79db2 | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1831 | EXPECT_EQ(ThisAdjustment, N->getThisAdjustment()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1832 | EXPECT_EQ(Flags, N->getFlags()); |
| 1833 | EXPECT_EQ(IsOptimized, N->isOptimized()); |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1834 | EXPECT_EQ(Unit, N->getUnit()); |
Duncan P. N. Exon Smith | 2e25115 | 2015-04-07 16:50:39 +0000 | [diff] [blame] | 1835 | EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1836 | EXPECT_EQ(Declaration, N->getDeclaration()); |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1837 | EXPECT_EQ(RetainedNodes, N->getRetainedNodes().get()); |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1838 | EXPECT_EQ(ThrownTypes, N->getThrownTypes().get()); |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1839 | EXPECT_EQ(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1840 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1841 | ThisAdjustment, Flags, SPFlags, Unit, |
| 1842 | TemplateParams, Declaration, RetainedNodes, |
| 1843 | ThrownTypes)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1844 | |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1845 | EXPECT_NE(N, DISubprogram::get(Context, getCompositeType(), Name, LinkageName, |
| 1846 | File, Line, Type, ScopeLine, ContainingType, |
| 1847 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1848 | Unit, TemplateParams, Declaration, |
| 1849 | RetainedNodes, ThrownTypes)); |
| 1850 | EXPECT_NE(N, DISubprogram::get(Context, Scope, "other", LinkageName, File, |
| 1851 | Line, Type, ScopeLine, ContainingType, |
| 1852 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1853 | Unit, TemplateParams, Declaration, |
| 1854 | RetainedNodes, ThrownTypes)); |
| 1855 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, "other", File, Line, |
| 1856 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1857 | ThisAdjustment, Flags, SPFlags, Unit, |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1858 | TemplateParams, Declaration, RetainedNodes, |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1859 | ThrownTypes)); |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1860 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, getFile(), |
| 1861 | Line, Type, ScopeLine, ContainingType, |
| 1862 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1863 | Unit, TemplateParams, Declaration, |
| 1864 | RetainedNodes, ThrownTypes)); |
| 1865 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, |
| 1866 | Line + 1, Type, ScopeLine, ContainingType, |
| 1867 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1868 | Unit, TemplateParams, Declaration, |
| 1869 | RetainedNodes, ThrownTypes)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1870 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1871 | getSubroutineType(), ScopeLine, ContainingType, |
| 1872 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1873 | Unit, TemplateParams, Declaration, |
| 1874 | RetainedNodes, ThrownTypes)); |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1875 | EXPECT_NE(N, DISubprogram::get( |
| 1876 | Context, Scope, Name, LinkageName, File, Line, Type, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1877 | ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, |
| 1878 | Flags, SPFlags ^ DISubprogram::SPFlagLocalToUnit, Unit, |
| 1879 | TemplateParams, Declaration, RetainedNodes, ThrownTypes)); |
| 1880 | EXPECT_NE(N, DISubprogram::get( |
| 1881 | Context, Scope, Name, LinkageName, File, Line, Type, |
| 1882 | ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, |
| 1883 | Flags, SPFlags ^ DISubprogram::SPFlagDefinition, Unit, |
| 1884 | TemplateParams, Declaration, RetainedNodes, ThrownTypes)); |
Adrian Prantl | 4eeaa0d | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 1885 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1886 | Type, ScopeLine + 1, ContainingType, |
| 1887 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1888 | Unit, TemplateParams, Declaration, |
| 1889 | RetainedNodes, ThrownTypes)); |
| 1890 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1891 | Type, ScopeLine, getCompositeType(), |
| 1892 | VirtualIndex, ThisAdjustment, Flags, SPFlags, |
| 1893 | Unit, TemplateParams, Declaration, |
| 1894 | RetainedNodes, ThrownTypes)); |
| 1895 | EXPECT_NE(N, DISubprogram::get( |
| 1896 | Context, Scope, Name, LinkageName, File, Line, Type, |
| 1897 | ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, |
| 1898 | Flags, SPFlags ^ DISubprogram::SPFlagVirtual, Unit, |
| 1899 | TemplateParams, Declaration, RetainedNodes, ThrownTypes)); |
| 1900 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1901 | Type, ScopeLine, ContainingType, |
| 1902 | VirtualIndex + 1, ThisAdjustment, Flags, |
| 1903 | SPFlags, Unit, TemplateParams, Declaration, |
| 1904 | RetainedNodes, ThrownTypes)); |
| 1905 | EXPECT_NE(N, DISubprogram::get( |
| 1906 | Context, Scope, Name, LinkageName, File, Line, Type, |
| 1907 | ScopeLine, ContainingType, VirtualIndex, ThisAdjustment, |
| 1908 | Flags, SPFlags ^ DISubprogram::SPFlagOptimized, Unit, |
| 1909 | TemplateParams, Declaration, RetainedNodes, ThrownTypes)); |
| 1910 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1911 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1912 | ThisAdjustment, Flags, SPFlags, nullptr, |
| 1913 | TemplateParams, Declaration, RetainedNodes, |
| 1914 | ThrownTypes)); |
| 1915 | EXPECT_NE(N, |
| 1916 | DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1917 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1918 | ThisAdjustment, Flags, SPFlags, Unit, getTuple(), |
| 1919 | Declaration, RetainedNodes, ThrownTypes)); |
| 1920 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1921 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1922 | ThisAdjustment, Flags, SPFlags, Unit, |
Shiva Chen | a8a13bc | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 1923 | TemplateParams, getSubprogram(), RetainedNodes, |
Adrian Prantl | 1bf6297 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 1924 | ThrownTypes)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1925 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1926 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1927 | ThisAdjustment, Flags, SPFlags, Unit, |
Reid Kleckner | bd79db2 | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 1928 | TemplateParams, Declaration, getTuple())); |
Paul Robinson | eaa7353 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 1929 | EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, |
| 1930 | Type, ScopeLine, ContainingType, VirtualIndex, |
| 1931 | ThisAdjustment, Flags, SPFlags, Unit, |
| 1932 | TemplateParams, Declaration, RetainedNodes, |
| 1933 | getTuple())); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1934 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1935 | TempDISubprogram Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1936 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1939 | typedef MetadataTest DILexicalBlockTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1940 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1941 | TEST_F(DILexicalBlockTest, get) { |
| 1942 | DILocalScope *Scope = getSubprogram(); |
| 1943 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1944 | unsigned Line = 5; |
| 1945 | unsigned Column = 8; |
| 1946 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1947 | auto *N = DILexicalBlock::get(Context, Scope, File, Line, Column); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1948 | |
| 1949 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 1950 | EXPECT_EQ(Scope, N->getScope()); |
| 1951 | EXPECT_EQ(File, N->getFile()); |
| 1952 | EXPECT_EQ(Line, N->getLine()); |
| 1953 | EXPECT_EQ(Column, N->getColumn()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1954 | EXPECT_EQ(N, DILexicalBlock::get(Context, Scope, File, Line, Column)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1955 | |
Duncan P. N. Exon Smith | d3ec0ca | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 1956 | EXPECT_NE(N, |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1957 | DILexicalBlock::get(Context, getSubprogram(), File, Line, Column)); |
| 1958 | EXPECT_NE(N, DILexicalBlock::get(Context, Scope, getFile(), Line, Column)); |
| 1959 | EXPECT_NE(N, DILexicalBlock::get(Context, Scope, File, Line + 1, Column)); |
| 1960 | EXPECT_NE(N, DILexicalBlock::get(Context, Scope, File, Line, Column + 1)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1961 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1962 | TempDILexicalBlock Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 1963 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Duncan P. N. Exon Smith | 091adc7 | 2015-08-28 22:58:50 +0000 | [diff] [blame] | 1966 | TEST_F(DILexicalBlockTest, Overflow) { |
| 1967 | DISubprogram *SP = getSubprogram(); |
| 1968 | DIFile *F = getFile(); |
| 1969 | { |
| 1970 | auto *LB = DILexicalBlock::get(Context, SP, F, 2, 7); |
| 1971 | EXPECT_EQ(2u, LB->getLine()); |
| 1972 | EXPECT_EQ(7u, LB->getColumn()); |
| 1973 | } |
| 1974 | unsigned U16 = 1u << 16; |
| 1975 | { |
| 1976 | auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 - 1); |
| 1977 | EXPECT_EQ(UINT32_MAX, LB->getLine()); |
| 1978 | EXPECT_EQ(U16 - 1, LB->getColumn()); |
| 1979 | } |
| 1980 | { |
| 1981 | auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16); |
| 1982 | EXPECT_EQ(UINT32_MAX, LB->getLine()); |
| 1983 | EXPECT_EQ(0u, LB->getColumn()); |
| 1984 | } |
| 1985 | { |
| 1986 | auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 + 1); |
| 1987 | EXPECT_EQ(UINT32_MAX, LB->getLine()); |
| 1988 | EXPECT_EQ(0u, LB->getColumn()); |
| 1989 | } |
| 1990 | } |
| 1991 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1992 | typedef MetadataTest DILexicalBlockFileTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1993 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1994 | TEST_F(DILexicalBlockFileTest, get) { |
| 1995 | DILocalScope *Scope = getSubprogram(); |
| 1996 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1997 | unsigned Discriminator = 5; |
| 1998 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1999 | auto *N = DILexicalBlockFile::get(Context, Scope, File, Discriminator); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2000 | |
| 2001 | EXPECT_EQ(dwarf::DW_TAG_lexical_block, N->getTag()); |
| 2002 | EXPECT_EQ(Scope, N->getScope()); |
| 2003 | EXPECT_EQ(File, N->getFile()); |
| 2004 | EXPECT_EQ(Discriminator, N->getDiscriminator()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2005 | EXPECT_EQ(N, DILexicalBlockFile::get(Context, Scope, File, Discriminator)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2006 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2007 | EXPECT_NE(N, DILexicalBlockFile::get(Context, getSubprogram(), File, |
Duncan P. N. Exon Smith | d3ec0ca | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 2008 | Discriminator)); |
| 2009 | EXPECT_NE(N, |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2010 | DILexicalBlockFile::get(Context, Scope, getFile(), Discriminator)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2011 | EXPECT_NE(N, |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2012 | DILexicalBlockFile::get(Context, Scope, File, Discriminator + 1)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2013 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2014 | TempDILexicalBlockFile Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2015 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2018 | typedef MetadataTest DINamespaceTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2019 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2020 | TEST_F(DINamespaceTest, get) { |
| 2021 | DIScope *Scope = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2022 | StringRef Name = "namespace"; |
Adrian Prantl | 60a7c43 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 2023 | bool ExportSymbols = true; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2024 | |
Adrian Prantl | 841400b | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 2025 | auto *N = DINamespace::get(Context, Scope, Name, ExportSymbols); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2026 | |
| 2027 | EXPECT_EQ(dwarf::DW_TAG_namespace, N->getTag()); |
| 2028 | EXPECT_EQ(Scope, N->getScope()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2029 | EXPECT_EQ(Name, N->getName()); |
Adrian Prantl | 841400b | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 2030 | EXPECT_EQ(N, DINamespace::get(Context, Scope, Name, ExportSymbols)); |
| 2031 | EXPECT_NE(N, DINamespace::get(Context, getFile(), Name, ExportSymbols)); |
| 2032 | EXPECT_NE(N, DINamespace::get(Context, Scope, "other", ExportSymbols)); |
| 2033 | EXPECT_NE(N, DINamespace::get(Context, Scope, Name, !ExportSymbols)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2034 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2035 | TempDINamespace Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2036 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
Adrian Prantl | 7177647 | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 2039 | typedef MetadataTest DIModuleTest; |
| 2040 | |
| 2041 | TEST_F(DIModuleTest, get) { |
| 2042 | DIScope *Scope = getFile(); |
| 2043 | StringRef Name = "module"; |
| 2044 | StringRef ConfigMacro = "-DNDEBUG"; |
| 2045 | StringRef Includes = "-I."; |
| 2046 | StringRef Sysroot = "/"; |
| 2047 | |
| 2048 | auto *N = DIModule::get(Context, Scope, Name, ConfigMacro, Includes, Sysroot); |
| 2049 | |
| 2050 | EXPECT_EQ(dwarf::DW_TAG_module, N->getTag()); |
| 2051 | EXPECT_EQ(Scope, N->getScope()); |
| 2052 | EXPECT_EQ(Name, N->getName()); |
| 2053 | EXPECT_EQ(ConfigMacro, N->getConfigurationMacros()); |
| 2054 | EXPECT_EQ(Includes, N->getIncludePath()); |
| 2055 | EXPECT_EQ(Sysroot, N->getISysRoot()); |
| 2056 | EXPECT_EQ(N, DIModule::get(Context, Scope, Name, |
| 2057 | ConfigMacro, Includes, Sysroot)); |
| 2058 | EXPECT_NE(N, DIModule::get(Context, getFile(), Name, |
| 2059 | ConfigMacro, Includes, Sysroot)); |
| 2060 | EXPECT_NE(N, DIModule::get(Context, Scope, "other", |
| 2061 | ConfigMacro, Includes, Sysroot)); |
| 2062 | EXPECT_NE(N, DIModule::get(Context, Scope, Name, |
| 2063 | "other", Includes, Sysroot)); |
| 2064 | EXPECT_NE(N, DIModule::get(Context, Scope, Name, |
| 2065 | ConfigMacro, "other", Sysroot)); |
| 2066 | EXPECT_NE(N, DIModule::get(Context, Scope, Name, |
| 2067 | ConfigMacro, Includes, "other")); |
| 2068 | |
| 2069 | TempDIModule Temp = N->clone(); |
| 2070 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
| 2071 | } |
| 2072 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2073 | typedef MetadataTest DITemplateTypeParameterTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2074 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2075 | TEST_F(DITemplateTypeParameterTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2076 | StringRef Name = "template"; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2077 | DIType *Type = getBasicType("basic"); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2078 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2079 | auto *N = DITemplateTypeParameter::get(Context, Name, Type); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2080 | |
| 2081 | EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2082 | EXPECT_EQ(Name, N->getName()); |
| 2083 | EXPECT_EQ(Type, N->getType()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2084 | EXPECT_EQ(N, DITemplateTypeParameter::get(Context, Name, Type)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2085 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2086 | EXPECT_NE(N, DITemplateTypeParameter::get(Context, "other", Type)); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2087 | EXPECT_NE(N, |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2088 | DITemplateTypeParameter::get(Context, Name, getBasicType("other"))); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2089 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2090 | TempDITemplateTypeParameter Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2091 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2094 | typedef MetadataTest DITemplateValueParameterTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2095 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2096 | TEST_F(DITemplateValueParameterTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2097 | unsigned Tag = dwarf::DW_TAG_template_value_parameter; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2098 | StringRef Name = "template"; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2099 | DIType *Type = getBasicType("basic"); |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2100 | Metadata *Value = getConstantAsMetadata(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2101 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2102 | auto *N = DITemplateValueParameter::get(Context, Tag, Name, Type, Value); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2103 | EXPECT_EQ(Tag, N->getTag()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2104 | EXPECT_EQ(Name, N->getName()); |
| 2105 | EXPECT_EQ(Type, N->getType()); |
| 2106 | EXPECT_EQ(Value, N->getValue()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2107 | EXPECT_EQ(N, DITemplateValueParameter::get(Context, Tag, Name, Type, Value)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2108 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2109 | EXPECT_NE(N, DITemplateValueParameter::get( |
Duncan P. N. Exon Smith | eac950e | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 2110 | Context, dwarf::DW_TAG_GNU_template_template_param, Name, |
| 2111 | Type, Value)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2112 | EXPECT_NE(N, |
| 2113 | DITemplateValueParameter::get(Context, Tag, "other", Type, Value)); |
| 2114 | EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name, |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2115 | getBasicType("other"), Value)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2116 | EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name, Type, |
Duncan P. N. Exon Smith | 7380257 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 2117 | getConstantAsMetadata())); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2118 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2119 | TempDITemplateValueParameter Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2120 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2123 | typedef MetadataTest DIGlobalVariableTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2124 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2125 | TEST_F(DIGlobalVariableTest, get) { |
| 2126 | DIScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2127 | StringRef Name = "name"; |
| 2128 | StringRef LinkageName = "linkage"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2129 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2130 | unsigned Line = 5; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2131 | DIType *Type = getDerivedType(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2132 | bool IsLocalToUnit = false; |
| 2133 | bool IsDefinition = true; |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2134 | MDTuple *templateParams = getTuple(); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2135 | DIDerivedType *StaticDataMemberDeclaration = |
| 2136 | cast<DIDerivedType>(getDerivedType()); |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2137 | |
Victor Leschuk | 7614f6d | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2138 | uint32_t AlignInBits = 8; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2139 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2140 | auto *N = DIGlobalVariable::get( |
| 2141 | Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 2142 | IsDefinition, StaticDataMemberDeclaration, templateParams, AlignInBits); |
| 2143 | |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2144 | EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag()); |
| 2145 | EXPECT_EQ(Scope, N->getScope()); |
| 2146 | EXPECT_EQ(Name, N->getName()); |
| 2147 | EXPECT_EQ(LinkageName, N->getLinkageName()); |
| 2148 | EXPECT_EQ(File, N->getFile()); |
| 2149 | EXPECT_EQ(Line, N->getLine()); |
| 2150 | EXPECT_EQ(Type, N->getType()); |
| 2151 | EXPECT_EQ(IsLocalToUnit, N->isLocalToUnit()); |
| 2152 | EXPECT_EQ(IsDefinition, N->isDefinition()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2153 | EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration()); |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2154 | EXPECT_EQ(templateParams, N->getTemplateParams()); |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2155 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2156 | EXPECT_EQ(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2157 | Line, Type, IsLocalToUnit, IsDefinition, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2158 | StaticDataMemberDeclaration, |
| 2159 | templateParams, AlignInBits)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2160 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2161 | EXPECT_NE(N, DIGlobalVariable::get( |
| 2162 | Context, getSubprogram(), Name, LinkageName, File, Line, |
| 2163 | Type, IsLocalToUnit, IsDefinition, |
| 2164 | StaticDataMemberDeclaration, templateParams, AlignInBits)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2165 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, "other", LinkageName, File, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2166 | Line, Type, IsLocalToUnit, IsDefinition, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2167 | StaticDataMemberDeclaration, |
| 2168 | templateParams, AlignInBits)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2169 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, "other", File, Line, |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2170 | Type, IsLocalToUnit, IsDefinition, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2171 | StaticDataMemberDeclaration, |
| 2172 | templateParams, AlignInBits)); |
| 2173 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, |
| 2174 | getFile(), Line, Type, IsLocalToUnit, |
| 2175 | IsDefinition, StaticDataMemberDeclaration, |
| 2176 | templateParams, AlignInBits)); |
| 2177 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 2178 | Line + 1, Type, IsLocalToUnit, |
| 2179 | IsDefinition, StaticDataMemberDeclaration, |
| 2180 | templateParams, AlignInBits)); |
| 2181 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 2182 | Line, getDerivedType(), IsLocalToUnit, |
| 2183 | IsDefinition, StaticDataMemberDeclaration, |
| 2184 | templateParams, AlignInBits)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2185 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2186 | Line, Type, !IsLocalToUnit, IsDefinition, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2187 | StaticDataMemberDeclaration, |
| 2188 | templateParams, AlignInBits)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2189 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2190 | Line, Type, IsLocalToUnit, !IsDefinition, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2191 | StaticDataMemberDeclaration, |
| 2192 | templateParams, AlignInBits)); |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2193 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 2194 | Line, Type, IsLocalToUnit, IsDefinition, |
| 2195 | cast<DIDerivedType>(getDerivedType()), |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2196 | templateParams, AlignInBits)); |
| 2197 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 2198 | Line, Type, IsLocalToUnit, IsDefinition, |
| 2199 | StaticDataMemberDeclaration, nullptr, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2200 | AlignInBits)); |
Peter Collingbourne | 5420de3 | 2016-09-13 01:12:59 +0000 | [diff] [blame] | 2201 | EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, |
| 2202 | Line, Type, IsLocalToUnit, IsDefinition, |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2203 | StaticDataMemberDeclaration, |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2204 | templateParams, (AlignInBits << 1))); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2205 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2206 | TempDIGlobalVariable Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2207 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2210 | typedef MetadataTest DIGlobalVariableExpressionTest; |
| 2211 | |
| 2212 | TEST_F(DIGlobalVariableExpressionTest, get) { |
| 2213 | DIScope *Scope = getSubprogram(); |
| 2214 | StringRef Name = "name"; |
| 2215 | StringRef LinkageName = "linkage"; |
| 2216 | DIFile *File = getFile(); |
| 2217 | unsigned Line = 5; |
| 2218 | DIType *Type = getDerivedType(); |
| 2219 | bool IsLocalToUnit = false; |
| 2220 | bool IsDefinition = true; |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2221 | MDTuple *templateParams = getTuple(); |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2222 | auto *Expr = DIExpression::get(Context, {1, 2}); |
| 2223 | auto *Expr2 = DIExpression::get(Context, {1, 2, 3}); |
| 2224 | DIDerivedType *StaticDataMemberDeclaration = |
| 2225 | cast<DIDerivedType>(getDerivedType()); |
| 2226 | uint32_t AlignInBits = 8; |
| 2227 | |
Matthew Voss | fff44e6 | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 2228 | auto *Var = DIGlobalVariable::get( |
| 2229 | Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, |
| 2230 | IsDefinition, StaticDataMemberDeclaration, templateParams, AlignInBits); |
| 2231 | auto *Var2 = DIGlobalVariable::get( |
| 2232 | Context, Scope, "other", LinkageName, File, Line, Type, IsLocalToUnit, |
| 2233 | IsDefinition, StaticDataMemberDeclaration, templateParams, AlignInBits); |
Adrian Prantl | 7b500b4 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 2234 | auto *N = DIGlobalVariableExpression::get(Context, Var, Expr); |
| 2235 | |
| 2236 | EXPECT_EQ(Var, N->getVariable()); |
| 2237 | EXPECT_EQ(Expr, N->getExpression()); |
| 2238 | EXPECT_EQ(N, DIGlobalVariableExpression::get(Context, Var, Expr)); |
| 2239 | EXPECT_NE(N, DIGlobalVariableExpression::get(Context, Var2, Expr)); |
| 2240 | EXPECT_NE(N, DIGlobalVariableExpression::get(Context, Var, Expr2)); |
| 2241 | |
| 2242 | TempDIGlobalVariableExpression Temp = N->clone(); |
| 2243 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
| 2244 | } |
| 2245 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2246 | typedef MetadataTest DILocalVariableTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2247 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2248 | TEST_F(DILocalVariableTest, get) { |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2249 | DILocalScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2250 | StringRef Name = "name"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2251 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2252 | unsigned Line = 5; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2253 | DIType *Type = getDerivedType(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2254 | unsigned Arg = 6; |
Leny Kholodov | d9478f8 | 2016-09-06 10:46:28 +0000 | [diff] [blame] | 2255 | DINode::DIFlags Flags = static_cast<DINode::DIFlags>(7); |
Victor Leschuk | 7614f6d | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 2256 | uint32_t AlignInBits = 8; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2257 | |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2258 | auto *N = |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2259 | DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, Flags, |
| 2260 | AlignInBits); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2261 | EXPECT_TRUE(N->isParameter()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2262 | EXPECT_EQ(Scope, N->getScope()); |
| 2263 | EXPECT_EQ(Name, N->getName()); |
| 2264 | EXPECT_EQ(File, N->getFile()); |
| 2265 | EXPECT_EQ(Line, N->getLine()); |
| 2266 | EXPECT_EQ(Type, N->getType()); |
| 2267 | EXPECT_EQ(Arg, N->getArg()); |
| 2268 | EXPECT_EQ(Flags, N->getFlags()); |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2269 | EXPECT_EQ(AlignInBits, N->getAlignInBits()); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2270 | EXPECT_EQ(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2271 | Flags, AlignInBits)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2272 | |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2273 | EXPECT_FALSE( |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2274 | DILocalVariable::get(Context, Scope, Name, File, Line, Type, 0, Flags, |
| 2275 | AlignInBits)->isParameter()); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2276 | EXPECT_NE(N, DILocalVariable::get(Context, getSubprogram(), Name, File, Line, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2277 | Type, Arg, Flags, AlignInBits)); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2278 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, "other", File, Line, Type, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2279 | Arg, Flags, AlignInBits)); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2280 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, getFile(), Line, Type, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2281 | Arg, Flags, AlignInBits)); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2282 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line + 1, Type, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2283 | Arg, Flags, AlignInBits)); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2284 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2285 | getDerivedType(), Arg, Flags, AlignInBits)); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2286 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2287 | Arg + 1, Flags, AlignInBits)); |
| 2288 | EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, |
| 2289 | Arg, Flags, (AlignInBits << 1))); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2290 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2291 | TempDILocalVariable Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2292 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2295 | TEST_F(DILocalVariableTest, getArg256) { |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2296 | EXPECT_EQ(255u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2297 | 0, nullptr, 255, DINode::FlagZero, 0) |
Duncan P. N. Exon Smith | fef4836 | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 2298 | ->getArg()); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2299 | EXPECT_EQ(256u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2300 | 0, nullptr, 256, DINode::FlagZero, 0) |
Duncan P. N. Exon Smith | fef4836 | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 2301 | ->getArg()); |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2302 | EXPECT_EQ(257u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2303 | 0, nullptr, 257, DINode::FlagZero, 0) |
Duncan P. N. Exon Smith | fef4836 | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 2304 | ->getArg()); |
| 2305 | unsigned Max = UINT16_MAX; |
Duncan P. N. Exon Smith | bf2040f | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 2306 | EXPECT_EQ(Max, DILocalVariable::get(Context, getSubprogram(), "", getFile(), |
Victor Leschuk | e69c459 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 2307 | 0, nullptr, Max, DINode::FlagZero, 0) |
Duncan P. N. Exon Smith | fef4836 | 2015-04-28 01:07:33 +0000 | [diff] [blame] | 2308 | ->getArg()); |
| 2309 | } |
| 2310 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2311 | typedef MetadataTest DIExpressionTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2312 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2313 | TEST_F(DIExpressionTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2314 | uint64_t Elements[] = {2, 6, 9, 78, 0}; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2315 | auto *N = DIExpression::get(Context, Elements); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2316 | EXPECT_EQ(makeArrayRef(Elements), N->getElements()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2317 | EXPECT_EQ(N, DIExpression::get(Context, Elements)); |
Duncan P. N. Exon Smith | db7dea0 | 2015-02-10 01:36:46 +0000 | [diff] [blame] | 2318 | |
| 2319 | EXPECT_EQ(5u, N->getNumElements()); |
| 2320 | EXPECT_EQ(2u, N->getElement(0)); |
| 2321 | EXPECT_EQ(6u, N->getElement(1)); |
| 2322 | EXPECT_EQ(9u, N->getElement(2)); |
| 2323 | EXPECT_EQ(78u, N->getElement(3)); |
| 2324 | EXPECT_EQ(0u, N->getElement(4)); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2325 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2326 | TempDIExpression Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2327 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Adrian Prantl | 0375b23 | 2017-12-08 21:58:18 +0000 | [diff] [blame] | 2328 | |
| 2329 | // Test DIExpression::prepend(). |
| 2330 | uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32}; |
| 2331 | auto *N0 = DIExpression::get(Context, Elts0); |
Vedant Kumar | 081d211 | 2018-07-26 20:56:53 +0000 | [diff] [blame] | 2332 | auto *N0WithPrependedOps = DIExpression::prepend(N0, true, 64, true, true); |
Adrian Prantl | 0375b23 | 2017-12-08 21:58:18 +0000 | [diff] [blame] | 2333 | uint64_t Elts1[] = {dwarf::DW_OP_deref, |
| 2334 | dwarf::DW_OP_plus_uconst, 64, |
| 2335 | dwarf::DW_OP_deref, |
| 2336 | dwarf::DW_OP_stack_value, |
| 2337 | dwarf::DW_OP_LLVM_fragment, 0, 32}; |
| 2338 | auto *N1 = DIExpression::get(Context, Elts1); |
Vedant Kumar | 081d211 | 2018-07-26 20:56:53 +0000 | [diff] [blame] | 2339 | EXPECT_EQ(N0WithPrependedOps, N1); |
| 2340 | |
| 2341 | // Test DIExpression::append(). |
| 2342 | uint64_t Elts2[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64, |
| 2343 | dwarf::DW_OP_deref, dwarf::DW_OP_stack_value}; |
| 2344 | auto *N2 = DIExpression::append(N0, Elts2); |
| 2345 | EXPECT_EQ(N0WithPrependedOps, N2); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2348 | TEST_F(DIExpressionTest, isValid) { |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2349 | #define EXPECT_VALID(...) \ |
| 2350 | do { \ |
| 2351 | uint64_t Elements[] = {__VA_ARGS__}; \ |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2352 | EXPECT_TRUE(DIExpression::get(Context, Elements)->isValid()); \ |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2353 | } while (false) |
| 2354 | #define EXPECT_INVALID(...) \ |
| 2355 | do { \ |
| 2356 | uint64_t Elements[] = {__VA_ARGS__}; \ |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2357 | EXPECT_FALSE(DIExpression::get(Context, Elements)->isValid()); \ |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2358 | } while (false) |
| 2359 | |
| 2360 | // Empty expression should be valid. |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2361 | EXPECT_TRUE(DIExpression::get(Context, None)); |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2362 | |
| 2363 | // Valid constructions. |
Florian Hahn | 10ccfa6 | 2017-06-13 16:54:44 +0000 | [diff] [blame] | 2364 | EXPECT_VALID(dwarf::DW_OP_plus_uconst, 6); |
Florian Hahn | 50963b3 | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 2365 | EXPECT_VALID(dwarf::DW_OP_constu, 6, dwarf::DW_OP_plus); |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2366 | EXPECT_VALID(dwarf::DW_OP_deref); |
Adrian Prantl | 460dd60 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 2367 | EXPECT_VALID(dwarf::DW_OP_LLVM_fragment, 3, 7); |
Florian Hahn | 50963b3 | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 2368 | EXPECT_VALID(dwarf::DW_OP_plus_uconst, 6, dwarf::DW_OP_deref); |
| 2369 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 6); |
Adrian Prantl | 460dd60 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 2370 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_LLVM_fragment, 3, 7); |
Florian Hahn | 50963b3 | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 2371 | EXPECT_VALID(dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 6, |
Adrian Prantl | 460dd60 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 2372 | dwarf::DW_OP_LLVM_fragment, 3, 7); |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2373 | |
| 2374 | // Invalid constructions. |
| 2375 | EXPECT_INVALID(~0u); |
Florian Hahn | 50963b3 | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 2376 | EXPECT_INVALID(dwarf::DW_OP_plus, 0); |
Florian Hahn | 10ccfa6 | 2017-06-13 16:54:44 +0000 | [diff] [blame] | 2377 | EXPECT_INVALID(dwarf::DW_OP_plus_uconst); |
Adrian Prantl | 460dd60 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 2378 | EXPECT_INVALID(dwarf::DW_OP_LLVM_fragment); |
| 2379 | EXPECT_INVALID(dwarf::DW_OP_LLVM_fragment, 3); |
Florian Hahn | 50963b3 | 2017-06-14 13:14:38 +0000 | [diff] [blame] | 2380 | EXPECT_INVALID(dwarf::DW_OP_LLVM_fragment, 3, 7, dwarf::DW_OP_plus_uconst, 3); |
Adrian Prantl | 460dd60 | 2016-12-05 18:04:47 +0000 | [diff] [blame] | 2381 | EXPECT_INVALID(dwarf::DW_OP_LLVM_fragment, 3, 7, dwarf::DW_OP_deref); |
Duncan P. N. Exon Smith | 7473485 | 2015-02-13 01:07:46 +0000 | [diff] [blame] | 2382 | |
| 2383 | #undef EXPECT_VALID |
| 2384 | #undef EXPECT_INVALID |
| 2385 | } |
| 2386 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2387 | typedef MetadataTest DIObjCPropertyTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2388 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2389 | TEST_F(DIObjCPropertyTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2390 | StringRef Name = "name"; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2391 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2392 | unsigned Line = 5; |
| 2393 | StringRef GetterName = "getter"; |
| 2394 | StringRef SetterName = "setter"; |
| 2395 | unsigned Attributes = 7; |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2396 | DIType *Type = getBasicType("basic"); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2397 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2398 | auto *N = DIObjCProperty::get(Context, Name, File, Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2399 | SetterName, Attributes, Type); |
| 2400 | |
| 2401 | EXPECT_EQ(dwarf::DW_TAG_APPLE_property, N->getTag()); |
| 2402 | EXPECT_EQ(Name, N->getName()); |
| 2403 | EXPECT_EQ(File, N->getFile()); |
| 2404 | EXPECT_EQ(Line, N->getLine()); |
| 2405 | EXPECT_EQ(GetterName, N->getGetterName()); |
| 2406 | EXPECT_EQ(SetterName, N->getSetterName()); |
| 2407 | EXPECT_EQ(Attributes, N->getAttributes()); |
| 2408 | EXPECT_EQ(Type, N->getType()); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2409 | EXPECT_EQ(N, DIObjCProperty::get(Context, Name, File, Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2410 | SetterName, Attributes, Type)); |
| 2411 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2412 | EXPECT_NE(N, DIObjCProperty::get(Context, "other", File, Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2413 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2414 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, getFile(), Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2415 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2416 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line + 1, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2417 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2418 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line, "other", |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2419 | SetterName, Attributes, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2420 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2421 | "other", Attributes, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2422 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line, GetterName, |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2423 | SetterName, Attributes + 1, Type)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2424 | EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line, GetterName, |
Duncan P. N. Exon Smith | e009b6f | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 2425 | SetterName, Attributes, |
Adrian Prantl | 0f80e47 | 2015-06-15 23:18:03 +0000 | [diff] [blame] | 2426 | getBasicType("other"))); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2427 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2428 | TempDIObjCProperty Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2429 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2432 | typedef MetadataTest DIImportedEntityTest; |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2433 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2434 | TEST_F(DIImportedEntityTest, get) { |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2435 | unsigned Tag = dwarf::DW_TAG_imported_module; |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2436 | DIScope *Scope = getSubprogram(); |
Duncan P. N. Exon Smith | de74840 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 2437 | DINode *Entity = getCompositeType(); |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2438 | DIFile *File = getFile(); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2439 | unsigned Line = 5; |
| 2440 | StringRef Name = "name"; |
| 2441 | |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2442 | auto *N = |
| 2443 | DIImportedEntity::get(Context, Tag, Scope, Entity, File, Line, Name); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2444 | |
| 2445 | EXPECT_EQ(Tag, N->getTag()); |
| 2446 | EXPECT_EQ(Scope, N->getScope()); |
| 2447 | EXPECT_EQ(Entity, N->getEntity()); |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2448 | EXPECT_EQ(File, N->getFile()); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2449 | EXPECT_EQ(Line, N->getLine()); |
| 2450 | EXPECT_EQ(Name, N->getName()); |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2451 | EXPECT_EQ( |
| 2452 | N, DIImportedEntity::get(Context, Tag, Scope, Entity, File, Line, Name)); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2453 | |
| 2454 | EXPECT_NE(N, |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2455 | DIImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration, |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2456 | Scope, Entity, File, Line, Name)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2457 | EXPECT_NE(N, DIImportedEntity::get(Context, Tag, getSubprogram(), Entity, |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2458 | File, Line, Name)); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2459 | EXPECT_NE(N, DIImportedEntity::get(Context, Tag, Scope, getCompositeType(), |
Adrian Prantl | 9563b5a | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 2460 | File, Line, Name)); |
| 2461 | EXPECT_NE(N, DIImportedEntity::get(Context, Tag, Scope, Entity, nullptr, Line, |
| 2462 | Name)); |
| 2463 | EXPECT_NE(N, DIImportedEntity::get(Context, Tag, Scope, Entity, File, |
| 2464 | Line + 1, Name)); |
| 2465 | EXPECT_NE(N, DIImportedEntity::get(Context, Tag, Scope, Entity, File, Line, |
| 2466 | "other")); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2467 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2468 | TempDIImportedEntity Temp = N->clone(); |
Duncan P. N. Exon Smith | 15aa8ba | 2015-02-17 23:10:13 +0000 | [diff] [blame] | 2469 | EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); |
Duncan P. N. Exon Smith | 14fcfef | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2472 | typedef MetadataTest MetadataAsValueTest; |
| 2473 | |
| 2474 | TEST_F(MetadataAsValueTest, MDNode) { |
| 2475 | MDNode *N = MDNode::get(Context, None); |
| 2476 | auto *V = MetadataAsValue::get(Context, N); |
| 2477 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2478 | EXPECT_EQ(N, V->getMetadata()); |
| 2479 | |
| 2480 | auto *V2 = MetadataAsValue::get(Context, N); |
| 2481 | EXPECT_EQ(V, V2); |
| 2482 | } |
| 2483 | |
| 2484 | TEST_F(MetadataAsValueTest, MDNodeMDNode) { |
| 2485 | MDNode *N = MDNode::get(Context, None); |
| 2486 | Metadata *Ops[] = {N}; |
| 2487 | MDNode *N2 = MDNode::get(Context, Ops); |
| 2488 | auto *V = MetadataAsValue::get(Context, N2); |
| 2489 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2490 | EXPECT_EQ(N2, V->getMetadata()); |
| 2491 | |
| 2492 | auto *V2 = MetadataAsValue::get(Context, N2); |
| 2493 | EXPECT_EQ(V, V2); |
| 2494 | |
| 2495 | auto *V3 = MetadataAsValue::get(Context, N); |
| 2496 | EXPECT_TRUE(V3->getType()->isMetadataTy()); |
| 2497 | EXPECT_NE(V, V3); |
| 2498 | EXPECT_EQ(N, V3->getMetadata()); |
| 2499 | } |
| 2500 | |
| 2501 | TEST_F(MetadataAsValueTest, MDNodeConstant) { |
| 2502 | auto *C = ConstantInt::getTrue(Context); |
| 2503 | auto *MD = ConstantAsMetadata::get(C); |
| 2504 | Metadata *Ops[] = {MD}; |
| 2505 | auto *N = MDNode::get(Context, Ops); |
| 2506 | |
| 2507 | auto *V = MetadataAsValue::get(Context, MD); |
| 2508 | EXPECT_TRUE(V->getType()->isMetadataTy()); |
| 2509 | EXPECT_EQ(MD, V->getMetadata()); |
| 2510 | |
| 2511 | auto *V2 = MetadataAsValue::get(Context, N); |
| 2512 | EXPECT_EQ(MD, V2->getMetadata()); |
| 2513 | EXPECT_EQ(V, V2); |
| 2514 | } |
| 2515 | |
Duncan P. N. Exon Smith | 85cbe57 | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 2516 | typedef MetadataTest ValueAsMetadataTest; |
| 2517 | |
| 2518 | TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) { |
| 2519 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2520 | std::unique_ptr<GlobalVariable> GV0( |
| 2521 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2522 | auto *MD = ValueAsMetadata::get(GV0.get()); |
| 2523 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 2524 | ASSERT_TRUE(GV0->use_empty()); |
| 2525 | |
| 2526 | std::unique_ptr<GlobalVariable> GV1( |
| 2527 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2528 | GV0->replaceAllUsesWith(GV1.get()); |
| 2529 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 2530 | } |
| 2531 | |
Adrian Prantl | c44fb84 | 2016-02-08 17:02:34 +0000 | [diff] [blame] | 2532 | TEST_F(ValueAsMetadataTest, TempTempReplacement) { |
| 2533 | // Create a constant. |
Mehdi Amini | 8be7707 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 2534 | ConstantAsMetadata *CI = |
| 2535 | ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0))); |
Adrian Prantl | c44fb84 | 2016-02-08 17:02:34 +0000 | [diff] [blame] | 2536 | |
Adrian Prantl | c44fb84 | 2016-02-08 17:02:34 +0000 | [diff] [blame] | 2537 | auto Temp1 = MDTuple::getTemporary(Context, None); |
Adrian Prantl | 4ebe058 | 2016-02-08 19:13:15 +0000 | [diff] [blame] | 2538 | auto Temp2 = MDTuple::getTemporary(Context, {CI}); |
| 2539 | auto *N = MDTuple::get(Context, {Temp1.get()}); |
Adrian Prantl | c44fb84 | 2016-02-08 17:02:34 +0000 | [diff] [blame] | 2540 | |
| 2541 | // Test replacing a temporary node with another temporary node. |
| 2542 | Temp1->replaceAllUsesWith(Temp2.get()); |
| 2543 | EXPECT_EQ(N->getOperand(0), Temp2.get()); |
| 2544 | |
| 2545 | // Clean up Temp2 for teardown. |
| 2546 | Temp2->replaceAllUsesWith(nullptr); |
| 2547 | } |
| 2548 | |
Duncan P. N. Exon Smith | 9e4a11f | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2549 | TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) { |
| 2550 | // Create a constant. |
Mehdi Amini | 8be7707 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 2551 | ConstantAsMetadata *CI = |
| 2552 | ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0))); |
Duncan P. N. Exon Smith | 9e4a11f | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2553 | |
| 2554 | // Create a temporary to prevent nodes from resolving. |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2555 | auto Temp = MDTuple::getTemporary(Context, None); |
Duncan P. N. Exon Smith | 9e4a11f | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2556 | |
| 2557 | // When the first operand of N1 gets reset to nullptr, it'll collide with N2. |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2558 | Metadata *Ops1[] = {CI, CI, Temp.get()}; |
| 2559 | Metadata *Ops2[] = {nullptr, CI, Temp.get()}; |
Duncan P. N. Exon Smith | 9e4a11f | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2560 | |
| 2561 | auto *N1 = MDTuple::get(Context, Ops1); |
| 2562 | auto *N2 = MDTuple::get(Context, Ops2); |
| 2563 | ASSERT_NE(N1, N2); |
| 2564 | |
| 2565 | // Tell metadata that the constant is getting deleted. |
| 2566 | // |
| 2567 | // After this, N1 will be invalid, so don't touch it. |
| 2568 | ValueAsMetadata::handleDeletion(CI->getValue()); |
| 2569 | EXPECT_EQ(nullptr, N2->getOperand(0)); |
| 2570 | EXPECT_EQ(nullptr, N2->getOperand(1)); |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 2571 | EXPECT_EQ(Temp.get(), N2->getOperand(2)); |
Duncan P. N. Exon Smith | 9e4a11f | 2015-01-14 19:56:10 +0000 | [diff] [blame] | 2572 | |
| 2573 | // Clean up Temp for teardown. |
| 2574 | Temp->replaceAllUsesWith(nullptr); |
| 2575 | } |
| 2576 | |
Duncan P. N. Exon Smith | 85cbe57 | 2014-12-12 19:24:33 +0000 | [diff] [blame] | 2577 | typedef MetadataTest TrackingMDRefTest; |
| 2578 | |
| 2579 | TEST_F(TrackingMDRefTest, UpdatesOnRAUW) { |
| 2580 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2581 | std::unique_ptr<GlobalVariable> GV0( |
| 2582 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2583 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV0.get())); |
| 2584 | EXPECT_TRUE(MD->getValue() == GV0.get()); |
| 2585 | ASSERT_TRUE(GV0->use_empty()); |
| 2586 | |
| 2587 | std::unique_ptr<GlobalVariable> GV1( |
| 2588 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2589 | GV0->replaceAllUsesWith(GV1.get()); |
| 2590 | EXPECT_TRUE(MD->getValue() == GV1.get()); |
| 2591 | |
| 2592 | // Reset it, so we don't inadvertently test deletion. |
| 2593 | MD.reset(); |
| 2594 | } |
| 2595 | |
| 2596 | TEST_F(TrackingMDRefTest, UpdatesOnDeletion) { |
| 2597 | Type *Ty = Type::getInt1PtrTy(Context); |
| 2598 | std::unique_ptr<GlobalVariable> GV( |
| 2599 | new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage)); |
| 2600 | TypedTrackingMDRef<ValueAsMetadata> MD(ValueAsMetadata::get(GV.get())); |
| 2601 | EXPECT_TRUE(MD->getValue() == GV.get()); |
| 2602 | ASSERT_TRUE(GV->use_empty()); |
| 2603 | |
| 2604 | GV.reset(); |
| 2605 | EXPECT_TRUE(!MD); |
| 2606 | } |
| 2607 | |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2608 | TEST(NamedMDNodeTest, Search) { |
Jeffrey Yasskin | e5790a4 | 2010-03-04 23:24:19 +0000 | [diff] [blame] | 2609 | LLVMContext Context; |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2610 | ConstantAsMetadata *C = |
| 2611 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 1)); |
| 2612 | ConstantAsMetadata *C2 = |
| 2613 | ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), 2)); |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2614 | |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 2615 | Metadata *const V = C; |
| 2616 | Metadata *const V2 = C2; |
Jay Foad | ec9186bc | 2011-04-21 19:59:31 +0000 | [diff] [blame] | 2617 | MDNode *n = MDNode::get(Context, V); |
| 2618 | MDNode *n2 = MDNode::get(Context, V2); |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2619 | |
Jeffrey Yasskin | 9d0b3dd | 2010-03-13 01:39:20 +0000 | [diff] [blame] | 2620 | Module M("MyModule", Context); |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2621 | const char *Name = "llvm.NMD1"; |
Dan Gohman | 17aa92c | 2010-07-21 23:38:33 +0000 | [diff] [blame] | 2622 | NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name); |
| 2623 | NMD->addOperand(n); |
| 2624 | NMD->addOperand(n2); |
| 2625 | |
Chris Lattner | 0c47a41 | 2009-08-23 04:47:35 +0000 | [diff] [blame] | 2626 | std::string Str; |
| 2627 | raw_string_ostream oss(Str); |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2628 | NMD->print(oss); |
Chris Lattner | ab2f2f1 | 2009-12-31 02:12:13 +0000 | [diff] [blame] | 2629 | EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n", |
Devang Patel | fa7c4dc | 2009-07-30 00:03:41 +0000 | [diff] [blame] | 2630 | oss.str().c_str()); |
| 2631 | } |
Duncan P. N. Exon Smith | eb79bb6 | 2015-04-24 21:51:02 +0000 | [diff] [blame] | 2632 | |
| 2633 | typedef MetadataTest FunctionAttachmentTest; |
| 2634 | TEST_F(FunctionAttachmentTest, setMetadata) { |
| 2635 | Function *F = getFunction("foo"); |
| 2636 | ASSERT_FALSE(F->hasMetadata()); |
| 2637 | EXPECT_EQ(nullptr, F->getMetadata(LLVMContext::MD_dbg)); |
| 2638 | EXPECT_EQ(nullptr, F->getMetadata("dbg")); |
| 2639 | EXPECT_EQ(nullptr, F->getMetadata("other")); |
| 2640 | |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2641 | DISubprogram *SP1 = getSubprogram(); |
| 2642 | DISubprogram *SP2 = getSubprogram(); |
Duncan P. N. Exon Smith | eb79bb6 | 2015-04-24 21:51:02 +0000 | [diff] [blame] | 2643 | ASSERT_NE(SP1, SP2); |
| 2644 | |
| 2645 | F->setMetadata("dbg", SP1); |
| 2646 | EXPECT_TRUE(F->hasMetadata()); |
| 2647 | EXPECT_EQ(SP1, F->getMetadata(LLVMContext::MD_dbg)); |
| 2648 | EXPECT_EQ(SP1, F->getMetadata("dbg")); |
| 2649 | EXPECT_EQ(nullptr, F->getMetadata("other")); |
| 2650 | |
| 2651 | F->setMetadata(LLVMContext::MD_dbg, SP2); |
| 2652 | EXPECT_TRUE(F->hasMetadata()); |
| 2653 | EXPECT_EQ(SP2, F->getMetadata(LLVMContext::MD_dbg)); |
| 2654 | EXPECT_EQ(SP2, F->getMetadata("dbg")); |
| 2655 | EXPECT_EQ(nullptr, F->getMetadata("other")); |
| 2656 | |
| 2657 | F->setMetadata("dbg", nullptr); |
| 2658 | EXPECT_FALSE(F->hasMetadata()); |
| 2659 | EXPECT_EQ(nullptr, F->getMetadata(LLVMContext::MD_dbg)); |
| 2660 | EXPECT_EQ(nullptr, F->getMetadata("dbg")); |
| 2661 | EXPECT_EQ(nullptr, F->getMetadata("other")); |
| 2662 | |
| 2663 | MDTuple *T1 = getTuple(); |
| 2664 | MDTuple *T2 = getTuple(); |
| 2665 | ASSERT_NE(T1, T2); |
| 2666 | |
| 2667 | F->setMetadata("other1", T1); |
| 2668 | F->setMetadata("other2", T2); |
| 2669 | EXPECT_TRUE(F->hasMetadata()); |
| 2670 | EXPECT_EQ(T1, F->getMetadata("other1")); |
| 2671 | EXPECT_EQ(T2, F->getMetadata("other2")); |
| 2672 | EXPECT_EQ(nullptr, F->getMetadata("dbg")); |
| 2673 | |
| 2674 | F->setMetadata("other1", T2); |
| 2675 | F->setMetadata("other2", T1); |
| 2676 | EXPECT_EQ(T2, F->getMetadata("other1")); |
| 2677 | EXPECT_EQ(T1, F->getMetadata("other2")); |
| 2678 | |
| 2679 | F->setMetadata("other1", nullptr); |
| 2680 | F->setMetadata("other2", nullptr); |
| 2681 | EXPECT_FALSE(F->hasMetadata()); |
| 2682 | EXPECT_EQ(nullptr, F->getMetadata("other1")); |
| 2683 | EXPECT_EQ(nullptr, F->getMetadata("other2")); |
| 2684 | } |
| 2685 | |
| 2686 | TEST_F(FunctionAttachmentTest, getAll) { |
| 2687 | Function *F = getFunction("foo"); |
| 2688 | |
| 2689 | MDTuple *T1 = getTuple(); |
| 2690 | MDTuple *T2 = getTuple(); |
| 2691 | MDTuple *P = getTuple(); |
Duncan P. N. Exon Smith | e56023a | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 2692 | DISubprogram *SP = getSubprogram(); |
Duncan P. N. Exon Smith | eb79bb6 | 2015-04-24 21:51:02 +0000 | [diff] [blame] | 2693 | |
| 2694 | F->setMetadata("other1", T2); |
| 2695 | F->setMetadata(LLVMContext::MD_dbg, SP); |
| 2696 | F->setMetadata("other2", T1); |
| 2697 | F->setMetadata(LLVMContext::MD_prof, P); |
| 2698 | F->setMetadata("other2", T2); |
| 2699 | F->setMetadata("other1", T1); |
| 2700 | |
| 2701 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
| 2702 | F->getAllMetadata(MDs); |
| 2703 | ASSERT_EQ(4u, MDs.size()); |
| 2704 | EXPECT_EQ(LLVMContext::MD_dbg, MDs[0].first); |
| 2705 | EXPECT_EQ(LLVMContext::MD_prof, MDs[1].first); |
| 2706 | EXPECT_EQ(Context.getMDKindID("other1"), MDs[2].first); |
| 2707 | EXPECT_EQ(Context.getMDKindID("other2"), MDs[3].first); |
| 2708 | EXPECT_EQ(SP, MDs[0].second); |
| 2709 | EXPECT_EQ(P, MDs[1].second); |
| 2710 | EXPECT_EQ(T1, MDs[2].second); |
| 2711 | EXPECT_EQ(T2, MDs[3].second); |
| 2712 | } |
| 2713 | |
Duncan P. N. Exon Smith | ef477f3 | 2015-04-24 21:53:27 +0000 | [diff] [blame] | 2714 | TEST_F(FunctionAttachmentTest, Verifier) { |
| 2715 | Function *F = getFunction("foo"); |
| 2716 | F->setMetadata("attach", getTuple()); |
Peter Collingbourne | 052c9ee | 2016-06-06 23:21:27 +0000 | [diff] [blame] | 2717 | F->setIsMaterializable(true); |
Peter Collingbourne | 052c9ee | 2016-06-06 23:21:27 +0000 | [diff] [blame] | 2718 | |
Peter Collingbourne | 99e2e27 | 2016-06-21 23:42:48 +0000 | [diff] [blame] | 2719 | // Confirm this is materializable. |
| 2720 | ASSERT_TRUE(F->isMaterializable()); |
| 2721 | |
| 2722 | // Materializable functions cannot have metadata attachments. |
| 2723 | EXPECT_TRUE(verifyFunction(*F)); |
| 2724 | |
| 2725 | // Function declarations can. |
Peter Collingbourne | 052c9ee | 2016-06-06 23:21:27 +0000 | [diff] [blame] | 2726 | F->setIsMaterializable(false); |
Peter Collingbourne | 99e2e27 | 2016-06-21 23:42:48 +0000 | [diff] [blame] | 2727 | EXPECT_FALSE(verifyModule(*F->getParent())); |
| 2728 | EXPECT_FALSE(verifyFunction(*F)); |
| 2729 | |
| 2730 | // So can definitions. |
Duncan P. N. Exon Smith | ef477f3 | 2015-04-24 21:53:27 +0000 | [diff] [blame] | 2731 | (void)new UnreachableInst(Context, BasicBlock::Create(Context, "bb", F)); |
| 2732 | EXPECT_FALSE(verifyModule(*F->getParent())); |
| 2733 | EXPECT_FALSE(verifyFunction(*F)); |
| 2734 | } |
| 2735 | |
Diego Novillo | a3bccce | 2015-05-13 15:13:45 +0000 | [diff] [blame] | 2736 | TEST_F(FunctionAttachmentTest, EntryCount) { |
| 2737 | Function *F = getFunction("foo"); |
| 2738 | EXPECT_FALSE(F->getEntryCount().hasValue()); |
Easwaran Raman | fd33515 | 2018-01-17 22:24:23 +0000 | [diff] [blame] | 2739 | F->setEntryCount(12304, Function::PCT_Real); |
| 2740 | auto Count = F->getEntryCount(); |
| 2741 | EXPECT_TRUE(Count.hasValue()); |
| 2742 | EXPECT_EQ(12304u, Count.getCount()); |
| 2743 | EXPECT_EQ(Function::PCT_Real, Count.getType()); |
| 2744 | |
| 2745 | // Repeat the same for synthetic counts. |
| 2746 | F = getFunction("bar"); |
| 2747 | EXPECT_FALSE(F->getEntryCount().hasValue()); |
| 2748 | F->setEntryCount(123, Function::PCT_Synthetic); |
| 2749 | Count = F->getEntryCount(); |
| 2750 | EXPECT_TRUE(Count.hasValue()); |
| 2751 | EXPECT_EQ(123u, Count.getCount()); |
| 2752 | EXPECT_EQ(Function::PCT_Synthetic, Count.getType()); |
Diego Novillo | a3bccce | 2015-05-13 15:13:45 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Duncan P. N. Exon Smith | 819d0a5 | 2015-08-28 21:55:35 +0000 | [diff] [blame] | 2755 | TEST_F(FunctionAttachmentTest, SubprogramAttachment) { |
| 2756 | Function *F = getFunction("foo"); |
| 2757 | DISubprogram *SP = getSubprogram(); |
| 2758 | F->setSubprogram(SP); |
| 2759 | |
| 2760 | // Note that the static_cast confirms that F->getSubprogram() actually |
| 2761 | // returns an DISubprogram. |
| 2762 | EXPECT_EQ(SP, static_cast<DISubprogram *>(F->getSubprogram())); |
| 2763 | EXPECT_EQ(SP, F->getMetadata("dbg")); |
| 2764 | EXPECT_EQ(SP, F->getMetadata(LLVMContext::MD_dbg)); |
| 2765 | } |
| 2766 | |
Duncan P. N. Exon Smith | 20c4466 | 2016-04-23 04:15:56 +0000 | [diff] [blame] | 2767 | typedef MetadataTest DistinctMDOperandPlaceholderTest; |
| 2768 | TEST_F(DistinctMDOperandPlaceholderTest, getID) { |
| 2769 | EXPECT_EQ(7u, DistinctMDOperandPlaceholder(7).getID()); |
| 2770 | } |
| 2771 | |
| 2772 | TEST_F(DistinctMDOperandPlaceholderTest, replaceUseWith) { |
| 2773 | // Set up some placeholders. |
| 2774 | DistinctMDOperandPlaceholder PH0(7); |
| 2775 | DistinctMDOperandPlaceholder PH1(3); |
| 2776 | DistinctMDOperandPlaceholder PH2(0); |
| 2777 | Metadata *Ops[] = {&PH0, &PH1, &PH2}; |
| 2778 | auto *D = MDTuple::getDistinct(Context, Ops); |
| 2779 | ASSERT_EQ(&PH0, D->getOperand(0)); |
| 2780 | ASSERT_EQ(&PH1, D->getOperand(1)); |
| 2781 | ASSERT_EQ(&PH2, D->getOperand(2)); |
| 2782 | |
| 2783 | // Replace them. |
| 2784 | auto *N0 = MDTuple::get(Context, None); |
| 2785 | auto *N1 = MDTuple::get(Context, N0); |
| 2786 | PH0.replaceUseWith(N0); |
| 2787 | PH1.replaceUseWith(N1); |
| 2788 | PH2.replaceUseWith(nullptr); |
| 2789 | EXPECT_EQ(N0, D->getOperand(0)); |
| 2790 | EXPECT_EQ(N1, D->getOperand(1)); |
| 2791 | EXPECT_EQ(nullptr, D->getOperand(2)); |
| 2792 | } |
| 2793 | |
| 2794 | TEST_F(DistinctMDOperandPlaceholderTest, replaceUseWithNoUser) { |
| 2795 | // There is no user, but we can still call replace. |
| 2796 | DistinctMDOperandPlaceholder(7).replaceUseWith(MDTuple::get(Context, None)); |
| 2797 | } |
| 2798 | |
Reid Kleckner | f9841d4 | 2017-08-10 21:14:07 +0000 | [diff] [blame] | 2799 | // Test various assertions in metadata tracking. Don't run these tests if gtest |
| 2800 | // will use SEH to recover from them. Two of these tests get halfway through |
| 2801 | // inserting metadata into DenseMaps for tracking purposes, and then they |
| 2802 | // assert, and we attempt to destroy an LLVMContext with broken invariants, |
| 2803 | // leading to infinite loops. |
| 2804 | #if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG) && !defined(GTEST_HAS_SEH) |
Duncan P. N. Exon Smith | 20c4466 | 2016-04-23 04:15:56 +0000 | [diff] [blame] | 2805 | TEST_F(DistinctMDOperandPlaceholderTest, MetadataAsValue) { |
| 2806 | // This shouldn't crash. |
| 2807 | DistinctMDOperandPlaceholder PH(7); |
| 2808 | EXPECT_DEATH(MetadataAsValue::get(Context, &PH), |
| 2809 | "Unexpected callback to owner"); |
| 2810 | } |
| 2811 | |
| 2812 | TEST_F(DistinctMDOperandPlaceholderTest, UniquedMDNode) { |
| 2813 | // This shouldn't crash. |
| 2814 | DistinctMDOperandPlaceholder PH(7); |
| 2815 | EXPECT_DEATH(MDTuple::get(Context, &PH), "Unexpected callback to owner"); |
| 2816 | } |
| 2817 | |
| 2818 | TEST_F(DistinctMDOperandPlaceholderTest, SecondDistinctMDNode) { |
| 2819 | // This shouldn't crash. |
| 2820 | DistinctMDOperandPlaceholder PH(7); |
| 2821 | MDTuple::getDistinct(Context, &PH); |
| 2822 | EXPECT_DEATH(MDTuple::getDistinct(Context, &PH), |
| 2823 | "Placeholders can only be used once"); |
| 2824 | } |
| 2825 | |
| 2826 | TEST_F(DistinctMDOperandPlaceholderTest, TrackingMDRefAndDistinctMDNode) { |
| 2827 | // TrackingMDRef doesn't install an owner callback, so it can't be detected |
| 2828 | // as an invalid use. However, using a placeholder in a TrackingMDRef *and* |
| 2829 | // a distinct node isn't possible and we should assert. |
| 2830 | // |
| 2831 | // (There's no positive test for using TrackingMDRef because it's not a |
| 2832 | // useful thing to do.) |
| 2833 | { |
| 2834 | DistinctMDOperandPlaceholder PH(7); |
| 2835 | MDTuple::getDistinct(Context, &PH); |
| 2836 | EXPECT_DEATH(TrackingMDRef Ref(&PH), "Placeholders can only be used once"); |
| 2837 | } |
| 2838 | { |
| 2839 | DistinctMDOperandPlaceholder PH(7); |
| 2840 | TrackingMDRef Ref(&PH); |
| 2841 | EXPECT_DEATH(MDTuple::getDistinct(Context, &PH), |
| 2842 | "Placeholders can only be used once"); |
| 2843 | } |
| 2844 | } |
| 2845 | #endif |
| 2846 | |
Duncan P. N. Exon Smith | bb8cd12 | 2016-04-23 04:02:39 +0000 | [diff] [blame] | 2847 | } // end namespace |