diff options
Diffstat (limited to 'unittests/CodeGen/DIEHashTest.cpp')
-rw-r--r-- | unittests/CodeGen/DIEHashTest.cpp | 126 |
1 files changed, 70 insertions, 56 deletions
diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp index efb0920..c1b1160 100644 --- a/unittests/CodeGen/DIEHashTest.cpp +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -10,6 +10,7 @@ #include "llvm/CodeGen/DIE.h" #include "../lib/CodeGen/AsmPrinter/DIEHash.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" @@ -18,7 +19,20 @@ using namespace llvm; namespace { -TEST(DIEHashTest, Data1) { + +// Test fixture +class DIEHashTest : public testing::Test { + StringMap<DwarfStringPoolEntry> Pool; + +public: + DIEString getString(StringRef S) { + DwarfStringPoolEntry Entry = {nullptr, 1, 1}; + return DIEString( + DwarfStringPoolEntryRef(*Pool.insert(std::make_pair(S, Entry)).first)); + } +}; + +TEST_F(DIEHashTest, Data1) { DIEHash Hash; DIE Die(dwarf::DW_TAG_base_type); DIEInteger Size(4); @@ -28,7 +42,7 @@ TEST(DIEHashTest, Data1) { } // struct {}; -TEST(DIEHashTest, TrivialType) { +TEST_F(DIEHashTest, TrivialType) { DIE Unnamed(dwarf::DW_TAG_structure_type); DIEInteger One(1); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); @@ -43,10 +57,10 @@ TEST(DIEHashTest, TrivialType) { } // struct foo { }; -TEST(DIEHashTest, NamedType) { +TEST_F(DIEHashTest, NamedType) { DIE Foo(dwarf::DW_TAG_structure_type); DIEInteger One(1); - DIEString FooStr(&One, "foo"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); @@ -57,19 +71,19 @@ TEST(DIEHashTest, NamedType) { } // namespace space { struct foo { }; } -TEST(DIEHashTest, NamespacedType) { +TEST_F(DIEHashTest, NamespacedType) { DIE CU(dwarf::DW_TAG_compile_unit); auto Space = make_unique<DIE>(dwarf::DW_TAG_namespace); DIEInteger One(1); - DIEString SpaceStr(&One, "space"); + DIEString SpaceStr = getString("space"); Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr); // DW_AT_declaration is ignored. Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One); // sibling? auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type); - DIEString FooStr(&One, "foo"); + DIEString FooStr = getString("foo"); Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); @@ -84,13 +98,13 @@ TEST(DIEHashTest, NamespacedType) { } // struct { int member; }; -TEST(DIEHashTest, TypeWithMember) { +TEST_F(DIEHashTest, TypeWithMember) { DIE Unnamed(dwarf::DW_TAG_structure_type); DIEInteger Four(4); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); DIE Int(dwarf::DW_TAG_base_type); - DIEString IntStr(&Four, "int"); + DIEString IntStr = getString("int"); Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); DIEInteger Five(5); @@ -99,7 +113,7 @@ TEST(DIEHashTest, TypeWithMember) { DIEEntry IntRef(Int); auto Member = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemberStr(&Four, "member"); + DIEString MemberStr = getString("member"); Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr); DIEInteger Zero(0); Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, @@ -114,14 +128,14 @@ TEST(DIEHashTest, TypeWithMember) { } // struct foo { int mem1, mem2; }; -TEST(DIEHashTest, ReusedType) { +TEST_F(DIEHashTest, ReusedType) { DIE Unnamed(dwarf::DW_TAG_structure_type); DIEInteger Eight(8); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); DIEInteger Four(4); DIE Int(dwarf::DW_TAG_base_type); - DIEString IntStr(&Four, "int"); + DIEString IntStr = getString("int"); Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); Int.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); DIEInteger Five(5); @@ -130,7 +144,7 @@ TEST(DIEHashTest, ReusedType) { DIEEntry IntRef(Int); auto Mem1 = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString Mem1Str(&Four, "mem1"); + DIEString Mem1Str = getString("mem1"); Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem1Str); DIEInteger Zero(0); Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, @@ -140,7 +154,7 @@ TEST(DIEHashTest, ReusedType) { Unnamed.addChild(std::move(Mem1)); auto Mem2 = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString Mem2Str(&Four, "mem2"); + DIEString Mem2Str = getString("mem2"); Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem2Str); Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Four); @@ -154,15 +168,15 @@ TEST(DIEHashTest, ReusedType) { } // struct foo { static foo f; }; -TEST(DIEHashTest, RecursiveType) { +TEST_F(DIEHashTest, RecursiveType) { DIE Foo(dwarf::DW_TAG_structure_type); DIEInteger One(1); Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); - DIEString FooStr(&One, "foo"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); auto Mem = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemStr(&One, "mem"); + DIEString MemStr = getString("mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEEntry FooRef(Foo); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef); @@ -176,15 +190,15 @@ TEST(DIEHashTest, RecursiveType) { } // struct foo { foo *mem; }; -TEST(DIEHashTest, Pointer) { +TEST_F(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"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); auto Mem = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemStr(&Eight, "mem"); + DIEString MemStr = getString("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); @@ -205,15 +219,15 @@ TEST(DIEHashTest, Pointer) { } // struct foo { foo &mem; }; -TEST(DIEHashTest, Reference) { +TEST_F(DIEHashTest, Reference) { 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"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); auto Mem = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemStr(&Eight, "mem"); + DIEString MemStr = getString("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); @@ -238,15 +252,15 @@ TEST(DIEHashTest, Reference) { } // struct foo { foo &&mem; }; -TEST(DIEHashTest, RValueReference) { +TEST_F(DIEHashTest, RValueReference) { 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"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); auto Mem = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemStr(&Eight, "mem"); + DIEString MemStr = getString("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); @@ -271,15 +285,15 @@ TEST(DIEHashTest, RValueReference) { } // struct foo { foo foo::*mem; }; -TEST(DIEHashTest, PtrToMember) { +TEST_F(DIEHashTest, PtrToMember) { 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"); + DIEString FooStr = getString("foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); auto Mem = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString MemStr(&Eight, "mem"); + DIEString MemStr = getString("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); @@ -305,13 +319,13 @@ TEST(DIEHashTest, PtrToMember) { // // struct bar; // { }; // struct foo { bar foo::*mem; }; -TEST(DIEHashTest, PtrToMemberDeclDefMatch) { +TEST_F(DIEHashTest, PtrToMemberDeclDefMatch) { DIEInteger Zero(0); DIEInteger One(1); DIEInteger Eight(8); - DIEString FooStr(&Eight, "foo"); - DIEString BarStr(&Eight, "bar"); - DIEString MemStr(&Eight, "mem"); + DIEString FooStr = getString("foo"); + DIEString BarStr = getString("bar"); + DIEString MemStr = getString("mem"); uint64_t MD5ResDecl; { DIE Bar(dwarf::DW_TAG_structure_type); @@ -378,13 +392,13 @@ TEST(DIEHashTest, PtrToMemberDeclDefMatch) { // // struct bar; // { }; // struct foo { bar bar::*mem; }; -TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { +TEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) { DIEInteger Zero(0); DIEInteger One(1); DIEInteger Eight(8); - DIEString FooStr(&Eight, "foo"); - DIEString BarStr(&Eight, "bar"); - DIEString MemStr(&Eight, "mem"); + DIEString FooStr = getString("foo"); + DIEString BarStr = getString("bar"); + DIEString MemStr = getString("mem"); uint64_t MD5ResDecl; { DIE Bar(dwarf::DW_TAG_structure_type); @@ -451,12 +465,12 @@ TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { // struct { } a; // struct foo { decltype(a) mem; }; -TEST(DIEHashTest, RefUnnamedType) { +TEST_F(DIEHashTest, RefUnnamedType) { DIEInteger Zero(0); DIEInteger One(1); DIEInteger Eight(8); - DIEString FooStr(&Zero, "foo"); - DIEString MemStr(&Zero, "mem"); + DIEString FooStr = getString("foo"); + DIEString MemStr = getString("mem"); DIE Unnamed(dwarf::DW_TAG_structure_type); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); @@ -485,13 +499,13 @@ TEST(DIEHashTest, RefUnnamedType) { } // struct { struct foo { }; }; -TEST(DIEHashTest, NestedType) { +TEST_F(DIEHashTest, NestedType) { DIE Unnamed(dwarf::DW_TAG_structure_type); DIEInteger One(1); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); auto Foo = make_unique<DIE>(dwarf::DW_TAG_structure_type); - DIEString FooStr(&One, "foo"); + DIEString FooStr = getString("foo"); Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); @@ -504,13 +518,13 @@ TEST(DIEHashTest, NestedType) { } // struct { static void func(); }; -TEST(DIEHashTest, MemberFunc) { +TEST_F(DIEHashTest, MemberFunc) { DIE Unnamed(dwarf::DW_TAG_structure_type); DIEInteger One(1); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram); - DIEString FuncStr(&One, "func"); + DIEString FuncStr = getString("func"); Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr); Unnamed.addChild(std::move(Func)); @@ -524,18 +538,18 @@ TEST(DIEHashTest, MemberFunc) { // struct A { // static void func(); // }; -TEST(DIEHashTest, MemberFuncFlag) { +TEST_F(DIEHashTest, MemberFuncFlag) { DIE A(dwarf::DW_TAG_structure_type); DIEInteger One(1); - DIEString AStr(&One, "A"); + DIEString AStr = getString("A"); A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr); A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One); auto Func = make_unique<DIE>(dwarf::DW_TAG_subprogram); - DIEString FuncStr(&One, "func"); - DIEString FuncLinkage(&One, "_ZN1A4funcEv"); + DIEString FuncStr = getString("func"); + DIEString FuncLinkage = getString("_ZN1A4funcEv"); DIEInteger Two(2); Func->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One); Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr); @@ -557,10 +571,10 @@ TEST(DIEHashTest, MemberFuncFlag) { // const static int PI = -3; // }; // A a; -TEST(DIEHashTest, MemberSdata) { +TEST_F(DIEHashTest, MemberSdata) { DIE A(dwarf::DW_TAG_structure_type); DIEInteger One(1); - DIEString AStr(&One, "A"); + DIEString AStr = getString("A"); A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr); A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); @@ -568,7 +582,7 @@ TEST(DIEHashTest, MemberSdata) { DIEInteger Four(4); DIEInteger Five(5); - DIEString FStr(&One, "int"); + DIEString FStr = getString("int"); DIE IntTyDIE(dwarf::DW_TAG_base_type); IntTyDIE.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); IntTyDIE.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five); @@ -580,7 +594,7 @@ TEST(DIEHashTest, MemberSdata) { DIEEntry PITy(*PITyDIE); auto PI = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString PIStr(&One, "PI"); + DIEString PIStr = getString("PI"); DIEInteger Two(2); DIEInteger NegThree(-3); PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr); @@ -602,17 +616,17 @@ TEST(DIEHashTest, MemberSdata) { // const static float PI = 3.14; // }; // A a; -TEST(DIEHashTest, MemberBlock) { +TEST_F(DIEHashTest, MemberBlock) { DIE A(dwarf::DW_TAG_structure_type); DIEInteger One(1); - DIEString AStr(&One, "A"); + DIEString AStr = getString("A"); A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr); A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One); DIEInteger Four(4); - DIEString FStr(&One, "float"); + DIEString FStr = getString("float"); auto FloatTyDIE = make_unique<DIE>(dwarf::DW_TAG_base_type); FloatTyDIE->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Four); @@ -624,7 +638,7 @@ TEST(DIEHashTest, MemberBlock) { DIEEntry PITy(*PITyDIE); auto PI = make_unique<DIE>(dwarf::DW_TAG_member); - DIEString PIStr(&One, "PI"); + DIEString PIStr = getString("PI"); DIEInteger Two(2); PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr); PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); |