DWARF type hashing: begin implementing Step 5, summary hashing in declarable contexts

There are several other tag types that need similar handling but to
ensure test coverage they'll be coming incrementally.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193126 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp
index 6c9cd89..7d8b024 100644
--- a/unittests/CodeGen/DIEHashTest.cpp
+++ b/unittests/CodeGen/DIEHashTest.cpp
@@ -26,9 +26,8 @@
   ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
 }
 
+// struct {};
 TEST(DIEHashTest, TrivialType) {
-  // A complete, but simple, type containing no members and defined on the first
-  // line of a file.
   DIE Unnamed(dwarf::DW_TAG_structure_type);
   DIEInteger One(1);
   Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
@@ -42,9 +41,8 @@
   ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
 }
 
+// struct foo { };
 TEST(DIEHashTest, NamedType) {
-  // A complete named type containing no members and defined on the first line
-  // of a file.
   DIE Foo(dwarf::DW_TAG_structure_type);
   DIEInteger One(1);
   DIEString FooStr(&One, "foo");
@@ -57,9 +55,8 @@
   ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
 }
 
+// namespace space { struct foo { }; }
 TEST(DIEHashTest, NamespacedType) {
-  // A complete named type containing no members and defined on the first line
-  // of a file.
   DIE CU(dwarf::DW_TAG_compile_unit);
 
   DIE *Space = new DIE(dwarf::DW_TAG_namespace);
@@ -84,6 +81,7 @@
   ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
 }
 
+// struct { int member; };
 TEST(DIEHashTest, TypeWithMember) {
   DIE Unnamed(dwarf::DW_TAG_structure_type);
   DIEInteger Four(4);
@@ -112,6 +110,7 @@
   ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
 }
 
+// struct foo { int mem1, mem2; };
 TEST(DIEHashTest, ReusedType) {
   DIE Unnamed(dwarf::DW_TAG_structure_type);
   DIEInteger Eight(8);
@@ -149,6 +148,7 @@
   ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
 }
 
+// struct foo { static foo f; };
 TEST(DIEHashTest, RecursiveType) {
   DIE Foo(dwarf::DW_TAG_structure_type);
   DIEInteger One(1);
@@ -169,4 +169,33 @@
 
   ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
 }
+
+// struct foo { foo *mem; };
+TEST(DIEHashTest, Pointer) {
+  DIE Foo(dwarf::DW_TAG_structure_type);
+  DIEInteger Eight(8);
+  Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
+  DIEString FooStr(&Eight, "foo");
+  Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
+
+  DIE *Mem = new DIE(dwarf::DW_TAG_member);
+  DIEString MemStr(&Eight, "mem");
+  Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
+  DIEInteger Zero(0);
+  Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
+
+  DIE FooPtr(dwarf::DW_TAG_pointer_type);
+  FooPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
+  DIEEntry FooRef(&Foo);
+  FooPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef);
+
+  DIEEntry FooPtrRef(&FooPtr);
+  Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooPtrRef);
+
+  Foo.addChild(Mem);
+
+  uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo);
+
+  ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
+}
 }