diff options
author | David Blaikie <dblaikie@gmail.com> | 2013-10-21 18:59:40 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2013-10-21 18:59:40 +0000 |
commit | 3baa3c37ce2cd7db7a4840e66f22a08ce1702787 (patch) | |
tree | 45a04a70e0926df6d3d1e2dbdb2763a4350bb6c8 /unittests/CodeGen | |
parent | 79de3d7b3aae9c7cc1038a3223dc96dbdafbeb3f (diff) | |
download | external_llvm-3baa3c37ce2cd7db7a4840e66f22a08ce1702787.zip external_llvm-3baa3c37ce2cd7db7a4840e66f22a08ce1702787.tar.gz external_llvm-3baa3c37ce2cd7db7a4840e66f22a08ce1702787.tar.bz2 |
DWARF type hashing: Handle multiple (including recursive) references to the same type
This uses a map, keeping the type DIE numbering separate from the DIEs
themselves - alternatively we could do things the way GCC does if we
want to add an integer to the DIE type to record the numbering there.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193105 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/CodeGen')
-rw-r--r-- | unittests/CodeGen/DIEHashTest.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp index 834a16a2..6da1fd7 100644 --- a/unittests/CodeGen/DIEHashTest.cpp +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -92,7 +92,6 @@ TEST(TypeWithMember, DIEHash) { DIE *Member = new DIE(dwarf::DW_TAG_member); DIEString MemberStr(&Four, "member"); Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr); - // type DIEInteger Zero(0); Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -112,4 +111,62 @@ TEST(TypeWithMember, DIEHash) { ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res); } + +TEST(ReusedType, DIEHash) { + DIE Unnamed(dwarf::DW_TAG_structure_type); + DIEInteger Eight(8); + Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); + + DIE *Mem1 = new DIE(dwarf::DW_TAG_member); + DIEInteger Four(4); + DIEString Mem1Str(&Four, "mem1"); + Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem1Str); + DIEInteger Zero(0); + Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); + + Unnamed.addChild(Mem1); + + DIE *Mem2 = new DIE(dwarf::DW_TAG_member); + DIEString Mem2Str(&Four, "mem2"); + Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem2Str); + Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Four); + + Unnamed.addChild(Mem2); + + DIE Int(dwarf::DW_TAG_base_type); + DIEString IntStr(&Four, "int"); + Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); + Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); + DIEInteger Five(5); + Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five); + + DIEEntry IntRef(&Int); + Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); + Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); + + uint64_t MD5Res = DIEHash().computeTypeSignature(&Unnamed); + + ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res); +} + +TEST(RecursiveType, DIEHash) { + DIE Foo(dwarf::DW_TAG_structure_type); + DIEInteger One(1); + Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); + DIEString FooStr(&One, "foo"); + Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); + + DIE *Mem = new DIE(dwarf::DW_TAG_member); + DIEString MemStr(&One, "mem"); + Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); + DIEEntry FooRef(&Foo); + Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef); + // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them. + + Foo.addChild(Mem); + + uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo); + + ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res); +} } |