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