llvm.org GIT mirror llvm / 88a68cb
DIEHash: Include the type's context in the type hash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192856 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
2 changed file(s) with 59 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
465465 /// standard.
466466 uint64_t DIEHash::computeTypeSignature(DIE *Die) {
467467
468 if (DIE *Parent = Die->getParent())
469 addParentContext(Parent);
470
468471 // Hash the DIE.
469472 computeHash(Die);
470473
1616 using namespace llvm;
1717
1818 namespace {
19 TEST(DIEHashData1Test, DIEHash) {
19 TEST(Data1, DIEHash) {
2020 DIEHash Hash;
2121 DIE Die(dwarf::DW_TAG_base_type);
2222 DIEInteger Size(4);
2525 ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
2626 }
2727
28 TEST(DIEHashTrivialTypeTest, DIEHash) {
28 TEST(TrivialType, DIEHash) {
2929 // A complete, but simple, type containing no members and defined on the first
3030 // line of a file.
31 DIE FooType(dwarf::DW_TAG_structure_type);
31 DIE Unnamed(dwarf::DW_TAG_structure_type);
3232 DIEInteger One(1);
33 FooType.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
33 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
3434
3535 // Line and file number are ignored.
36 FooType.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
37 FooType.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
38 uint64_t MD5Res = DIEHash().computeTypeSignature(&FooType);
36 Unnamed.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
37 Unnamed.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
38 uint64_t MD5Res = DIEHash().computeTypeSignature(&Unnamed);
3939
4040 // The exact same hash GCC produces for this DIE.
4141 ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
4242 }
43
44 TEST(NamedType, DIEHash) {
45 // A complete named type containing no members and defined on the first line
46 // of a file.
47 DIE Foo(dwarf::DW_TAG_structure_type);
48 DIEInteger One(1);
49 DIEString FooStr(&One, "foo");
50 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
51 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
52
53 // Line and file number are ignored.
54 Foo.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
55 Foo.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
56 uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo);
57
58 // The exact same hash GCC produces for this DIE.
59 ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
4360 }
61
62 TEST(NamespacedType, DIEHash) {
63 // A complete named type containing no members and defined on the first line
64 // of a file.
65 DIE CU(dwarf::DW_TAG_compile_unit);
66
67 DIE *Space = new DIE(dwarf::DW_TAG_namespace);
68 DIEInteger One(1);
69 DIEString SpaceStr(&One, "space");
70 Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr);
71 // DW_AT_declaration is ignored.
72 Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
73 // sibling?
74
75 DIE *Foo = new DIE(dwarf::DW_TAG_structure_type);
76 DIEString FooStr(&One, "foo");
77 Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
78 Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
79
80 // Line and file number are ignored.
81 Foo->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
82 Foo->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
83
84 Space->addChild(Foo);
85 CU.addChild(Space);
86
87 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
88
89 // The exact same hash GCC produces for this DIE.
90 ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
91 }
92 }