120
|
1 //===- llvm/unittest/CodeGen/DIEHashTest.cpp ------------------------------===//
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 #include "../lib/CodeGen/AsmPrinter/DIEHash.h"
|
83
|
11 #include "llvm/ADT/STLExtras.h"
|
121
|
12 #include "llvm/BinaryFormat/Dwarf.h"
|
|
13 #include "llvm/CodeGen/DIE.h"
|
95
|
14 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
|
77
|
15 #include "llvm/Support/Debug.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 #include "llvm/Support/Format.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #include "gtest/gtest.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 namespace {
|
95
|
22
|
|
23 // Test fixture
|
|
24 class DIEHashTest : public testing::Test {
|
|
25 public:
|
|
26 BumpPtrAllocator Alloc;
|
|
27
|
|
28 private:
|
|
29 StringMap<DwarfStringPoolEntry> Pool;
|
|
30
|
|
31 public:
|
|
32 DIEString getString(StringRef S) {
|
|
33 DwarfStringPoolEntry Entry = {nullptr, 1, 1};
|
|
34 return DIEString(
|
|
35 DwarfStringPoolEntryRef(*Pool.insert(std::make_pair(S, Entry)).first));
|
|
36 }
|
|
37 };
|
|
38
|
|
39 TEST_F(DIEHashTest, Data1) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 DIEHash Hash;
|
95
|
41 DIE &Die = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 DIEInteger Size(4);
|
95
|
43 Die.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 uint64_t MD5Res = Hash.computeTypeSignature(Die);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 // struct {};
|
95
|
49 TEST_F(DIEHashTest, TrivialType) {
|
|
50 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 DIEInteger One(1);
|
95
|
52 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 // Line and file number are ignored.
|
95
|
55 Unnamed.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
56 Unnamed.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 // The exact same hash GCC produces for this DIE.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 // struct foo { };
|
95
|
64 TEST_F(DIEHashTest, NamedType) {
|
|
65 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 DIEInteger One(1);
|
95
|
67 DIEString FooStr = getString("foo");
|
|
68 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
69 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 // The exact same hash GCC produces for this DIE.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 // namespace space { struct foo { }; }
|
95
|
78 TEST_F(DIEHashTest, NamespacedType) {
|
|
79 DIE &CU = *DIE::get(Alloc, dwarf::DW_TAG_compile_unit);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80
|
95
|
81 auto Space = DIE::get(Alloc, dwarf::DW_TAG_namespace);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 DIEInteger One(1);
|
95
|
83 DIEString SpaceStr = getString("space");
|
|
84 Space->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, SpaceStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 // DW_AT_declaration is ignored.
|
95
|
86 Space->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
87 One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 // sibling?
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89
|
95
|
90 auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
91 DIEString FooStr = getString("foo");
|
|
92 Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
93 Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94
|
77
|
95 DIE &N = *Foo;
|
|
96 Space->addChild(std::move(Foo));
|
|
97 CU.addChild(std::move(Space));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98
|
77
|
99 uint64_t MD5Res = DIEHash().computeTypeSignature(N);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 // The exact same hash GCC produces for this DIE.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 // struct { int member; };
|
95
|
106 TEST_F(DIEHashTest, TypeWithMember) {
|
|
107 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 DIEInteger Four(4);
|
95
|
109 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110
|
95
|
111 DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
|
112 DIEString IntStr = getString("int");
|
|
113 Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
|
|
114 Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 DIEInteger Five(5);
|
95
|
116 Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117
|
77
|
118 DIEEntry IntRef(Int);
|
|
119
|
95
|
120 auto Member = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
121 DIEString MemberStr = getString("member");
|
|
122 Member->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemberStr);
|
77
|
123 DIEInteger Zero(0);
|
95
|
124 Member->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
125 dwarf::DW_FORM_data1, Zero);
|
|
126 Member->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127
|
77
|
128 Unnamed.addChild(std::move(Member));
|
|
129
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 // struct foo { int mem1, mem2; };
|
95
|
136 TEST_F(DIEHashTest, ReusedType) {
|
|
137 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 DIEInteger Eight(8);
|
95
|
139 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 DIEInteger Four(4);
|
95
|
142 DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
|
143 DIEString IntStr = getString("int");
|
|
144 Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
|
|
145 Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 DIEInteger Five(5);
|
95
|
147 Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148
|
77
|
149 DIEEntry IntRef(Int);
|
|
150
|
95
|
151 auto Mem1 = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
152 DIEString Mem1Str = getString("mem1");
|
|
153 Mem1->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem1Str);
|
77
|
154 DIEInteger Zero(0);
|
95
|
155 Mem1->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
156 Zero);
|
|
157 Mem1->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
77
|
158
|
|
159 Unnamed.addChild(std::move(Mem1));
|
|
160
|
95
|
161 auto Mem2 = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
162 DIEString Mem2Str = getString("mem2");
|
|
163 Mem2->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem2Str);
|
|
164 Mem2->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
165 Four);
|
|
166 Mem2->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167
|
77
|
168 Unnamed.addChild(std::move(Mem2));
|
|
169
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 // struct foo { static foo f; };
|
95
|
176 TEST_F(DIEHashTest, RecursiveType) {
|
|
177 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 DIEInteger One(1);
|
95
|
179 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
180 DIEString FooStr = getString("foo");
|
|
181 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182
|
95
|
183 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
184 DIEString MemStr = getString("mem");
|
|
185 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
77
|
186 DIEEntry FooRef(Foo);
|
95
|
187 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189
|
77
|
190 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 // struct foo { foo *mem; };
|
95
|
198 TEST_F(DIEHashTest, Pointer) {
|
|
199 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 DIEInteger Eight(8);
|
95
|
201 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
202 DIEString FooStr = getString("foo");
|
|
203 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204
|
95
|
205 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
206 DIEString MemStr = getString("mem");
|
|
207 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 DIEInteger Zero(0);
|
95
|
209 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
210 Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211
|
95
|
212 DIE &FooPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type);
|
|
213 FooPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
77
|
214 DIEEntry FooRef(Foo);
|
95
|
215 FooPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216
|
77
|
217 DIEEntry FooPtrRef(FooPtr);
|
95
|
218 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooPtrRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219
|
77
|
220 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 // struct foo { foo &mem; };
|
95
|
228 TEST_F(DIEHashTest, Reference) {
|
|
229 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 DIEInteger Eight(8);
|
95
|
231 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
232 DIEString FooStr = getString("foo");
|
|
233 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234
|
95
|
235 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
236 DIEString MemStr = getString("mem");
|
|
237 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 DIEInteger Zero(0);
|
95
|
239 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
240 Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241
|
95
|
242 DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_reference_type);
|
|
243 FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
77
|
244 DIEEntry FooEntry(Foo);
|
95
|
245 FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246
|
95
|
247 DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
77
|
248 DIEEntry FooRefRef(FooRef);
|
95
|
249 FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
250 FooRefRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251
|
77
|
252 DIEEntry FooRefConstRef(FooRefConst);
|
95
|
253 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254
|
77
|
255 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 // struct foo { foo &&mem; };
|
95
|
263 TEST_F(DIEHashTest, RValueReference) {
|
|
264 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 DIEInteger Eight(8);
|
95
|
266 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
267 DIEString FooStr = getString("foo");
|
|
268 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269
|
95
|
270 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
271 DIEString MemStr = getString("mem");
|
|
272 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 DIEInteger Zero(0);
|
95
|
274 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
275 Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276
|
95
|
277 DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_rvalue_reference_type);
|
|
278 FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
77
|
279 DIEEntry FooEntry(Foo);
|
95
|
280 FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281
|
95
|
282 DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
77
|
283 DIEEntry FooRefRef(FooRef);
|
95
|
284 FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
285 FooRefRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286
|
77
|
287 DIEEntry FooRefConstRef(FooRefConst);
|
95
|
288 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289
|
77
|
290 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 // struct foo { foo foo::*mem; };
|
95
|
298 TEST_F(DIEHashTest, PtrToMember) {
|
|
299 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300 DIEInteger Eight(8);
|
95
|
301 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
302 DIEString FooStr = getString("foo");
|
|
303 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304
|
95
|
305 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
306 DIEString MemStr = getString("mem");
|
|
307 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 DIEInteger Zero(0);
|
95
|
309 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
310 Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
311
|
95
|
312 DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
77
|
313 DIEEntry FooEntry(Foo);
|
95
|
314 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
|
315 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
316 FooEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
317
|
77
|
318 DIEEntry PtrToFooMemRef(PtrToFooMem);
|
95
|
319 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320
|
77
|
321 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
322
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
324
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
325 ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
326 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
327
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328 // Check that the hash for a pointer-to-member matches regardless of whether the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
329 // pointed-to type is a declaration or a definition.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
330 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 // struct bar; // { };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
332 // struct foo { bar foo::*mem; };
|
95
|
333 TEST_F(DIEHashTest, PtrToMemberDeclDefMatch) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
334 DIEInteger Zero(0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
335 DIEInteger One(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
336 DIEInteger Eight(8);
|
95
|
337 DIEString FooStr = getString("foo");
|
|
338 DIEString BarStr = getString("bar");
|
|
339 DIEString MemStr = getString("mem");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
340 uint64_t MD5ResDecl;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
341 {
|
95
|
342 DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
343 Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
344 Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
345 One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
346
|
95
|
347 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
348 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
349 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
350
|
95
|
351 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
352 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
353 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
354 dwarf::DW_FORM_data1, Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
355
|
95
|
356 DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
77
|
357 DIEEntry BarEntry(Bar);
|
95
|
358 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
359 BarEntry);
|
77
|
360 DIEEntry FooEntry(Foo);
|
95
|
361 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
362 dwarf::DW_FORM_ref4, FooEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
363
|
77
|
364 DIEEntry PtrToFooMemRef(PtrToFooMem);
|
95
|
365 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
366 PtrToFooMemRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
367
|
77
|
368 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
369
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
370 MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
371 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
372 uint64_t MD5ResDef;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 {
|
95
|
374 DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
375 Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
376 Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377
|
95
|
378 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
379 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
380 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
381
|
95
|
382 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
383 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
384 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
385 dwarf::DW_FORM_data1, Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
386
|
95
|
387 DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
77
|
388 DIEEntry BarEntry(Bar);
|
95
|
389 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
390 BarEntry);
|
77
|
391 DIEEntry FooEntry(Foo);
|
95
|
392 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
393 dwarf::DW_FORM_ref4, FooEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394
|
77
|
395 DIEEntry PtrToFooMemRef(PtrToFooMem);
|
95
|
396 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
397 PtrToFooMemRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
398
|
77
|
399 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 ASSERT_EQ(MD5ResDef, MD5ResDecl);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 // Check that the hash for a pointer-to-member matches regardless of whether the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 // pointed-to type is a declaration or a definition.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 // struct bar; // { };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410 // struct foo { bar bar::*mem; };
|
95
|
411 TEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
412 DIEInteger Zero(0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
413 DIEInteger One(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414 DIEInteger Eight(8);
|
95
|
415 DIEString FooStr = getString("foo");
|
|
416 DIEString BarStr = getString("bar");
|
|
417 DIEString MemStr = getString("mem");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418 uint64_t MD5ResDecl;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 {
|
95
|
420 DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
421 Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
422 Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
423 One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424
|
95
|
425 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
426 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
427 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428
|
95
|
429 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
430 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
431 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
432 dwarf::DW_FORM_data1, Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433
|
95
|
434 DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
77
|
435 DIEEntry BarEntry(Bar);
|
95
|
436 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
437 BarEntry);
|
|
438 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
439 dwarf::DW_FORM_ref4, BarEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440
|
77
|
441 DIEEntry PtrToFooMemRef(PtrToFooMem);
|
95
|
442 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
443 PtrToFooMemRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444
|
77
|
445 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
447 MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
448 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 uint64_t MD5ResDef;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450 {
|
95
|
451 DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
452 Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
453 Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454
|
95
|
455 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
456 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
457 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458
|
95
|
459 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
460 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
461 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
462 dwarf::DW_FORM_data1, Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
463
|
95
|
464 DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
77
|
465 DIEEntry BarEntry(Bar);
|
95
|
466 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
467 BarEntry);
|
|
468 PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
469 dwarf::DW_FORM_ref4, BarEntry);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
470
|
77
|
471 DIEEntry PtrToFooMemRef(PtrToFooMem);
|
95
|
472 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
473 PtrToFooMemRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
474
|
77
|
475 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
476
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
477 MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
478 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
479 // FIXME: This seems to be a bug in the DWARF type hashing specification that
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
480 // only uses the brief name hashing for types referenced via DW_AT_type. In
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
481 // this case the type is referenced via DW_AT_containing_type and full hashing
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
482 // causes a hash to differ when the containing type is a declaration in one TU
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483 // and a definition in another.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484 ASSERT_NE(MD5ResDef, MD5ResDecl);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
487 // struct { } a;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488 // struct foo { decltype(a) mem; };
|
95
|
489 TEST_F(DIEHashTest, RefUnnamedType) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
490 DIEInteger Zero(0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
491 DIEInteger One(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
492 DIEInteger Eight(8);
|
95
|
493 DIEString FooStr = getString("foo");
|
|
494 DIEString MemStr = getString("mem");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495
|
95
|
496 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
497 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
498
|
|
499 DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
500 Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
501 Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502
|
95
|
503 auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
504 Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
505 Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
506 Zero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
507
|
95
|
508 DIE &UnnamedPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type);
|
|
509 UnnamedPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
|
|
510 Eight);
|
77
|
511 DIEEntry UnnamedRef(Unnamed);
|
95
|
512 UnnamedPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
513 UnnamedRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514
|
77
|
515 DIEEntry UnnamedPtrRef(UnnamedPtr);
|
95
|
516 Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedPtrRef);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517
|
77
|
518 Foo.addChild(std::move(Mem));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 ASSERT_EQ(0x954e026f01c02529ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524
|
77
|
525 // struct { struct foo { }; };
|
95
|
526 TEST_F(DIEHashTest, NestedType) {
|
|
527 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528 DIEInteger One(1);
|
95
|
529 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
530
|
95
|
531 auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
|
532 DIEString FooStr = getString("foo");
|
|
533 Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
534 Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535
|
77
|
536 Unnamed.addChild(std::move(Foo));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
538 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
540 // The exact same hash GCC produces for this DIE.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 // struct { static void func(); };
|
95
|
545 TEST_F(DIEHashTest, MemberFunc) {
|
|
546 DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547 DIEInteger One(1);
|
95
|
548 Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549
|
95
|
550 auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram);
|
|
551 DIEString FuncStr = getString("func");
|
|
552 Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553
|
77
|
554 Unnamed.addChild(std::move(Func));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 // The exact same hash GCC produces for this DIE.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
559 ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
560 }
|
77
|
561
|
|
562 // struct A {
|
|
563 // static void func();
|
|
564 // };
|
95
|
565 TEST_F(DIEHashTest, MemberFuncFlag) {
|
|
566 DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
77
|
567 DIEInteger One(1);
|
95
|
568 DIEString AStr = getString("A");
|
|
569 A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
570 A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
571 A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
572 A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
77
|
573
|
95
|
574 auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram);
|
|
575 DIEString FuncStr = getString("func");
|
|
576 DIEString FuncLinkage = getString("_ZN1A4funcEv");
|
77
|
577 DIEInteger Two(2);
|
95
|
578 Func->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present,
|
|
579 One);
|
|
580 Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
|
|
581 Func->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
582 Func->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
583 Func->addValue(Alloc, dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp,
|
|
584 FuncLinkage);
|
|
585 Func->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
586 One);
|
77
|
587
|
|
588 A.addChild(std::move(Func));
|
|
589
|
|
590 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
591
|
|
592 // The exact same hash GCC produces for this DIE.
|
|
593 ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
594 }
|
77
|
595
|
|
596 // Derived from:
|
|
597 // struct A {
|
|
598 // const static int PI = -3;
|
|
599 // };
|
|
600 // A a;
|
95
|
601 TEST_F(DIEHashTest, MemberSdata) {
|
|
602 DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
77
|
603 DIEInteger One(1);
|
95
|
604 DIEString AStr = getString("A");
|
|
605 A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
606 A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
607 A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
608 A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
77
|
609
|
|
610 DIEInteger Four(4);
|
|
611 DIEInteger Five(5);
|
95
|
612 DIEString FStr = getString("int");
|
|
613 DIE &IntTyDIE = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
|
614 IntTyDIE.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
|
615 IntTyDIE.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
|
616 IntTyDIE.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
77
|
617
|
|
618 DIEEntry IntTy(IntTyDIE);
|
95
|
619 auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
|
620 PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntTy);
|
77
|
621
|
|
622 DIEEntry PITy(*PITyDIE);
|
95
|
623 auto PI = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
624 DIEString PIStr = getString("PI");
|
77
|
625 DIEInteger Two(2);
|
|
626 DIEInteger NegThree(-3);
|
95
|
627 PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
|
|
628 PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
629 PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
630 PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
631 PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
632 PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
633 One);
|
|
634 PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, NegThree);
|
77
|
635
|
|
636 A.addChild(std::move(PI));
|
|
637
|
|
638 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
639 ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
|
|
640 }
|
|
641
|
|
642 // Derived from:
|
|
643 // struct A {
|
|
644 // const static float PI = 3.14;
|
|
645 // };
|
|
646 // A a;
|
95
|
647 TEST_F(DIEHashTest, MemberBlock) {
|
|
648 DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
77
|
649 DIEInteger One(1);
|
95
|
650 DIEString AStr = getString("A");
|
|
651 A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
652 A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
653 A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
654 A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
77
|
655
|
|
656 DIEInteger Four(4);
|
95
|
657 DIEString FStr = getString("float");
|
|
658 auto FloatTyDIE = DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
|
659 FloatTyDIE->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
|
|
660 Four);
|
|
661 FloatTyDIE->addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
|
662 Four);
|
|
663 FloatTyDIE->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
77
|
664 DIEEntry FloatTy(*FloatTyDIE);
|
95
|
665 auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
|
666 PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FloatTy);
|
77
|
667
|
|
668 DIEEntry PITy(*PITyDIE);
|
95
|
669 auto PI = DIE::get(Alloc, dwarf::DW_TAG_member);
|
|
670 DIEString PIStr = getString("PI");
|
77
|
671 DIEInteger Two(2);
|
95
|
672 PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
|
|
673 PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
674 PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
675 PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
676 PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
677 PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
678 One);
|
77
|
679
|
|
680 DIEBlock PIBlock;
|
|
681 DIEInteger Blk1(0xc3);
|
|
682 DIEInteger Blk2(0xf5);
|
|
683 DIEInteger Blk3(0x48);
|
|
684 DIEInteger Blk4(0x40);
|
|
685
|
95
|
686 PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk1);
|
|
687 PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk2);
|
|
688 PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk3);
|
|
689 PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk4);
|
77
|
690
|
95
|
691 PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_block1,
|
|
692 &PIBlock);
|
77
|
693
|
|
694 A.addChild(std::move(PI));
|
|
695
|
|
696 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
697 ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
|
|
698 }
|
|
699 }
|