blob: fd1845eb167148c07b07f9f24c6ee150481e0fb3 [file] [log] [blame]
Eric Christopher800a8762013-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
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 Christopher800a8762013-09-03 21:57:57 +000017using namespace llvm;
David Blaikiee4df43e2013-10-15 23:00:17 +000018
19namespace {
David Blaikie88a68cb2013-10-17 00:10:34 +000020TEST(Data1, DIEHash) {
Eric Christopher800a8762013-09-03 21:57:57 +000021 DIEHash Hash;
Benjamin Kramer449a88e2013-09-29 11:29:20 +000022 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 Blaikiec0987082013-10-16 23:36:20 +000026 ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
27}
28
David Blaikie88a68cb2013-10-17 00:10:34 +000029TEST(TrivialType, DIEHash) {
David Blaikiec0987082013-10-16 23:36:20 +000030 // A complete, but simple, type containing no members and defined on the first
31 // line of a file.
David Blaikie88a68cb2013-10-17 00:10:34 +000032 DIE Unnamed(dwarf::DW_TAG_structure_type);
David Blaikiec0987082013-10-16 23:36:20 +000033 DIEInteger One(1);
David Blaikie88a68cb2013-10-17 00:10:34 +000034 Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
David Blaikiec0987082013-10-16 23:36:20 +000035
36 // Line and file number are ignored.
David Blaikie88a68cb2013-10-17 00:10:34 +000037 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 Blaikiec0987082013-10-16 23:36:20 +000040
41 // The exact same hash GCC produces for this DIE.
42 ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
Eric Christopher800a8762013-09-03 21:57:57 +000043}
David Blaikie88a68cb2013-10-17 00:10:34 +000044
45TEST(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
54 // Line and file number are ignored.
55 Foo.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
56 Foo.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
57 uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo);
58
59 // The exact same hash GCC produces for this DIE.
60 ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
61}
62
63TEST(NamespacedType, DIEHash) {
64 // A complete named type containing no members and defined on the first line
65 // of a file.
66 DIE CU(dwarf::DW_TAG_compile_unit);
67
68 DIE *Space = new DIE(dwarf::DW_TAG_namespace);
69 DIEInteger One(1);
70 DIEString SpaceStr(&One, "space");
71 Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr);
72 // DW_AT_declaration is ignored.
73 Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
74 // sibling?
75
76 DIE *Foo = new DIE(dwarf::DW_TAG_structure_type);
77 DIEString FooStr(&One, "foo");
78 Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
79 Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
80
81 // Line and file number are ignored.
82 Foo->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
83 Foo->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
84
85 Space->addChild(Foo);
86 CU.addChild(Space);
87
88 uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
89
90 // The exact same hash GCC produces for this DIE.
91 ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
92}
Eric Christopher800a8762013-09-03 21:57:57 +000093}