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