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