blob: 8e78f0ca13b5411225e94fb9569da129a29a004c [file] [log] [blame]
Eric Christopher25b7adc2013-09-03 21:57:57 +00001//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Frederic Risse541e0b2015-01-05 21:29:41 +000010#include "llvm/CodeGen/DIE.h"
Eric Christopher25b7adc2013-09-03 21:57:57 +000011#include "../lib/CodeGen/AsmPrinter/DIEHash.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000012#include "llvm/ADT/STLExtras.h"
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000013#include "llvm/CodeGen/DwarfStringPoolEntry.h"
Eric Christopher25b7adc2013-09-03 21:57:57 +000014#include "llvm/Support/Debug.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000015#include "llvm/Support/Dwarf.h"
Eric Christopher25b7adc2013-09-03 21:57:57 +000016#include "llvm/Support/Format.h"
17#include "gtest/gtest.h"
18
Eric Christopher25b7adc2013-09-03 21:57:57 +000019using namespace llvm;
David Blaikie59804192013-10-15 23:00:17 +000020
21namespace {
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000022
23// Test fixture
24class DIEHashTest : public testing::Test {
25 StringMap<DwarfStringPoolEntry> Pool;
26
27public:
28 DIEString getString(StringRef S) {
29 DwarfStringPoolEntry Entry = {nullptr, 1, 1};
30 return DIEString(
31 DwarfStringPoolEntryRef(*Pool.insert(std::make_pair(S, Entry)).first));
32 }
33};
34
35TEST_F(DIEHashTest, Data1) {
Eric Christopher25b7adc2013-09-03 21:57:57 +000036 DIEHash Hash;
Benjamin Kramer0f01d4e2013-09-29 11:29:20 +000037 DIE Die(dwarf::DW_TAG_base_type);
38 DIEInteger Size(4);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000039 Die.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size);
David Blaikie2aee7be2013-10-24 18:29:03 +000040 uint64_t MD5Res = Hash.computeTypeSignature(Die);
David Blaikie6316ca42013-10-16 23:36:20 +000041 ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
42}
43
David Blaikie6cf58c82013-10-21 22:36:50 +000044// struct {};
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000045TEST_F(DIEHashTest, TrivialType) {
David Blaikie8a142aa2013-10-17 00:10:34 +000046 DIE Unnamed(dwarf::DW_TAG_structure_type);
David Blaikie6316ca42013-10-16 23:36:20 +000047 DIEInteger One(1);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000048 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie6316ca42013-10-16 23:36:20 +000049
50 // Line and file number are ignored.
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000051 Unnamed.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
52 Unnamed.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
David Blaikie2aee7be2013-10-24 18:29:03 +000053 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
David Blaikie6316ca42013-10-16 23:36:20 +000054
55 // The exact same hash GCC produces for this DIE.
56 ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
Eric Christopher25b7adc2013-09-03 21:57:57 +000057}
David Blaikie8a142aa2013-10-17 00:10:34 +000058
David Blaikie6cf58c82013-10-21 22:36:50 +000059// struct foo { };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000060TEST_F(DIEHashTest, NamedType) {
David Blaikie8a142aa2013-10-17 00:10:34 +000061 DIE Foo(dwarf::DW_TAG_structure_type);
62 DIEInteger One(1);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000063 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000064 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
65 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie8a142aa2013-10-17 00:10:34 +000066
David Blaikie2aee7be2013-10-24 18:29:03 +000067 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikie8a142aa2013-10-17 00:10:34 +000068
69 // The exact same hash GCC produces for this DIE.
70 ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
71}
72
David Blaikie6cf58c82013-10-21 22:36:50 +000073// namespace space { struct foo { }; }
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000074TEST_F(DIEHashTest, NamespacedType) {
David Blaikie8a142aa2013-10-17 00:10:34 +000075 DIE CU(dwarf::DW_TAG_compile_unit);
76
David Blaikie914046e2014-04-25 20:00:34 +000077 auto Space = make_unique<DIE>(dwarf::DW_TAG_namespace);
David Blaikie8a142aa2013-10-17 00:10:34 +000078 DIEInteger One(1);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000079 DIEString SpaceStr = getString("space");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000080 Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, SpaceStr);
David Blaikie8a142aa2013-10-17 00:10:34 +000081 // DW_AT_declaration is ignored.
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000082 Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
David Blaikie8a142aa2013-10-17 00:10:34 +000083 // sibling?
84
David Blaikie914046e2014-04-25 20:00:34 +000085 auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +000086 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +000087 Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
88 Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie8a142aa2013-10-17 00:10:34 +000089
David Blaikie914046e2014-04-25 20:00:34 +000090 DIE &N = *Foo;
91 Space->addChild(std::move(Foo));
92 CU.addChild(std::move(Space));
David Blaikie8a142aa2013-10-17 00:10:34 +000093
David Blaikie914046e2014-04-25 20:00:34 +000094 uint64_t MD5Res = DIEHash().computeTypeSignature(N);
David Blaikie8a142aa2013-10-17 00:10:34 +000095
96 // The exact same hash GCC produces for this DIE.
97 ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
98}
David Blaikieca353be2013-10-17 22:07:09 +000099
David Blaikie6cf58c82013-10-21 22:36:50 +0000100// struct { int member; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000101TEST_F(DIEHashTest, TypeWithMember) {
David Blaikieca353be2013-10-17 22:07:09 +0000102 DIE Unnamed(dwarf::DW_TAG_structure_type);
103 DIEInteger Four(4);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000104 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
David Blaikieca353be2013-10-17 22:07:09 +0000105
David Blaikieca353be2013-10-17 22:07:09 +0000106 DIE Int(dwarf::DW_TAG_base_type);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000107 DIEString IntStr = getString("int");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000108 Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
109 Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
David Blaikieca353be2013-10-17 22:07:09 +0000110 DIEInteger Five(5);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000111 Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
David Blaikieca353be2013-10-17 22:07:09 +0000112
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000113 DIEEntry IntRef(Int);
David Blaikie914046e2014-04-25 20:00:34 +0000114
115 auto Member = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000116 DIEString MemberStr = getString("member");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000117 Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemberStr);
David Blaikie914046e2014-04-25 20:00:34 +0000118 DIEInteger Zero(0);
119 Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000120 Zero);
121 Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
David Blaikieca353be2013-10-17 22:07:09 +0000122
David Blaikie914046e2014-04-25 20:00:34 +0000123 Unnamed.addChild(std::move(Member));
124
David Blaikie2aee7be2013-10-24 18:29:03 +0000125 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
David Blaikieca353be2013-10-17 22:07:09 +0000126
127 ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
128}
David Blaikie980d4992013-10-21 18:59:40 +0000129
David Blaikie6cf58c82013-10-21 22:36:50 +0000130// struct foo { int mem1, mem2; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000131TEST_F(DIEHashTest, ReusedType) {
David Blaikie980d4992013-10-21 18:59:40 +0000132 DIE Unnamed(dwarf::DW_TAG_structure_type);
133 DIEInteger Eight(8);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000134 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
David Blaikie980d4992013-10-21 18:59:40 +0000135
David Blaikie980d4992013-10-21 18:59:40 +0000136 DIEInteger Four(4);
David Blaikie980d4992013-10-21 18:59:40 +0000137 DIE Int(dwarf::DW_TAG_base_type);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000138 DIEString IntStr = getString("int");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000139 Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
140 Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
David Blaikie980d4992013-10-21 18:59:40 +0000141 DIEInteger Five(5);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000142 Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
David Blaikie980d4992013-10-21 18:59:40 +0000143
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000144 DIEEntry IntRef(Int);
David Blaikie914046e2014-04-25 20:00:34 +0000145
146 auto Mem1 = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000147 DIEString Mem1Str = getString("mem1");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000148 Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem1Str);
David Blaikie914046e2014-04-25 20:00:34 +0000149 DIEInteger Zero(0);
150 Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000151 Zero);
152 Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
David Blaikie914046e2014-04-25 20:00:34 +0000153
154 Unnamed.addChild(std::move(Mem1));
155
156 auto Mem2 = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000157 DIEString Mem2Str = getString("mem2");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000158 Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem2Str);
David Blaikie914046e2014-04-25 20:00:34 +0000159 Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000160 Four);
161 Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
David Blaikie980d4992013-10-21 18:59:40 +0000162
David Blaikie914046e2014-04-25 20:00:34 +0000163 Unnamed.addChild(std::move(Mem2));
164
David Blaikie2aee7be2013-10-24 18:29:03 +0000165 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
David Blaikie980d4992013-10-21 18:59:40 +0000166
167 ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
168}
169
David Blaikie6cf58c82013-10-21 22:36:50 +0000170// struct foo { static foo f; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000171TEST_F(DIEHashTest, RecursiveType) {
David Blaikie980d4992013-10-21 18:59:40 +0000172 DIE Foo(dwarf::DW_TAG_structure_type);
173 DIEInteger One(1);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000174 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000175 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000176 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikie980d4992013-10-21 18:59:40 +0000177
David Blaikie914046e2014-04-25 20:00:34 +0000178 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000179 DIEString MemStr = getString("mem");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000180 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000181 DIEEntry FooRef(Foo);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000182 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
David Blaikie980d4992013-10-21 18:59:40 +0000183 // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
184
David Blaikie914046e2014-04-25 20:00:34 +0000185 Foo.addChild(std::move(Mem));
David Blaikie980d4992013-10-21 18:59:40 +0000186
David Blaikie2aee7be2013-10-24 18:29:03 +0000187 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikie980d4992013-10-21 18:59:40 +0000188
189 ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
190}
David Blaikie6cf58c82013-10-21 22:36:50 +0000191
192// struct foo { foo *mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000193TEST_F(DIEHashTest, Pointer) {
David Blaikie6cf58c82013-10-21 22:36:50 +0000194 DIE Foo(dwarf::DW_TAG_structure_type);
195 DIEInteger Eight(8);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000196 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000197 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000198 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikie6cf58c82013-10-21 22:36:50 +0000199
David Blaikie914046e2014-04-25 20:00:34 +0000200 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000201 DIEString MemStr = getString("mem");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000202 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikie6cf58c82013-10-21 22:36:50 +0000203 DIEInteger Zero(0);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000204 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
David Blaikie6cf58c82013-10-21 22:36:50 +0000205
206 DIE FooPtr(dwarf::DW_TAG_pointer_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000207 FooPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000208 DIEEntry FooRef(Foo);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000209 FooPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
David Blaikie6cf58c82013-10-21 22:36:50 +0000210
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000211 DIEEntry FooPtrRef(FooPtr);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000212 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooPtrRef);
David Blaikie6cf58c82013-10-21 22:36:50 +0000213
David Blaikie914046e2014-04-25 20:00:34 +0000214 Foo.addChild(std::move(Mem));
David Blaikie6cf58c82013-10-21 22:36:50 +0000215
David Blaikie2aee7be2013-10-24 18:29:03 +0000216 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikie6cf58c82013-10-21 22:36:50 +0000217
218 ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
219}
David Blaikiefe3233a2013-10-21 23:06:19 +0000220
221// struct foo { foo &mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000222TEST_F(DIEHashTest, Reference) {
David Blaikiefe3233a2013-10-21 23:06:19 +0000223 DIE Foo(dwarf::DW_TAG_structure_type);
224 DIEInteger Eight(8);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000225 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000226 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000227 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikiefe3233a2013-10-21 23:06:19 +0000228
David Blaikie914046e2014-04-25 20:00:34 +0000229 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000230 DIEString MemStr = getString("mem");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000231 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikiefe3233a2013-10-21 23:06:19 +0000232 DIEInteger Zero(0);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000233 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
David Blaikiefe3233a2013-10-21 23:06:19 +0000234
235 DIE FooRef(dwarf::DW_TAG_reference_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000236 FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000237 DIEEntry FooEntry(Foo);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000238 FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
David Blaikiefe3233a2013-10-21 23:06:19 +0000239
240 DIE FooRefConst(dwarf::DW_TAG_const_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000241 DIEEntry FooRefRef(FooRef);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000242 FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefRef);
David Blaikiefe3233a2013-10-21 23:06:19 +0000243
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000244 DIEEntry FooRefConstRef(FooRefConst);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000245 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
David Blaikiefe3233a2013-10-21 23:06:19 +0000246
David Blaikie914046e2014-04-25 20:00:34 +0000247 Foo.addChild(std::move(Mem));
David Blaikiefe3233a2013-10-21 23:06:19 +0000248
David Blaikie2aee7be2013-10-24 18:29:03 +0000249 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikiefe3233a2013-10-21 23:06:19 +0000250
251 ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res);
252}
253
254// struct foo { foo &&mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000255TEST_F(DIEHashTest, RValueReference) {
David Blaikiefe3233a2013-10-21 23:06:19 +0000256 DIE Foo(dwarf::DW_TAG_structure_type);
257 DIEInteger Eight(8);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000258 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000259 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000260 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikiefe3233a2013-10-21 23:06:19 +0000261
David Blaikie914046e2014-04-25 20:00:34 +0000262 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000263 DIEString MemStr = getString("mem");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000264 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikiefe3233a2013-10-21 23:06:19 +0000265 DIEInteger Zero(0);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000266 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
David Blaikiefe3233a2013-10-21 23:06:19 +0000267
268 DIE FooRef(dwarf::DW_TAG_rvalue_reference_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000269 FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000270 DIEEntry FooEntry(Foo);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000271 FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
David Blaikiefe3233a2013-10-21 23:06:19 +0000272
273 DIE FooRefConst(dwarf::DW_TAG_const_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000274 DIEEntry FooRefRef(FooRef);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000275 FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefRef);
David Blaikiefe3233a2013-10-21 23:06:19 +0000276
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000277 DIEEntry FooRefConstRef(FooRefConst);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000278 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
David Blaikiefe3233a2013-10-21 23:06:19 +0000279
David Blaikie914046e2014-04-25 20:00:34 +0000280 Foo.addChild(std::move(Mem));
David Blaikiefe3233a2013-10-21 23:06:19 +0000281
David Blaikie2aee7be2013-10-24 18:29:03 +0000282 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikiefe3233a2013-10-21 23:06:19 +0000283
284 ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
285}
David Blaikied70a0552013-10-22 18:14:41 +0000286
287// struct foo { foo foo::*mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000288TEST_F(DIEHashTest, PtrToMember) {
David Blaikied70a0552013-10-22 18:14:41 +0000289 DIE Foo(dwarf::DW_TAG_structure_type);
290 DIEInteger Eight(8);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000291 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000292 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000293 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikied70a0552013-10-22 18:14:41 +0000294
David Blaikie914046e2014-04-25 20:00:34 +0000295 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000296 DIEString MemStr = getString("mem");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000297 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikied70a0552013-10-22 18:14:41 +0000298 DIEInteger Zero(0);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000299 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
David Blaikied70a0552013-10-22 18:14:41 +0000300
301 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000302 DIEEntry FooEntry(Foo);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000303 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
Eric Christopherda1d7d92014-02-20 00:54:38 +0000304 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000305 FooEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000306
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000307 DIEEntry PtrToFooMemRef(PtrToFooMem);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000308 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
David Blaikied70a0552013-10-22 18:14:41 +0000309
David Blaikie914046e2014-04-25 20:00:34 +0000310 Foo.addChild(std::move(Mem));
David Blaikied70a0552013-10-22 18:14:41 +0000311
David Blaikie2aee7be2013-10-24 18:29:03 +0000312 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000313
314 ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res);
315}
316
317// Check that the hash for a pointer-to-member matches regardless of whether the
318// pointed-to type is a declaration or a definition.
319//
320// struct bar; // { };
321// struct foo { bar foo::*mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000322TEST_F(DIEHashTest, PtrToMemberDeclDefMatch) {
David Blaikied70a0552013-10-22 18:14:41 +0000323 DIEInteger Zero(0);
324 DIEInteger One(1);
325 DIEInteger Eight(8);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000326 DIEString FooStr = getString("foo");
327 DIEString BarStr = getString("bar");
328 DIEString MemStr = getString("mem");
David Blaikied70a0552013-10-22 18:14:41 +0000329 uint64_t MD5ResDecl;
330 {
331 DIE Bar(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000332 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
333 Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
David Blaikied70a0552013-10-22 18:14:41 +0000334
335 DIE Foo(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000336 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
337 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikied70a0552013-10-22 18:14:41 +0000338
David Blaikie914046e2014-04-25 20:00:34 +0000339 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000340 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikied70a0552013-10-22 18:14:41 +0000341 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000342 Zero);
David Blaikied70a0552013-10-22 18:14:41 +0000343
344 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000345 DIEEntry BarEntry(Bar);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000346 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000347 DIEEntry FooEntry(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000348 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000349 FooEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000350
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000351 DIEEntry PtrToFooMemRef(PtrToFooMem);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000352 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
David Blaikied70a0552013-10-22 18:14:41 +0000353
David Blaikie914046e2014-04-25 20:00:34 +0000354 Foo.addChild(std::move(Mem));
David Blaikied70a0552013-10-22 18:14:41 +0000355
David Blaikie2aee7be2013-10-24 18:29:03 +0000356 MD5ResDecl = DIEHash().computeTypeSignature(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000357 }
358 uint64_t MD5ResDef;
359 {
360 DIE Bar(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000361 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
362 Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikied70a0552013-10-22 18:14:41 +0000363
364 DIE Foo(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000365 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
366 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikied70a0552013-10-22 18:14:41 +0000367
David Blaikie914046e2014-04-25 20:00:34 +0000368 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000369 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikied70a0552013-10-22 18:14:41 +0000370 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000371 Zero);
David Blaikied70a0552013-10-22 18:14:41 +0000372
373 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000374 DIEEntry BarEntry(Bar);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000375 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000376 DIEEntry FooEntry(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000377 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000378 FooEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000379
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000380 DIEEntry PtrToFooMemRef(PtrToFooMem);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000381 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
David Blaikied70a0552013-10-22 18:14:41 +0000382
David Blaikie914046e2014-04-25 20:00:34 +0000383 Foo.addChild(std::move(Mem));
David Blaikied70a0552013-10-22 18:14:41 +0000384
David Blaikie2aee7be2013-10-24 18:29:03 +0000385 MD5ResDef = DIEHash().computeTypeSignature(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000386 }
387 ASSERT_EQ(MD5ResDef, MD5ResDecl);
388}
389
390// Check that the hash for a pointer-to-member matches regardless of whether the
391// pointed-to type is a declaration or a definition.
392//
393// struct bar; // { };
394// struct foo { bar bar::*mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000395TEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) {
David Blaikied70a0552013-10-22 18:14:41 +0000396 DIEInteger Zero(0);
397 DIEInteger One(1);
398 DIEInteger Eight(8);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000399 DIEString FooStr = getString("foo");
400 DIEString BarStr = getString("bar");
401 DIEString MemStr = getString("mem");
David Blaikied70a0552013-10-22 18:14:41 +0000402 uint64_t MD5ResDecl;
403 {
404 DIE Bar(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000405 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
406 Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
David Blaikied70a0552013-10-22 18:14:41 +0000407
408 DIE Foo(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000409 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
410 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikied70a0552013-10-22 18:14:41 +0000411
David Blaikie914046e2014-04-25 20:00:34 +0000412 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000413 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikied70a0552013-10-22 18:14:41 +0000414 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000415 Zero);
David Blaikied70a0552013-10-22 18:14:41 +0000416
417 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000418 DIEEntry BarEntry(Bar);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000419 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000420 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000421 BarEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000422
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000423 DIEEntry PtrToFooMemRef(PtrToFooMem);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000424 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
David Blaikied70a0552013-10-22 18:14:41 +0000425
David Blaikie914046e2014-04-25 20:00:34 +0000426 Foo.addChild(std::move(Mem));
David Blaikied70a0552013-10-22 18:14:41 +0000427
David Blaikie2aee7be2013-10-24 18:29:03 +0000428 MD5ResDecl = DIEHash().computeTypeSignature(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000429 }
430 uint64_t MD5ResDef;
431 {
432 DIE Bar(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000433 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
434 Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikied70a0552013-10-22 18:14:41 +0000435
436 DIE Foo(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000437 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
438 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikied70a0552013-10-22 18:14:41 +0000439
David Blaikie914046e2014-04-25 20:00:34 +0000440 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000441 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
David Blaikied70a0552013-10-22 18:14:41 +0000442 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000443 Zero);
David Blaikied70a0552013-10-22 18:14:41 +0000444
445 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000446 DIEEntry BarEntry(Bar);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000447 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000448 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000449 BarEntry);
David Blaikied70a0552013-10-22 18:14:41 +0000450
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000451 DIEEntry PtrToFooMemRef(PtrToFooMem);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000452 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
David Blaikied70a0552013-10-22 18:14:41 +0000453
David Blaikie914046e2014-04-25 20:00:34 +0000454 Foo.addChild(std::move(Mem));
David Blaikied70a0552013-10-22 18:14:41 +0000455
David Blaikie2aee7be2013-10-24 18:29:03 +0000456 MD5ResDef = DIEHash().computeTypeSignature(Foo);
David Blaikied70a0552013-10-22 18:14:41 +0000457 }
458 // FIXME: This seems to be a bug in the DWARF type hashing specification that
459 // only uses the brief name hashing for types referenced via DW_AT_type. In
460 // this case the type is referenced via DW_AT_containing_type and full hashing
461 // causes a hash to differ when the containing type is a declaration in one TU
462 // and a definition in another.
463 ASSERT_NE(MD5ResDef, MD5ResDecl);
464}
David Blaikie32744412013-10-24 17:53:58 +0000465
466// struct { } a;
467// struct foo { decltype(a) mem; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000468TEST_F(DIEHashTest, RefUnnamedType) {
David Blaikie32744412013-10-24 17:53:58 +0000469 DIEInteger Zero(0);
470 DIEInteger One(1);
471 DIEInteger Eight(8);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000472 DIEString FooStr = getString("foo");
473 DIEString MemStr = getString("mem");
David Blaikie32744412013-10-24 17:53:58 +0000474
475 DIE Unnamed(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000476 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie32744412013-10-24 17:53:58 +0000477
478 DIE Foo(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000479 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
480 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
David Blaikie32744412013-10-24 17:53:58 +0000481
David Blaikie914046e2014-04-25 20:00:34 +0000482 auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000483 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
484 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
David Blaikie32744412013-10-24 17:53:58 +0000485
486 DIE UnnamedPtr(dwarf::DW_TAG_pointer_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000487 UnnamedPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000488 DIEEntry UnnamedRef(Unnamed);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000489 UnnamedPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedRef);
David Blaikie32744412013-10-24 17:53:58 +0000490
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000491 DIEEntry UnnamedPtrRef(UnnamedPtr);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000492 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedPtrRef);
David Blaikie32744412013-10-24 17:53:58 +0000493
David Blaikie914046e2014-04-25 20:00:34 +0000494 Foo.addChild(std::move(Mem));
David Blaikie32744412013-10-24 17:53:58 +0000495
David Blaikie2aee7be2013-10-24 18:29:03 +0000496 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
David Blaikie32744412013-10-24 17:53:58 +0000497
498 ASSERT_EQ(0x954e026f01c02529ULL, MD5Res);
499}
David Blaikie65cc9692013-10-25 18:38:43 +0000500
Eric Christopher5ad8d902014-01-31 20:02:55 +0000501// struct { struct foo { }; };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000502TEST_F(DIEHashTest, NestedType) {
David Blaikie65cc9692013-10-25 18:38:43 +0000503 DIE Unnamed(dwarf::DW_TAG_structure_type);
504 DIEInteger One(1);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000505 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie65cc9692013-10-25 18:38:43 +0000506
David Blaikie914046e2014-04-25 20:00:34 +0000507 auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000508 DIEString FooStr = getString("foo");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000509 Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
510 Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie65cc9692013-10-25 18:38:43 +0000511
David Blaikie914046e2014-04-25 20:00:34 +0000512 Unnamed.addChild(std::move(Foo));
David Blaikie65cc9692013-10-25 18:38:43 +0000513
514 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
515
516 // The exact same hash GCC produces for this DIE.
517 ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res);
518}
David Blaikie8bc7db72013-10-25 20:04:25 +0000519
520// struct { static void func(); };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000521TEST_F(DIEHashTest, MemberFunc) {
David Blaikie8bc7db72013-10-25 20:04:25 +0000522 DIE Unnamed(dwarf::DW_TAG_structure_type);
523 DIEInteger One(1);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000524 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
David Blaikie8bc7db72013-10-25 20:04:25 +0000525
David Blaikie914046e2014-04-25 20:00:34 +0000526 auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000527 DIEString FuncStr = getString("func");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000528 Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
David Blaikie8bc7db72013-10-25 20:04:25 +0000529
David Blaikie914046e2014-04-25 20:00:34 +0000530 Unnamed.addChild(std::move(Func));
David Blaikie8bc7db72013-10-25 20:04:25 +0000531
532 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
533
534 // The exact same hash GCC produces for this DIE.
535 ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
536}
Eric Christopher4b1cf582014-01-31 20:02:58 +0000537
538// struct A {
539// static void func();
540// };
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000541TEST_F(DIEHashTest, MemberFuncFlag) {
Eric Christopher4b1cf582014-01-31 20:02:58 +0000542 DIE A(dwarf::DW_TAG_structure_type);
543 DIEInteger One(1);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000544 DIEString AStr = getString("A");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000545 A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
546 A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
547 A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
548 A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
Eric Christopher4b1cf582014-01-31 20:02:58 +0000549
David Blaikie914046e2014-04-25 20:00:34 +0000550 auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000551 DIEString FuncStr = getString("func");
552 DIEString FuncLinkage = getString("_ZN1A4funcEv");
Eric Christopher4b1cf582014-01-31 20:02:58 +0000553 DIEInteger Two(2);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000554 Func->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
555 Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
556 Func->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
557 Func->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
558 Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, FuncLinkage);
559 Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
Eric Christopher4b1cf582014-01-31 20:02:58 +0000560
David Blaikie914046e2014-04-25 20:00:34 +0000561 A.addChild(std::move(Func));
Eric Christopher4b1cf582014-01-31 20:02:58 +0000562
563 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
564
565 // The exact same hash GCC produces for this DIE.
566 ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
567}
Eric Christopher8192ba22014-02-20 00:54:40 +0000568
569// Derived from:
570// struct A {
Eric Christopherf5ec3a02014-02-20 00:59:17 +0000571// const static int PI = -3;
Eric Christopher8192ba22014-02-20 00:54:40 +0000572// };
573// A a;
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000574TEST_F(DIEHashTest, MemberSdata) {
Eric Christopher8192ba22014-02-20 00:54:40 +0000575 DIE A(dwarf::DW_TAG_structure_type);
576 DIEInteger One(1);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000577 DIEString AStr = getString("A");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000578 A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
579 A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
580 A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
581 A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
Eric Christopher8192ba22014-02-20 00:54:40 +0000582
583 DIEInteger Four(4);
584 DIEInteger Five(5);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000585 DIEString FStr = getString("int");
David Blaikiede519a22014-04-25 17:07:55 +0000586 DIE IntTyDIE(dwarf::DW_TAG_base_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000587 IntTyDIE.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
588 IntTyDIE.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
589 IntTyDIE.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
Eric Christopher8192ba22014-02-20 00:54:40 +0000590
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000591 DIEEntry IntTy(IntTyDIE);
David Blaikie914046e2014-04-25 20:00:34 +0000592 auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000593 PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntTy);
Eric Christopher8192ba22014-02-20 00:54:40 +0000594
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000595 DIEEntry PITy(*PITyDIE);
David Blaikie914046e2014-04-25 20:00:34 +0000596 auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000597 DIEString PIStr = getString("PI");
Eric Christopher8192ba22014-02-20 00:54:40 +0000598 DIEInteger Two(2);
599 DIEInteger NegThree(-3);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000600 PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
601 PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
602 PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
603 PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
604 PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
605 PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
606 PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, NegThree);
Eric Christopher8192ba22014-02-20 00:54:40 +0000607
David Blaikie914046e2014-04-25 20:00:34 +0000608 A.addChild(std::move(PI));
Eric Christopher8192ba22014-02-20 00:54:40 +0000609
Eric Christopher8192ba22014-02-20 00:54:40 +0000610 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
611 ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
612}
Eric Christopher420569b2014-02-20 02:50:45 +0000613
614// Derived from:
615// struct A {
616// const static float PI = 3.14;
617// };
618// A a;
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000619TEST_F(DIEHashTest, MemberBlock) {
Eric Christopher420569b2014-02-20 02:50:45 +0000620 DIE A(dwarf::DW_TAG_structure_type);
621 DIEInteger One(1);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000622 DIEString AStr = getString("A");
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000623 A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
624 A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
625 A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
626 A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
Eric Christopher420569b2014-02-20 02:50:45 +0000627
628 DIEInteger Four(4);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000629 DIEString FStr = getString("float");
David Blaikie914046e2014-04-25 20:00:34 +0000630 auto FloatTyDIE = make_unique<DIE>(dwarf::DW_TAG_base_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000631 FloatTyDIE->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
632 FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Four);
633 FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
Eric Christopher420569b2014-02-20 02:50:45 +0000634
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000635 DIEEntry FloatTy(*FloatTyDIE);
David Blaikie914046e2014-04-25 20:00:34 +0000636 auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000637 PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FloatTy);
Eric Christopher420569b2014-02-20 02:50:45 +0000638
David Blaikie8dbcc3f2014-04-25 19:33:43 +0000639 DIEEntry PITy(*PITyDIE);
David Blaikie914046e2014-04-25 20:00:34 +0000640 auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
Duncan P. N. Exon Smithf73bcf42015-05-24 16:40:47 +0000641 DIEString PIStr = getString("PI");
Eric Christopher420569b2014-02-20 02:50:45 +0000642 DIEInteger Two(2);
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000643 PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
644 PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
645 PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
646 PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
647 PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
648 PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
Eric Christopher420569b2014-02-20 02:50:45 +0000649
David Blaikiede519a22014-04-25 17:07:55 +0000650 DIEBlock PIBlock;
Eric Christopher420569b2014-02-20 02:50:45 +0000651 DIEInteger Blk1(0xc3);
652 DIEInteger Blk2(0xf5);
653 DIEInteger Blk3(0x48);
654 DIEInteger Blk4(0x40);
655
Duncan P. N. Exon Smithe7e1d0c2015-05-27 22:14:58 +0000656 PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk1);
657 PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk2);
658 PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk3);
659 PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk4);
Eric Christopher420569b2014-02-20 02:50:45 +0000660
David Blaikiede519a22014-04-25 17:07:55 +0000661 PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, &PIBlock);
Eric Christopher420569b2014-02-20 02:50:45 +0000662
David Blaikie914046e2014-04-25 20:00:34 +0000663 A.addChild(std::move(PI));
Eric Christopher420569b2014-02-20 02:50:45 +0000664
665 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
666 ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
667}
Eric Christopher25b7adc2013-09-03 21:57:57 +0000668}