Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 10 | #include "../lib/CodeGen/AsmPrinter/DIE.h" |
| 11 | #include "../lib/CodeGen/AsmPrinter/DIEHash.h" |
| 12 | #include "llvm/Support/Dwarf.h" |
| 13 | #include "llvm/Support/Debug.h" |
| 14 | #include "llvm/Support/Format.h" |
| 15 | #include "gtest/gtest.h" |
| 16 | |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 17 | using namespace llvm; |
David Blaikie | e4df43e | 2013-10-15 23:00:17 +0000 | [diff] [blame] | 18 | |
| 19 | namespace { |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 20 | TEST(Data1, DIEHash) { |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 21 | DIEHash Hash; |
Benjamin Kramer | 449a88e | 2013-09-29 11:29:20 +0000 | [diff] [blame] | 22 | DIE Die(dwarf::DW_TAG_base_type); |
| 23 | DIEInteger Size(4); |
| 24 | Die.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Size); |
| 25 | uint64_t MD5Res = Hash.computeTypeSignature(&Die); |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 26 | ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res); |
| 27 | } |
| 28 | |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 29 | TEST(TrivialType, DIEHash) { |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 30 | // A complete, but simple, type containing no members and defined on the first |
| 31 | // line of a file. |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 32 | DIE Unnamed(dwarf::DW_TAG_structure_type); |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 33 | DIEInteger One(1); |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 34 | Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 35 | |
| 36 | // Line and file number are ignored. |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 37 | Unnamed.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); |
| 38 | Unnamed.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One); |
| 39 | uint64_t MD5Res = DIEHash().computeTypeSignature(&Unnamed); |
David Blaikie | c098708 | 2013-10-16 23:36:20 +0000 | [diff] [blame] | 40 | |
| 41 | // The exact same hash GCC produces for this DIE. |
| 42 | ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res); |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 43 | } |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 44 | |
| 45 | TEST(NamedType, DIEHash) { |
| 46 | // A complete named type containing no members and defined on the first line |
| 47 | // of a file. |
| 48 | DIE Foo(dwarf::DW_TAG_structure_type); |
| 49 | DIEInteger One(1); |
| 50 | DIEString FooStr(&One, "foo"); |
| 51 | Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); |
| 52 | Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); |
| 53 | |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 54 | uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo); |
| 55 | |
| 56 | // The exact same hash GCC produces for this DIE. |
| 57 | ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res); |
| 58 | } |
| 59 | |
| 60 | TEST(NamespacedType, DIEHash) { |
| 61 | // A complete named type containing no members and defined on the first line |
| 62 | // of a file. |
| 63 | DIE CU(dwarf::DW_TAG_compile_unit); |
| 64 | |
| 65 | DIE *Space = new DIE(dwarf::DW_TAG_namespace); |
| 66 | DIEInteger One(1); |
| 67 | DIEString SpaceStr(&One, "space"); |
| 68 | Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr); |
| 69 | // DW_AT_declaration is ignored. |
| 70 | Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One); |
| 71 | // sibling? |
| 72 | |
| 73 | DIE *Foo = new DIE(dwarf::DW_TAG_structure_type); |
| 74 | DIEString FooStr(&One, "foo"); |
| 75 | Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); |
| 76 | Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); |
| 77 | |
David Blaikie | 88a68cb | 2013-10-17 00:10:34 +0000 | [diff] [blame] | 78 | Space->addChild(Foo); |
| 79 | CU.addChild(Space); |
| 80 | |
| 81 | uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); |
| 82 | |
| 83 | // The exact same hash GCC produces for this DIE. |
| 84 | ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res); |
| 85 | } |
David Blaikie | 47f66d5 | 2013-10-17 22:07:09 +0000 | [diff] [blame^] | 86 | |
| 87 | TEST(TypeWithMember, DIEHash) { |
| 88 | DIE Unnamed(dwarf::DW_TAG_structure_type); |
| 89 | DIEInteger Four(4); |
| 90 | Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); |
| 91 | |
| 92 | DIE *Member = new DIE(dwarf::DW_TAG_member); |
| 93 | DIEString MemberStr(&Four, "member"); |
| 94 | Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr); |
| 95 | // type |
| 96 | DIEInteger Zero(0); |
| 97 | Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); |
| 98 | |
| 99 | Unnamed.addChild(Member); |
| 100 | |
| 101 | DIE Int(dwarf::DW_TAG_base_type); |
| 102 | DIEString IntStr(&Four, "int"); |
| 103 | Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); |
| 104 | Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); |
| 105 | DIEInteger Five(5); |
| 106 | Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five); |
| 107 | |
| 108 | DIEEntry IntRef(&Int); |
| 109 | Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); |
| 110 | |
| 111 | uint64_t MD5Res = DIEHash().computeTypeSignature(&Unnamed); |
| 112 | |
| 113 | ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res); |
| 114 | } |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 115 | } |