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