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 { |
Eric Christopher | 800a876 | 2013-09-03 21:57:57 +0000 | [diff] [blame] | 20 | TEST(DIEHashData1Test, DIEHash) { |
| 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 | |
| 29 | TEST(DIEHashTrivialTypeTest, DIEHash) { |
| 30 | // A complete, but simple, type containing no members and defined on the first |
| 31 | // line of a file. |
| 32 | DIE FooType(dwarf::DW_TAG_structure_type); |
| 33 | DIEInteger One(1); |
| 34 | FooType.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); |
| 35 | |
| 36 | // Line and file number are ignored. |
| 37 | FooType.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); |
| 38 | FooType.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One); |
| 39 | uint64_t MD5Res = DIEHash().computeTypeSignature(&FooType); |
| 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 | } |
| 44 | } |