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