mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
09fe4bf794
This reverts commit r238350, effectively reapplying r238349 after fixing (all?) the problems, all somehow related to how I was using `AlignedArrayCharUnion<>` inside `DIEValue`: - MSVC can only handle `sizeof()` on types, not values. Change the assert. - GCC doesn't know the `is_trivially_copyable` type trait. Instead of asserting it, add destructors. - Call placement new even when constructing POD (i.e., the pointers). - Instead of copying the char buffer, copy the casted classes. I've left in a couple of `static_assert`s that I think both MSVC and GCC know how to handle. If the bots disagree with me, I'll remove them. - Check that the constructed type is either standard layout or a pointer. This protects against a programming error: we really want the "small" `DIEValue`s to be small and simple, so don't accidentally change them not to be. - Similarly, check that the size of the buffer is no bigger than a `uint64_t` or a pointer. (I thought checking against `sizeof(uint64_t)` would be good enough, but Chandler suggested that pointers might sometimes be bigger than that in the context of sanitizers.) I've also committed r238359 in the meantime, which introduces a DIEValue.def to simplify dispatching between the various types (thanks to a review comment by David Blaikie). Without that, this commit would be almost unintelligible. Here's the original commit message: -- Change `DIEValue` to be stored/passed/etc. by value, instead of reference. It's now a discriminated union, with a `Val` field storing the actual type. The classes that used to inherit from `DIEValue` no longer do. There are two categories of these: - Small values fit in a single pointer and are stored by value. - Large values require auxiliary storage, and are stored by reference. The only non-mechanical change is to tools/dsymutil/DwarfLinker.cpp. It was relying on `DIEInteger`s being passed around by reference, so I replaced that assumption with a `PatchLocation` type that stores a safe reference to where the `DIEInteger` lives instead. This commit causes a temporary regression in memory usage, since I've left merging `DIEAbbrevData` into `DIEValue` for a follow-up commit. I measured an increase from 845 MB to 879 MB, around 3.9%. The follow-up drops it lower than the starting point, and I've only recently brought the memory this low anyway, so I'm committing these changes separately to keep them incremental. (I also considered swapping the commits, but the other one first would cause a lot more code churn.) (I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`; see r236629 for details.) -- git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238362 91177308-0d34-0410-b5e6-96231b3b80d8
669 lines
24 KiB
C++
669 lines
24 KiB
C++
//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#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"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
// 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);
|
|
Die.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size);
|
|
uint64_t MD5Res = Hash.computeTypeSignature(Die);
|
|
ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
|
|
}
|
|
|
|
// struct {};
|
|
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);
|
|
|
|
// Line and file number are ignored.
|
|
Unnamed.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
Unnamed.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { };
|
|
TEST_F(DIEHashTest, NamedType) {
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
DIEInteger One(1);
|
|
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);
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
|
|
}
|
|
|
|
// namespace space { struct foo { }; }
|
|
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 = 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 = 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);
|
|
|
|
DIE &N = *Foo;
|
|
Space->addChild(std::move(Foo));
|
|
CU.addChild(std::move(Space));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(N);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
|
|
}
|
|
|
|
// struct { int member; };
|
|
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 = 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);
|
|
Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
|
|
|
DIEEntry IntRef(Int);
|
|
|
|
auto Member = make_unique<DIE>(dwarf::DW_TAG_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,
|
|
Zero);
|
|
Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
|
|
|
Unnamed.addChild(std::move(Member));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { int mem1, mem2; };
|
|
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 = 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);
|
|
Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
|
|
|
DIEEntry IntRef(Int);
|
|
|
|
auto Mem1 = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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,
|
|
Zero);
|
|
Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
|
|
|
Unnamed.addChild(std::move(Mem1));
|
|
|
|
auto Mem2 = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
|
|
|
Unnamed.addChild(std::move(Mem2));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { static foo f; };
|
|
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 = getString("foo");
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
// DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { foo *mem; };
|
|
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 = getString("foo");
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
|
|
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(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { foo &mem; };
|
|
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 = getString("foo");
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
|
|
DIE FooRef(dwarf::DW_TAG_reference_type);
|
|
FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
DIEEntry FooEntry(Foo);
|
|
FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
|
|
|
DIE FooRefConst(dwarf::DW_TAG_const_type);
|
|
DIEEntry FooRefRef(FooRef);
|
|
FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefRef);
|
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { foo &&mem; };
|
|
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 = getString("foo");
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
|
|
DIE FooRef(dwarf::DW_TAG_rvalue_reference_type);
|
|
FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
DIEEntry FooEntry(Foo);
|
|
FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
|
|
|
DIE FooRefConst(dwarf::DW_TAG_const_type);
|
|
DIEEntry FooRefRef(FooRef);
|
|
FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefRef);
|
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
|
|
}
|
|
|
|
// struct foo { foo foo::*mem; };
|
|
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 = getString("foo");
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
|
DIEEntry FooEntry(Foo);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
FooEntry);
|
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res);
|
|
}
|
|
|
|
// Check that the hash for a pointer-to-member matches regardless of whether the
|
|
// pointed-to type is a declaration or a definition.
|
|
//
|
|
// struct bar; // { };
|
|
// struct foo { bar foo::*mem; };
|
|
TEST_F(DIEHashTest, PtrToMemberDeclDefMatch) {
|
|
DIEInteger Zero(0);
|
|
DIEInteger One(1);
|
|
DIEInteger Eight(8);
|
|
DIEString FooStr = getString("foo");
|
|
DIEString BarStr = getString("bar");
|
|
DIEString MemStr = getString("mem");
|
|
uint64_t MD5ResDecl;
|
|
{
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
Zero);
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
|
DIEEntry BarEntry(Bar);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
|
|
DIEEntry FooEntry(Foo);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
FooEntry);
|
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
|
}
|
|
uint64_t MD5ResDef;
|
|
{
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
Zero);
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
|
DIEEntry BarEntry(Bar);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
|
|
DIEEntry FooEntry(Foo);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
FooEntry);
|
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
|
}
|
|
ASSERT_EQ(MD5ResDef, MD5ResDecl);
|
|
}
|
|
|
|
// Check that the hash for a pointer-to-member matches regardless of whether the
|
|
// pointed-to type is a declaration or a definition.
|
|
//
|
|
// struct bar; // { };
|
|
// struct foo { bar bar::*mem; };
|
|
TEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) {
|
|
DIEInteger Zero(0);
|
|
DIEInteger One(1);
|
|
DIEInteger Eight(8);
|
|
DIEString FooStr = getString("foo");
|
|
DIEString BarStr = getString("bar");
|
|
DIEString MemStr = getString("mem");
|
|
uint64_t MD5ResDecl;
|
|
{
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
Zero);
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
|
DIEEntry BarEntry(Bar);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
BarEntry);
|
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
|
}
|
|
uint64_t MD5ResDef;
|
|
{
|
|
DIE Bar(dwarf::DW_TAG_structure_type);
|
|
Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
Zero);
|
|
|
|
DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
|
|
DIEEntry BarEntry(Bar);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, BarEntry);
|
|
PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
|
BarEntry);
|
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
|
}
|
|
// FIXME: This seems to be a bug in the DWARF type hashing specification that
|
|
// only uses the brief name hashing for types referenced via DW_AT_type. In
|
|
// this case the type is referenced via DW_AT_containing_type and full hashing
|
|
// causes a hash to differ when the containing type is a declaration in one TU
|
|
// and a definition in another.
|
|
ASSERT_NE(MD5ResDef, MD5ResDecl);
|
|
}
|
|
|
|
// struct { } a;
|
|
// struct foo { decltype(a) mem; };
|
|
TEST_F(DIEHashTest, RefUnnamedType) {
|
|
DIEInteger Zero(0);
|
|
DIEInteger One(1);
|
|
DIEInteger Eight(8);
|
|
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);
|
|
|
|
DIE Foo(dwarf::DW_TAG_structure_type);
|
|
Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
auto Mem = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, Zero);
|
|
|
|
DIE UnnamedPtr(dwarf::DW_TAG_pointer_type);
|
|
UnnamedPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
DIEEntry UnnamedRef(Unnamed);
|
|
UnnamedPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedRef);
|
|
|
|
DIEEntry UnnamedPtrRef(UnnamedPtr);
|
|
Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedPtrRef);
|
|
|
|
Foo.addChild(std::move(Mem));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
|
|
|
ASSERT_EQ(0x954e026f01c02529ULL, MD5Res);
|
|
}
|
|
|
|
// struct { struct foo { }; };
|
|
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 = 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);
|
|
|
|
Unnamed.addChild(std::move(Foo));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res);
|
|
}
|
|
|
|
// struct { static void func(); };
|
|
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 = getString("func");
|
|
Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
|
|
|
|
Unnamed.addChild(std::move(Func));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
|
|
}
|
|
|
|
// struct A {
|
|
// static void func();
|
|
// };
|
|
TEST_F(DIEHashTest, MemberFuncFlag) {
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
DIEInteger One(1);
|
|
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 = 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);
|
|
Func->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
Func->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, FuncLinkage);
|
|
Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
|
|
|
|
A.addChild(std::move(Func));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
|
|
}
|
|
|
|
// Derived from:
|
|
// struct A {
|
|
// const static int PI = -3;
|
|
// };
|
|
// A a;
|
|
TEST_F(DIEHashTest, MemberSdata) {
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
DIEInteger One(1);
|
|
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);
|
|
DIEInteger Five(5);
|
|
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);
|
|
IntTyDIE.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
|
|
|
DIEEntry IntTy(IntTyDIE);
|
|
auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
|
|
PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntTy);
|
|
|
|
DIEEntry PITy(*PITyDIE);
|
|
auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
DIEString PIStr = getString("PI");
|
|
DIEInteger Two(2);
|
|
DIEInteger NegThree(-3);
|
|
PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
|
|
PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
|
|
PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, NegThree);
|
|
|
|
A.addChild(std::move(PI));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
|
|
}
|
|
|
|
// Derived from:
|
|
// struct A {
|
|
// const static float PI = 3.14;
|
|
// };
|
|
// A a;
|
|
TEST_F(DIEHashTest, MemberBlock) {
|
|
DIE A(dwarf::DW_TAG_structure_type);
|
|
DIEInteger One(1);
|
|
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 = 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);
|
|
FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
|
|
|
DIEEntry FloatTy(*FloatTyDIE);
|
|
auto PITyDIE = make_unique<DIE>(dwarf::DW_TAG_const_type);
|
|
PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FloatTy);
|
|
|
|
DIEEntry PITy(*PITyDIE);
|
|
auto PI = make_unique<DIE>(dwarf::DW_TAG_member);
|
|
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);
|
|
PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, One);
|
|
|
|
DIEBlock PIBlock;
|
|
DIEInteger Blk1(0xc3);
|
|
DIEInteger Blk2(0xf5);
|
|
DIEInteger Blk3(0x48);
|
|
DIEInteger Blk4(0x40);
|
|
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk1);
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk2);
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk3);
|
|
PIBlock.addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk4);
|
|
|
|
PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, &PIBlock);
|
|
|
|
A.addChild(std::move(PI));
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
|
|
}
|
|
}
|