2016-07-14 02:38:20 +08:00
|
|
|
//===- llvm/unittest/CodeGen/DIEHashTest.cpp ------------------------------===//
|
2013-09-04 05:57:57 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-09-04 05:57:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../lib/CodeGen/AsmPrinter/DIEHash.h"
|
2020-09-17 13:47:38 +08:00
|
|
|
#include "TestAsmPrinter.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-06-06 19:06:56 +08:00
|
|
|
#include "llvm/CodeGen/DIE.h"
|
2015-05-25 00:40:47 +08:00
|
|
|
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
|
2013-09-04 05:57:57 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2020-09-17 13:47:38 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Testing/Support/Error.h"
|
2013-09-04 05:57:57 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2013-10-16 07:00:17 +08:00
|
|
|
|
|
|
|
namespace {
|
2015-05-25 00:40:47 +08:00
|
|
|
|
|
|
|
// Test fixture
|
|
|
|
class DIEHashTest : public testing::Test {
|
2015-06-26 07:46:41 +08:00
|
|
|
public:
|
|
|
|
BumpPtrAllocator Alloc;
|
|
|
|
|
|
|
|
private:
|
2015-05-25 00:40:47 +08:00
|
|
|
StringMap<DwarfStringPoolEntry> Pool;
|
2020-09-17 13:47:38 +08:00
|
|
|
std::unique_ptr<TestAsmPrinter> TestPrinter;
|
|
|
|
|
|
|
|
void setupTestPrinter() {
|
|
|
|
auto ExpectedTestPrinter = TestAsmPrinter::create(
|
|
|
|
sys::getDefaultTargetTriple(), /*DwarfVersion=*/4, dwarf::DWARF32);
|
|
|
|
ASSERT_THAT_EXPECTED(ExpectedTestPrinter, Succeeded());
|
|
|
|
TestPrinter = std::move(ExpectedTestPrinter.get());
|
|
|
|
}
|
2015-05-25 00:40:47 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
DIEString getString(StringRef S) {
|
|
|
|
DwarfStringPoolEntry Entry = {nullptr, 1, 1};
|
[DebugInfo] Reduce debug_str_offsets section size
Summary:
The accelerator tables use the debug_str section to store their strings.
However, they do not support the indirect method of access that is
available for the debug_info section (DW_FORM_strx et al.).
Currently our code is assuming that all strings can/will be referenced
indirectly, and puts all of them into the debug_str_offsets section.
This is generally true for regular (unsplit) dwarf, but in the DWO case,
most of the strings in the debug_str section will only be used from the
accelerator tables. Therefore the contents of the debug_str_offsets
section will be largely unused and bloating the main executable.
This patch rectifies this by teaching the DwarfStringPool to
differentiate between strings accessed directly and indirectly. When a
user inserts a string into the pool it has to declare whether that
string will be referenced directly or not. If at least one user requsts
indirect access, that string will be assigned an index ID and put into
debug_str_offsets table. Otherwise, the offset table is skipped.
This approach reduces the overall binary size (when compiled with
-gdwarf-5 -gsplit-dwarf) in my tests by about 2% (debug_str_offsets is
shrunk by 99%).
Reviewers: probinson, dblaikie, JDevlieghere
Subscribers: aprantl, mgrang, llvm-commits
Differential Revision: https://reviews.llvm.org/D49493
llvm-svn: 339122
2018-08-07 17:54:52 +08:00
|
|
|
return DIEString(DwarfStringPoolEntryRef(
|
|
|
|
*Pool.insert(std::make_pair(S, Entry)).first, Entry.isIndexed()));
|
2015-05-25 00:40:47 +08:00
|
|
|
}
|
2020-09-17 13:47:38 +08:00
|
|
|
|
|
|
|
AsmPrinter *getAsmPrinter() {
|
|
|
|
if (!TestPrinter)
|
|
|
|
setupTestPrinter();
|
|
|
|
return TestPrinter ? TestPrinter->getAP() : nullptr;
|
|
|
|
}
|
2015-05-25 00:40:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DIEHashTest, Data1) {
|
2013-09-04 05:57:57 +08:00
|
|
|
DIEHash Hash;
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Die = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
2013-09-29 19:29:20 +08:00
|
|
|
DIEInteger Size(4);
|
2015-06-26 07:46:41 +08:00
|
|
|
Die.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Size);
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = Hash.computeTypeSignature(Die);
|
2013-10-17 07:36:20 +08:00
|
|
|
ASSERT_EQ(0x1AFE116E83701108ULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// struct {};
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, TrivialType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-17 07:36:20 +08:00
|
|
|
DIEInteger One(1);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-17 07:36:20 +08:00
|
|
|
|
|
|
|
// Line and file number are ignored.
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-17 07:36:20 +08:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x715305ce6cfd9ad1ULL, MD5Res);
|
2013-09-04 05:57:57 +08:00
|
|
|
}
|
2013-10-17 08:10:34 +08:00
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// struct foo { };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, NamedType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-17 08:10:34 +08:00
|
|
|
DIEInteger One(1);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-17 08:10:34 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-17 08:10:34 +08:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xd566dbd2ca5265ffULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// namespace space { struct foo { }; }
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, NamespacedType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &CU = *DIE::get(Alloc, dwarf::DW_TAG_compile_unit);
|
2013-10-17 08:10:34 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Space = DIE::get(Alloc, dwarf::DW_TAG_namespace);
|
2013-10-17 08:10:34 +08:00
|
|
|
DIEInteger One(1);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString SpaceStr = getString("space");
|
2015-06-26 07:46:41 +08:00
|
|
|
Space->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, SpaceStr);
|
2013-10-17 08:10:34 +08:00
|
|
|
// DW_AT_declaration is ignored.
|
2015-06-26 07:46:41 +08:00
|
|
|
Space->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
2013-10-17 08:10:34 +08:00
|
|
|
// sibling?
|
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-17 08:10:34 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
DIE &N = *Foo;
|
|
|
|
Space->addChild(std::move(Foo));
|
|
|
|
CU.addChild(std::move(Space));
|
2013-10-17 08:10:34 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(N);
|
2013-10-17 08:10:34 +08:00
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res);
|
|
|
|
}
|
2013-10-18 06:07:09 +08:00
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// struct { int member; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, TypeWithMember) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-18 06:07:09 +08:00
|
|
|
DIEInteger Four(4);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
2013-10-18 06:07:09 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString IntStr = getString("int");
|
2015-06-26 07:46:41 +08:00
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
|
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
2013-10-18 06:07:09 +08:00
|
|
|
DIEInteger Five(5);
|
2015-06-26 07:46:41 +08:00
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
2013-10-18 06:07:09 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry IntRef(Int);
|
2014-04-26 04:00:34 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Member = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemberStr = getString("member");
|
2015-06-26 07:46:41 +08:00
|
|
|
Member->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemberStr);
|
2014-04-26 04:00:34 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Member->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
|
|
dwarf::DW_FORM_data1, Zero);
|
|
|
|
Member->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
2013-10-18 06:07:09 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Unnamed.addChild(std::move(Member));
|
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-18 06:07:09 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// struct foo { int mem1, mem2; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, ReusedType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-22 02:59:40 +08:00
|
|
|
DIEInteger Eight(8);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
|
|
|
DIEInteger Four(4);
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Int = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString IntStr = getString("int");
|
2015-06-26 07:46:41 +08:00
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, IntStr);
|
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
2014-04-26 04:00:34 +08:00
|
|
|
DIEInteger Five(5);
|
2015-06-26 07:46:41 +08:00
|
|
|
Int.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
2014-04-26 04:00:34 +08:00
|
|
|
|
|
|
|
DIEEntry IntRef(Int);
|
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem1 = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString Mem1Str = getString("mem1");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem1->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem1Str);
|
2013-10-22 02:59:40 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem1->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
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.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
Zero);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem1->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Unnamed.addChild(std::move(Mem1));
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem2 = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString Mem2Str = getString("mem2");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem2->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, Mem2Str);
|
|
|
|
Mem2->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
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.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
Four);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem2->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntRef);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Unnamed.addChild(std::move(Mem2));
|
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
2013-10-22 06:36:50 +08:00
|
|
|
// struct foo { static foo f; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, RecursiveType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-22 02:59:40 +08:00
|
|
|
DIEInteger One(1);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemStr = getString("mem");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRef(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
|
2013-10-22 02:59:40 +08:00
|
|
|
// DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
|
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 02:59:40 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 02:59:40 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0x73d8b25aef227b06ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 06:36:50 +08:00
|
|
|
|
|
|
|
// struct foo { foo *mem; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, Pointer) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-22 06:36:50 +08:00
|
|
|
DIEInteger Eight(8);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-22 06:36:50 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemStr = getString("mem");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
2013-10-22 06:36:50 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
Zero);
|
2013-10-22 06:36:50 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &FooPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRef(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRef);
|
2013-10-22 06:36:50 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooPtrRef(FooPtr);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooPtrRef);
|
2013-10-22 06:36:50 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 06:36:50 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 06:36:50 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0x74ea73862e8708d2ULL, MD5Res);
|
|
|
|
}
|
2013-10-22 07:06:19 +08:00
|
|
|
|
|
|
|
// struct foo { foo &mem; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, Reference) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-22 07:06:19 +08:00
|
|
|
DIEInteger Eight(8);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemStr = getString("mem");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
2013-10-22 07:06:19 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
Zero);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_reference_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooEntry(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRefRef(FooRef);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
FooRefRef);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0xa0b15f467ad4525bULL, MD5Res);
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct foo { foo &&mem; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, RValueReference) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-22 07:06:19 +08:00
|
|
|
DIEInteger Eight(8);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemStr = getString("mem");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
2013-10-22 07:06:19 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
Zero);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &FooRef = *DIE::get(Alloc, dwarf::DW_TAG_rvalue_reference_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRef.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooEntry(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRef.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &FooRefConst = *DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRefRef(FooRef);
|
2015-06-26 07:46:41 +08:00
|
|
|
FooRefConst.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
FooRefRef);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooRefConstRef(FooRefConst);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooRefConstRef);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-22 07:06:19 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-22 07:06:19 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
|
|
|
|
}
|
2013-10-23 02:14:41 +08:00
|
|
|
|
|
|
|
// struct foo { foo foo::*mem; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, PtrToMember) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-23 02:14:41 +08:00
|
|
|
DIEInteger Eight(8);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString MemStr = getString("mem");
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
DIEInteger Zero(0);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
Zero);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooEntry(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FooEntry);
|
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
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.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
FooEntry);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PtrToFooMemRef);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
|
|
|
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; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, PtrToMemberDeclDefMatch) {
|
2013-10-23 02:14:41 +08:00
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
|
|
|
DIEString BarStr = getString("bar");
|
|
|
|
DIEString MemStr = getString("mem");
|
2013-10-23 02:14:41 +08:00
|
|
|
uint64_t MD5ResDecl;
|
|
|
|
{
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
|
|
dwarf::DW_FORM_data1, Zero);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry BarEntry(Bar);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
BarEntry);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooEntry(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
|
|
dwarf::DW_FORM_ref4, FooEntry);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
PtrToFooMemRef);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
2013-10-23 02:14:41 +08:00
|
|
|
}
|
|
|
|
uint64_t MD5ResDef;
|
|
|
|
{
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
|
|
dwarf::DW_FORM_data1, Zero);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry BarEntry(Bar);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
BarEntry);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FooEntry(Foo);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
|
|
dwarf::DW_FORM_ref4, FooEntry);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
PtrToFooMemRef);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
2013-10-23 02:14:41 +08:00
|
|
|
}
|
|
|
|
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; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, PtrToMemberDeclDefMisMatch) {
|
2013-10-23 02:14:41 +08:00
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
|
|
|
DIEString BarStr = getString("bar");
|
|
|
|
DIEString MemStr = getString("mem");
|
2013-10-23 02:14:41 +08:00
|
|
|
uint64_t MD5ResDecl;
|
|
|
|
{
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
|
|
dwarf::DW_FORM_data1, Zero);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry BarEntry(Bar);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
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.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
BarEntry);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
|
|
dwarf::DW_FORM_ref4, BarEntry);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
PtrToFooMemRef);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
MD5ResDecl = DIEHash().computeTypeSignature(Foo);
|
2013-10-23 02:14:41 +08:00
|
|
|
}
|
|
|
|
uint64_t MD5ResDef;
|
|
|
|
{
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Bar = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, BarStr);
|
|
|
|
Bar.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location,
|
|
|
|
dwarf::DW_FORM_data1, Zero);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &PtrToFooMem = *DIE::get(Alloc, dwarf::DW_TAG_ptr_to_member_type);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry BarEntry(Bar);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
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.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
BarEntry);
|
2015-06-26 07:46:41 +08:00
|
|
|
PtrToFooMem.addValue(Alloc, dwarf::DW_AT_containing_type,
|
|
|
|
dwarf::DW_FORM_ref4, BarEntry);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PtrToFooMemRef(PtrToFooMem);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
PtrToFooMemRef);
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-23 02:14:41 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
MD5ResDef = DIEHash().computeTypeSignature(Foo);
|
2013-10-23 02:14:41 +08:00
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
}
|
2013-10-25 01:53:58 +08:00
|
|
|
|
|
|
|
// struct { } a;
|
|
|
|
// struct foo { decltype(a) mem; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, RefUnnamedType) {
|
2013-10-25 01:53:58 +08:00
|
|
|
DIEInteger Zero(0);
|
|
|
|
DIEInteger One(1);
|
|
|
|
DIEInteger Eight(8);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
|
|
|
DIEString MemStr = getString("mem");
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Foo = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Eight);
|
|
|
|
Foo.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Mem = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, MemStr);
|
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
|
|
|
|
Zero);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &UnnamedPtr = *DIE::get(Alloc, dwarf::DW_TAG_pointer_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
UnnamedPtr.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
|
|
|
|
Eight);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry UnnamedRef(Unnamed);
|
2015-06-26 07:46:41 +08:00
|
|
|
UnnamedPtr.addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4,
|
|
|
|
UnnamedRef);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry UnnamedPtrRef(UnnamedPtr);
|
2015-06-26 07:46:41 +08:00
|
|
|
Mem->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, UnnamedPtrRef);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Foo.addChild(std::move(Mem));
|
2013-10-25 01:53:58 +08:00
|
|
|
|
2013-10-25 02:29:03 +08:00
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Foo);
|
2013-10-25 01:53:58 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(0x954e026f01c02529ULL, MD5Res);
|
|
|
|
}
|
2013-10-26 02:38:43 +08:00
|
|
|
|
2014-02-01 04:02:55 +08:00
|
|
|
// struct { struct foo { }; };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, NestedType) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-26 02:38:43 +08:00
|
|
|
DIEInteger One(1);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-26 02:38:43 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Foo = DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FooStr = getString("foo");
|
2015-06-26 07:46:41 +08:00
|
|
|
Foo->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FooStr);
|
|
|
|
Foo->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-26 02:38:43 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Unnamed.addChild(std::move(Foo));
|
2013-10-26 02:38:43 +08:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xde8a3b7b43807f4aULL, MD5Res);
|
|
|
|
}
|
2013-10-26 04:04:25 +08:00
|
|
|
|
|
|
|
// struct { static void func(); };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, MemberFunc) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &Unnamed = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2013-10-26 04:04:25 +08:00
|
|
|
DIEInteger One(1);
|
2015-06-26 07:46:41 +08:00
|
|
|
Unnamed.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
2013-10-26 04:04:25 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FuncStr = getString("func");
|
2015-06-26 07:46:41 +08:00
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
|
2013-10-26 04:04:25 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
Unnamed.addChild(std::move(Func));
|
2013-10-26 04:04:25 +08:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
|
|
|
|
}
|
2014-02-01 04:02:58 +08:00
|
|
|
|
|
|
|
// struct A {
|
|
|
|
// static void func();
|
|
|
|
// };
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, MemberFuncFlag) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2014-02-01 04:02:58 +08:00
|
|
|
DIEInteger One(1);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString AStr = getString("A");
|
2015-06-26 07:46:41 +08:00
|
|
|
A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
2014-02-01 04:02:58 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
auto Func = DIE::get(Alloc, dwarf::DW_TAG_subprogram);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FuncStr = getString("func");
|
|
|
|
DIEString FuncLinkage = getString("_ZN1A4funcEv");
|
2014-02-01 04:02:58 +08:00
|
|
|
DIEInteger Two(2);
|
2015-06-26 07:46:41 +08:00
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FuncStr);
|
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp,
|
|
|
|
FuncLinkage);
|
|
|
|
Func->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
2014-02-01 04:02:58 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
A.addChild(std::move(Func));
|
2014-02-01 04:02:58 +08:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
|
|
|
|
// The exact same hash GCC produces for this DIE.
|
|
|
|
ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
|
|
|
|
}
|
2014-02-20 08:54:40 +08:00
|
|
|
|
|
|
|
// Derived from:
|
|
|
|
// struct A {
|
2014-02-20 08:59:17 +08:00
|
|
|
// const static int PI = -3;
|
2014-02-20 08:54:40 +08:00
|
|
|
// };
|
|
|
|
// A a;
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, MemberSdata) {
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2014-02-20 08:54:40 +08:00
|
|
|
DIEInteger One(1);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString AStr = getString("A");
|
2015-06-26 07:46:41 +08:00
|
|
|
A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
2014-02-20 08:54:40 +08:00
|
|
|
|
|
|
|
DIEInteger Four(4);
|
|
|
|
DIEInteger Five(5);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FStr = getString("int");
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &IntTyDIE = *DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
IntTyDIE.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, Four);
|
|
|
|
IntTyDIE.addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Five);
|
|
|
|
IntTyDIE.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
2014-02-20 08:54:40 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry IntTy(IntTyDIE);
|
2015-06-26 07:52:10 +08:00
|
|
|
auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IntTy);
|
2014-02-20 08:54:40 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PITy(*PITyDIE);
|
2015-06-26 07:52:10 +08:00
|
|
|
auto PI = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString PIStr = getString("PI");
|
2014-02-20 08:54:40 +08:00
|
|
|
DIEInteger Two(2);
|
|
|
|
DIEInteger NegThree(-3);
|
2015-06-26 07:46:41 +08:00
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, NegThree);
|
2014-02-20 08:54:40 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
A.addChild(std::move(PI));
|
2014-02-20 08:54:40 +08:00
|
|
|
|
|
|
|
uint64_t MD5Res = DIEHash().computeTypeSignature(A);
|
|
|
|
ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
|
|
|
|
}
|
2014-02-20 10:50:45 +08:00
|
|
|
|
|
|
|
// Derived from:
|
|
|
|
// struct A {
|
|
|
|
// const static float PI = 3.14;
|
|
|
|
// };
|
|
|
|
// A a;
|
2015-05-25 00:40:47 +08:00
|
|
|
TEST_F(DIEHashTest, MemberBlock) {
|
2020-09-17 13:47:38 +08:00
|
|
|
if (!this->getAsmPrinter())
|
2021-05-21 11:31:56 +08:00
|
|
|
GTEST_SKIP();
|
2020-09-17 13:47:38 +08:00
|
|
|
|
2015-06-26 07:52:10 +08:00
|
|
|
DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type);
|
2014-02-20 10:50:45 +08:00
|
|
|
DIEInteger One(1);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString AStr = getString("A");
|
2015-06-26 07:46:41 +08:00
|
|
|
A.addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, AStr);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
A.addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, One);
|
2014-02-20 10:50:45 +08:00
|
|
|
|
|
|
|
DIEInteger Four(4);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString FStr = getString("float");
|
2015-06-26 07:52:10 +08:00
|
|
|
auto FloatTyDIE = DIE::get(Alloc, dwarf::DW_TAG_base_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
FloatTyDIE->addValue(Alloc, dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1,
|
|
|
|
Four);
|
|
|
|
FloatTyDIE->addValue(Alloc, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
|
|
|
Four);
|
|
|
|
FloatTyDIE->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, FStr);
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry FloatTy(*FloatTyDIE);
|
2015-06-26 07:52:10 +08:00
|
|
|
auto PITyDIE = DIE::get(Alloc, dwarf::DW_TAG_const_type);
|
2015-06-26 07:46:41 +08:00
|
|
|
PITyDIE->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, FloatTy);
|
2014-02-20 10:50:45 +08:00
|
|
|
|
2014-04-26 03:33:43 +08:00
|
|
|
DIEEntry PITy(*PITyDIE);
|
2015-06-26 07:52:10 +08:00
|
|
|
auto PI = DIE::get(Alloc, dwarf::DW_TAG_member);
|
2015-05-25 00:40:47 +08:00
|
|
|
DIEString PIStr = getString("PI");
|
2014-02-20 10:50:45 +08:00
|
|
|
DIEInteger Two(2);
|
2015-06-26 07:46:41 +08:00
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, PIStr);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, One);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, Two);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, PITy);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, One);
|
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present,
|
|
|
|
One);
|
2014-02-20 10:50:45 +08:00
|
|
|
|
2014-04-26 01:07:55 +08:00
|
|
|
DIEBlock PIBlock;
|
2014-02-20 10:50:45 +08:00
|
|
|
DIEInteger Blk1(0xc3);
|
|
|
|
DIEInteger Blk2(0xf5);
|
|
|
|
DIEInteger Blk3(0x48);
|
|
|
|
DIEInteger Blk4(0x40);
|
|
|
|
|
2015-06-26 07:46:41 +08:00
|
|
|
PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk1);
|
|
|
|
PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk2);
|
|
|
|
PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk3);
|
|
|
|
PIBlock.addValue(Alloc, (dwarf::Attribute)0, dwarf::DW_FORM_data1, Blk4);
|
2014-02-20 10:50:45 +08:00
|
|
|
|
2015-06-26 07:46:41 +08:00
|
|
|
PI->addValue(Alloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_block1,
|
|
|
|
&PIBlock);
|
2014-02-20 10:50:45 +08:00
|
|
|
|
2014-04-26 04:00:34 +08:00
|
|
|
A.addChild(std::move(PI));
|
2014-02-20 10:50:45 +08:00
|
|
|
|
2020-09-17 13:47:38 +08:00
|
|
|
uint64_t MD5Res = DIEHash(this->getAsmPrinter()).computeTypeSignature(A);
|
2014-02-20 10:50:45 +08:00
|
|
|
ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
|
|
|
|
}
|
2013-09-04 05:57:57 +08:00
|
|
|
}
|