From 2fc6c9d1e983e1efeafc610d3e5ca3138f64e5d8 Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Thu, 17 Sep 2020 12:47:38 +0700 Subject: [PATCH] [DebugInfo] Simplify DIEInteger::SizeOf(). An AsmPrinter should always be provided to the method because some forms depend on its parameters. The only place in the codebase which passed a nullptr value was found in the unit tests, so the patch updates it to use some dummy AsmPrinter instead. Differential Revision: https://reviews.llvm.org/D85293 --- lib/CodeGen/AsmPrinter/DIE.cpp | 8 ++++---- unittests/CodeGen/DIEHashTest.cpp | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DIE.cpp b/lib/CodeGen/AsmPrinter/DIE.cpp index 9b074c89aa9..39b0b027c76 100644 --- a/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/lib/CodeGen/AsmPrinter/DIE.cpp @@ -428,10 +428,10 @@ void DIEInteger::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const { /// SizeOf - Determine size of integer value in bytes. /// unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { - dwarf::FormParams Params = {0, 0, dwarf::DWARF32}; - if (AP) - Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()), - AP->OutStreamer->getContext().getDwarfFormat()}; + assert(AP && "AsmPrinter is required to set FormParams"); + dwarf::FormParams Params = {AP->getDwarfVersion(), + uint8_t(AP->getPointerSize()), + AP->OutStreamer->getContext().getDwarfFormat()}; if (Optional FixedSize = dwarf::getFixedFormByteSize(Form, Params)) return *FixedSize; diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp index 649e13208f0..03bb7de5a0a 100644 --- a/unittests/CodeGen/DIEHashTest.cpp +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -7,12 +7,15 @@ //===----------------------------------------------------------------------===// #include "../lib/CodeGen/AsmPrinter/DIEHash.h" +#include "TestAsmPrinter.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/DIE.h" #include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Format.h" +#include "llvm/Support/Host.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" using namespace llvm; @@ -26,6 +29,14 @@ public: private: StringMap Pool; + std::unique_ptr TestPrinter; + + void setupTestPrinter() { + auto ExpectedTestPrinter = TestAsmPrinter::create( + sys::getDefaultTargetTriple(), /*DwarfVersion=*/4, dwarf::DWARF32); + ASSERT_THAT_EXPECTED(ExpectedTestPrinter, Succeeded()); + TestPrinter = std::move(ExpectedTestPrinter.get()); + } public: DIEString getString(StringRef S) { @@ -33,6 +44,12 @@ public: return DIEString(DwarfStringPoolEntryRef( *Pool.insert(std::make_pair(S, Entry)).first, Entry.isIndexed())); } + + AsmPrinter *getAsmPrinter() { + if (!TestPrinter) + setupTestPrinter(); + return TestPrinter ? TestPrinter->getAP() : nullptr; + } }; TEST_F(DIEHashTest, Data1) { @@ -644,6 +661,10 @@ TEST_F(DIEHashTest, MemberSdata) { // }; // A a; TEST_F(DIEHashTest, MemberBlock) { + if (!this->getAsmPrinter()) + // TODO: Use GTEST_SKIP() when GTest is updated to version 1.10.0 + return; + DIE &A = *DIE::get(Alloc, dwarf::DW_TAG_structure_type); DIEInteger One(1); DIEString AStr = getString("A"); @@ -692,7 +713,7 @@ TEST_F(DIEHashTest, MemberBlock) { A.addChild(std::move(PI)); - uint64_t MD5Res = DIEHash().computeTypeSignature(A); + uint64_t MD5Res = DIEHash(this->getAsmPrinter()).computeTypeSignature(A); ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res); } }