1800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===// 2800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// 3800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// The LLVM Compiler Infrastructure 4800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// 5800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// This file is distributed under the University of Illinois Open Source 6800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// License. See LICENSE.TXT for details. 7800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher// 8800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher//===----------------------------------------------------------------------===// 9800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher 10ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/CodeGen/DIE.h" 11800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher#include "../lib/CodeGen/AsmPrinter/DIEHash.h" 12ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/ADT/STLExtras.h" 136948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar#include "llvm/CodeGen/DwarfStringPoolEntry.h" 14800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher#include "llvm/Support/Debug.h" 1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/Support/Dwarf.h" 16800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher#include "llvm/Support/Format.h" 17800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher#include "gtest/gtest.h" 18800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher 19800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopherusing namespace llvm; 20e4df43e36dbdca444a6e812bdd2c9ea93360a2ecDavid Blaikie 21e4df43e36dbdca444a6e812bdd2c9ea93360a2ecDavid Blaikienamespace { 226948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 236948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar// Test fixture 246948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarclass DIEHashTest : public testing::Test { 25cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainarpublic: 26cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar BumpPtrAllocator Alloc; 27cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar 28cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainarprivate: 296948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar StringMap<DwarfStringPoolEntry> Pool; 306948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 316948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainarpublic: 326948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString getString(StringRef S) { 336948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DwarfStringPoolEntry Entry = {nullptr, 1, 1}; 346948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return DIEString( 356948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DwarfStringPoolEntryRef(*Pool.insert(std::make_pair(S, Entry)).first)); 366948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar } 376948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar}; 386948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar 396948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, Data1) { 40800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher DIEHash Hash; 41cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Die = *DIE::get(Alloc, dwarf::DW_TAG_base_type); 42449a88e9a6279cc016d795e86e73c026675ab929Benjamin Kramer DIEInteger Size(4); 43cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Die.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size); 44377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = Hash.computeTypeSignature(Die); 45c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res); 46c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie} 47c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie 48f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct {}; 496948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, TrivialType) { 50cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 51c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie DIEInteger One(1); 52cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 53c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie 54c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie // Line and file number are ignored. 55cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 56cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One); 57377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); 58c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie 59c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie // The exact same hash GCC produces for this DIE. 60c0987082206d202c20ebe1d528c1b28a875160acDavid Blaikie ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res); 61800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher} 6288a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 63f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct foo { }; 646948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, NamedType) { 65cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 6688a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie DIEInteger One(1); 676948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 68cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 69cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 7088a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 71377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 7288a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 7388a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie // The exact same hash GCC produces for this DIE. 7488a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res); 7588a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie} 7688a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 77f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// namespace space { struct foo { }; } 786948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, NamespacedType) { 79cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &CU = *DIE::get(Alloc, dwarf::DW_TAG_compile_unit); 8088a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 81cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Space = DIE::get(Alloc, dwarf::DW_TAG_namespace); 8288a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie DIEInteger One(1); 836948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString SpaceStr = getString("space"); 84cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Space->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, SpaceStr); 8588a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie // DW_AT_declaration is ignored. 86cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Space->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 87cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 8888a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie // sibling? 8988a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 90cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type); 916948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 92cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 93cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 9488a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 95dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIE &N = *Foo; 96dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Space->addChild(std::move(Foo)); 97dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines CU.addChild(std::move(Space)); 9888a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 99dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines uint64_t MD5Res = DIEHash().computeTypeSignature(N); 10088a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie 10188a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie // The exact same hash GCC produces for this DIE. 10288a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res); 10388a68cbbb57aa9caef60dbd2f63d908983e77465David Blaikie} 10447f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie 105f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct { int member; }; 1066948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, TypeWithMember) { 107cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 10847f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie DIEInteger Four(4); 109cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four); 11047f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie 111cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type); 1126948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString IntStr = getString("int"); 113cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr); 114cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four); 11547f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie DIEInteger Five(5); 116cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five); 11747f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie 118dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry IntRef(Int); 119dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 120cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Member = DIE::get(Alloc, dwarf::DW_TAG_member); 1216948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemberStr = getString("member"); 122cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Member->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemberStr); 123dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEInteger Zero(0); 124cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Member->addValue(Alloc, dwarf::DW_AT_data_member_location, 125cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_data1, Zero); 126cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Member->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef); 12747f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie 128dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Unnamed.addChild(std::move(Member)); 129dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 130377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); 13147f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie 13247f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res); 13347f66d5a756d4eaeba9082ff4c82023a213daf45David Blaikie} 1343baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 135f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct foo { int mem1, mem2; }; 1366948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, ReusedType) { 137cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 1383baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie DIEInteger Eight(8); 139cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 1403baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 1413baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie DIEInteger Four(4); 142cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type); 1436948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString IntStr = getString("int"); 144cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr); 145cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four); 146dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEInteger Five(5); 147cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five); 148dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 149dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry IntRef(Int); 150dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 151cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem1 = DIE::get(Alloc, dwarf::DW_TAG_member); 1526948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString Mem1Str = getString("mem1"); 153cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem1->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem1Str); 1543baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie DIEInteger Zero(0); 155cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem1->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 1566948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar Zero); 157cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem1->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef); 1583baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 159dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Unnamed.addChild(std::move(Mem1)); 1603baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 161cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem2 = DIE::get(Alloc, dwarf::DW_TAG_member); 1626948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString Mem2Str = getString("mem2"); 163cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem2->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem2Str); 164cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem2->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 1656948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar Four); 166cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem2->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef); 1673baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 168dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Unnamed.addChild(std::move(Mem2)); 169dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 170377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); 1713baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 1723baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res); 1733baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie} 1743baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 175f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct foo { static foo f; }; 1766948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, RecursiveType) { 177cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 1783baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie DIEInteger One(1); 179cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 1806948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 181cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 1823baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 183cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 1846948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 185cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 186dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRef(Foo); 187cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef); 1883baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them. 1893baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 190dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 1913baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 192377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 1933baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie 1943baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res); 1953baa3c37ce2cd7db7a4840e66f22a08ce1702787David Blaikie} 196f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 197f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie// struct foo { foo *mem; }; 1986948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, Pointer) { 199cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 200f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie DIEInteger Eight(8); 201cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 2026948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 203cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 204f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 205cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 2066948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 207cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 208f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie DIEInteger Zero(0); 209cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 210cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Zero); 211f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 212cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &FooPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type); 213cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 214dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRef(Foo); 215cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef); 216f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 217dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooPtrRef(FooPtr); 218cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooPtrRef); 219f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 220dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 221f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 222377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 223f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie 224f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res); 225f1545a219744c1ae66137e64d1c456cd8e924eb7David Blaikie} 226449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 227449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie// struct foo { foo &mem; }; 2286948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, Reference) { 229cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 230449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie DIEInteger Eight(8); 231cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 2326948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 233cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 234449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 235cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 2366948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 237cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 238449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie DIEInteger Zero(0); 239cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 240cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Zero); 241449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 242cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_reference_type); 243cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 244dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooEntry(Foo); 245cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry); 246449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 247cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type); 248dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRefRef(FooRef); 249cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 250cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRefRef); 251449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 252dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRefConstRef(FooRefConst); 253cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef); 254449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 255dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 256449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 257377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 258449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 259449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res); 260449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie} 261449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 262449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie// struct foo { foo &&mem; }; 2636948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, RValueReference) { 264cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 265449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie DIEInteger Eight(8); 266cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 2676948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 268cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 269449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 270cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 2716948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 272cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 273449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie DIEInteger Zero(0); 274cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 275cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Zero); 276449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 277cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_rvalue_reference_type); 278cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 279dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooEntry(Foo); 280cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry); 281449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 282cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type); 283dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRefRef(FooRef); 284cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 285cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FooRefRef); 286449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 287dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooRefConstRef(FooRefConst); 288cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef); 289449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 290dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 291449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 292377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 293449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie 294449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res); 295449f036a8141b9032ff310ecbe0ab4433c5c307bDavid Blaikie} 296f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 297f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// struct foo { foo foo::*mem; }; 2986948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, PtrToMember) { 299cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 300f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Eight(8); 301cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 3026948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 303cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 304f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 305cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 3066948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 307cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 308f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Zero(0); 309cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 310cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Zero); 311f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 312cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type); 313dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooEntry(Foo); 314cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry); 315cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, 3166948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar FooEntry); 317f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 318dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PtrToFooMemRef(PtrToFooMem); 319cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef); 320f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 321dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 322f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 323377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 324f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 325f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res); 326f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie} 327f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 328f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// Check that the hash for a pointer-to-member matches regardless of whether the 329f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// pointed-to type is a declaration or a definition. 330f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// 331f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// struct bar; // { }; 332f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// struct foo { bar foo::*mem; }; 3336948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, PtrToMemberDeclDefMatch) { 334f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Zero(0); 335f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger One(1); 336f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Eight(8); 3376948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 3386948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString BarStr = getString("bar"); 3396948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 340f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie uint64_t MD5ResDecl; 341f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie { 342cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 343cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr); 344cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 345cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 346f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 347cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 348cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 349cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 350f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 351cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 352cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 353cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, 354cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_data1, Zero); 355f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 356cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type); 357dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry BarEntry(Bar); 358cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 359cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar BarEntry); 360dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooEntry(Foo); 361cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, 362cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_ref4, FooEntry); 363f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 364dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PtrToFooMemRef(PtrToFooMem); 365cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 366cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMemRef); 367f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 368dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 369f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 370377e83202cb40849d384ddede39f9468af197427David Blaikie MD5ResDecl = DIEHash().computeTypeSignature(Foo); 371f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie } 372f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie uint64_t MD5ResDef; 373f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie { 374cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 375cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr); 376cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 377f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 378cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 379cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 380cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 381f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 382cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 383cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 384cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, 385cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_data1, Zero); 386f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 387cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type); 388dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry BarEntry(Bar); 389cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 390cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar BarEntry); 391dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FooEntry(Foo); 392cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, 393cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_ref4, FooEntry); 394f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 395dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PtrToFooMemRef(PtrToFooMem); 396cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 397cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMemRef); 398f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 399dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 400f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 401377e83202cb40849d384ddede39f9468af197427David Blaikie MD5ResDef = DIEHash().computeTypeSignature(Foo); 402f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie } 403f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie ASSERT_EQ(MD5ResDef, MD5ResDecl); 404f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie} 405f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 406f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// Check that the hash for a pointer-to-member matches regardless of whether the 407f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// pointed-to type is a declaration or a definition. 408f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// 409f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// struct bar; // { }; 410f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie// struct foo { bar bar::*mem; }; 4116948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) { 412f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Zero(0); 413f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger One(1); 414f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie DIEInteger Eight(8); 4156948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 4166948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString BarStr = getString("bar"); 4176948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 418f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie uint64_t MD5ResDecl; 419f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie { 420cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 421cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr); 422cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 423cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 424f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 425cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 426cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 427cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 428f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 429cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 430cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 431cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, 432cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_data1, Zero); 433f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 434cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type); 435dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry BarEntry(Bar); 436cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 4376948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar BarEntry); 438cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, 439cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_ref4, BarEntry); 440f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 441dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PtrToFooMemRef(PtrToFooMem); 442cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 443cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMemRef); 444f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 445dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 446f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 447377e83202cb40849d384ddede39f9468af197427David Blaikie MD5ResDecl = DIEHash().computeTypeSignature(Foo); 448f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie } 449f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie uint64_t MD5ResDef; 450f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie { 451cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 452cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr); 453cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 454f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 455cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 456cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 457cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 458f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 459cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 460cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 461cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, 462cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_data1, Zero); 463f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 464cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type); 465dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry BarEntry(Bar); 466cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 4676948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar BarEntry); 468cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, 469cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar dwarf::DW_FORM_ref4, BarEntry); 470f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 471dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PtrToFooMemRef(PtrToFooMem); 472cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 473cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PtrToFooMemRef); 474f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 475dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 476f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie 477377e83202cb40849d384ddede39f9468af197427David Blaikie MD5ResDef = DIEHash().computeTypeSignature(Foo); 478f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie } 479f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie // FIXME: This seems to be a bug in the DWARF type hashing specification that 480f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie // only uses the brief name hashing for types referenced via DW_AT_type. In 481f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie // this case the type is referenced via DW_AT_containing_type and full hashing 482f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie // causes a hash to differ when the containing type is a declaration in one TU 483f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie // and a definition in another. 484f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie ASSERT_NE(MD5ResDef, MD5ResDecl); 485f196208900e690fe2d3bb1c6ca393d3fcd64226dDavid Blaikie} 4861d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 4871d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie// struct { } a; 4881d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie// struct foo { decltype(a) mem; }; 4896948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, RefUnnamedType) { 4901d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie DIEInteger Zero(0); 4911d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie DIEInteger One(1); 4921d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie DIEInteger Eight(8); 4936948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 4946948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString MemStr = getString("mem"); 4951d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 496cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 497cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 4981d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 499cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 500cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight); 501cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 5021d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 503cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member); 504cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr); 505cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, 506cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Zero); 5071d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 508cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &UnnamedPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type); 509cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar UnnamedPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, 510cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Eight); 511dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry UnnamedRef(Unnamed); 512cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar UnnamedPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, 513cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar UnnamedRef); 5141d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 515dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry UnnamedPtrRef(UnnamedPtr); 516cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedPtrRef); 5171d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 518dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Foo.addChild(std::move(Mem)); 5191d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 520377e83202cb40849d384ddede39f9468af197427David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); 5211d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie 5221d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie ASSERT_EQ(0x954e026f01c02529ULL, MD5Res); 5231d7d8da4cb81aa3f149e1e80811d72525eee15e3David Blaikie} 524a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie 52536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// struct { struct foo { }; }; 5266948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, NestedType) { 527cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 528a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie DIEInteger One(1); 529cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 530a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie 531cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type); 5326948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FooStr = getString("foo"); 533cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr); 534cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 535a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie 536dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Unnamed.addChild(std::move(Foo)); 537a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie 538a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); 539a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie 540a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie // The exact same hash GCC produces for this DIE. 541a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res); 542a954618c6e6c5f94d3cedc0b6bc19dbc49e56ac2David Blaikie} 5437c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie 5447c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie// struct { static void func(); }; 5456948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, MemberFunc) { 546cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 5477c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie DIEInteger One(1); 548cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 5497c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie 550cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram); 5516948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FuncStr = getString("func"); 552cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr); 5537c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie 554dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Unnamed.addChild(std::move(Func)); 5557c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie 5567c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); 5577c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie 5587c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie // The exact same hash GCC produces for this DIE. 5597c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res); 5607c0c2e56b09fee406ca0bb6e3ac840a3a6ed1160David Blaikie} 56136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 56236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// struct A { 56336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// static void func(); 56436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// }; 5656948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, MemberFuncFlag) { 566cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 56736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger One(1); 5686948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString AStr = getString("A"); 569cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr); 570cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 571cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 572cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One); 57336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 574cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram); 5756948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FuncStr = getString("func"); 5766948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FuncLinkage = getString("_ZN1A4funcEv"); 57736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Two(2); 578cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, 579cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 580cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr); 581cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 582cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two); 583cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, 584cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FuncLinkage); 585cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Func->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 586cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 58736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 588dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines A.addChild(std::move(Func)); 58936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 59036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines uint64_t MD5Res = DIEHash().computeTypeSignature(A); 59136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 59236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // The exact same hash GCC produces for this DIE. 59336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res); 59436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 59536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 59636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// Derived from: 59736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// struct A { 59836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// const static int PI = -3; 59936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// }; 60036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// A a; 6016948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, MemberSdata) { 602cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 60336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger One(1); 6046948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString AStr = getString("A"); 605cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr); 606cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 607cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 608cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One); 60936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 61036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Four(4); 61136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Five(5); 6126948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FStr = getString("int"); 613cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &IntTyDIE = *DIE::get(Alloc, dwarf::DW_TAG_base_type); 614cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar IntTyDIE.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four); 615cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar IntTyDIE.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five); 616cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar IntTyDIE.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr); 61736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 61836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEEntry IntTy(IntTyDIE); 619cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type); 620cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntTy); 62136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 622dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PITy(*PITyDIE); 623cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto PI = DIE::get(Alloc, dwarf::DW_TAG_member); 6246948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString PIStr = getString("PI"); 62536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Two(2); 62636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger NegThree(-3); 627cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr); 628cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 629cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two); 630cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy); 631cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One); 632cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 633cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 634cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, NegThree); 63536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 636dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines A.addChild(std::move(PI)); 63736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 63836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines uint64_t MD5Res = DIEHash().computeTypeSignature(A); 63936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res); 64036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 64136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 64236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// Derived from: 64336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// struct A { 64436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// const static float PI = 3.14; 64536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// }; 64636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// A a; 6476948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarTEST_F(DIEHashTest, MemberBlock) { 648cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); 64936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger One(1); 6506948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString AStr = getString("A"); 651cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr); 652cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One); 653cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 654cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One); 65536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 65636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Four(4); 6576948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString FStr = getString("float"); 658cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto FloatTyDIE = DIE::get(Alloc, dwarf::DW_TAG_base_type); 659cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FloatTyDIE->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, 660cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Four); 661cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FloatTyDIE->addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, 662cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar Four); 663cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar FloatTyDIE->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr); 664dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry FloatTy(*FloatTyDIE); 665cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type); 666cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FloatTy); 66736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 668dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEEntry PITy(*PITyDIE); 669cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar auto PI = DIE::get(Alloc, dwarf::DW_TAG_member); 6706948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar DIEString PIStr = getString("PI"); 67136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Two(2); 672cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr); 673cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One); 674cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two); 675cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy); 676cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One); 677cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, 678cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar One); 67936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 680dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines DIEBlock PIBlock; 68136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Blk1(0xc3); 68236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Blk2(0xf5); 68336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Blk3(0x48); 68436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DIEInteger Blk4(0x40); 68536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 686cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk1); 687cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk2); 688cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk3); 689cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk4); 69036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 691cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, 692cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar &PIBlock); 69336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 694dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines A.addChild(std::move(PI)); 69536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 69636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines uint64_t MD5Res = DIEHash().computeTypeSignature(A); 69736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res); 69836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 699800a8761285a239bb82f7d1883a8398815cd2d8fEric Christopher} 700