summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-07-26 13:16:06 +0000
committerPavel Labath <labath@google.com>2018-07-26 13:16:06 +0000
commit99cfb5c8a747a79c4be2ff37d2bcacd8a6b0260b (patch)
treed9672881c2c443c9805b239740ff1d9c8b29d432 /unittests
parent4f48c840d005ea5af3e1e2dec7febe739f35f479 (diff)
dwarfgen: Don't create an AsmPrinter with an invalid ObjFile lowering
The AsmPrinter created in the tests contained an uninitialized TargetLoweringObjectFile. Things mostly worked regardless, because we used a separate instance of that class to specify sections to emit. This rearanges the object construction order so that we can avoid creating two lowering objects. Instead, we properly initialize the object in the AsmPrinter, and have the DWARF generator store a pointer to it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338026 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/DebugInfo/DWARF/DwarfGenerator.cpp30
-rw-r--r--unittests/DebugInfo/DWARF/DwarfGenerator.h4
2 files changed, 18 insertions, 16 deletions
diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
index b93b0cc9bf9..4f4a7375eaa 100644
--- a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -30,6 +30,7 @@
#include "llvm/PassAnalysisSupport.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
@@ -372,10 +373,6 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
return make_error<StringError>("no asm info for target " + TripleName,
inconvertibleErrorCode());
- MOFI.reset(new MCObjectFileInfo);
- MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
- MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
-
MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
if (!MSTI)
return make_error<StringError>("no subtarget info for target " + TripleName,
@@ -393,6 +390,16 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
TripleName,
inconvertibleErrorCode());
+ TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
+ None));
+ if (!TM)
+ return make_error<StringError>("no target machine for target " + TripleName,
+ inconvertibleErrorCode());
+
+ TLOF = TM->getObjFileLowering();
+ MC.reset(new MCContext(MAI.get(), MRI.get(), TLOF));
+ TLOF->Initialize(*MC, *TM);
+
MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC);
if (!MCE)
return make_error<StringError>("no code emitter for target " + TripleName,
@@ -410,13 +417,8 @@ llvm::Error dwarfgen::Generator::init(Triple TheTriple, uint16_t V) {
TripleName,
inconvertibleErrorCode());
- // Finally create the AsmPrinter we'll use to emit the DIEs.
- TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
- None));
- if (!TM)
- return make_error<StringError>("no target machine for target " + TripleName,
- inconvertibleErrorCode());
+ // Finally create the AsmPrinter we'll use to emit the DIEs.
Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
if (!Asm)
return make_error<StringError>("no asm printer for target " + TripleName,
@@ -447,9 +449,9 @@ StringRef dwarfgen::Generator::generate() {
SecOffset += CUOffset;
CU->setLength(CUOffset - 4);
}
- Abbreviations.Emit(Asm.get(), MOFI->getDwarfAbbrevSection());
- StringPool->emit(*Asm, MOFI->getDwarfStrSection());
- MS->SwitchSection(MOFI->getDwarfInfoSection());
+ Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection());
+ StringPool->emit(*Asm, TLOF->getDwarfStrSection());
+ MS->SwitchSection(TLOF->getDwarfInfoSection());
for (auto &CU : CompileUnits) {
uint16_t Version = CU->getVersion();
auto Length = CU->getLength();
@@ -468,7 +470,7 @@ StringRef dwarfgen::Generator::generate() {
Asm->emitDwarfDIE(*CU->getUnitDIE().Die);
}
- MS->SwitchSection(MOFI->getDwarfLineSection());
+ MS->SwitchSection(TLOF->getDwarfLineSection());
for (auto &LT : LineTables)
LT->generate(*MC, *Asm);
diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.h b/unittests/DebugInfo/DWARF/DwarfGenerator.h
index 6d41cb53f2c..72cb0696b97 100644
--- a/unittests/DebugInfo/DWARF/DwarfGenerator.h
+++ b/unittests/DebugInfo/DWARF/DwarfGenerator.h
@@ -36,11 +36,11 @@ class MCCodeEmitter;
class MCContext;
struct MCDwarfLineTableParams;
class MCInstrInfo;
-class MCObjectFileInfo;
class MCRegisterInfo;
class MCStreamer;
class MCSubtargetInfo;
class raw_fd_ostream;
+class TargetLoweringObjectFile;
class TargetMachine;
class Triple;
@@ -227,7 +227,6 @@ private:
class Generator {
std::unique_ptr<MCRegisterInfo> MRI;
std::unique_ptr<MCAsmInfo> MAI;
- std::unique_ptr<MCObjectFileInfo> MOFI;
std::unique_ptr<MCContext> MC;
MCAsmBackend *MAB; // Owned by MCStreamer
std::unique_ptr<MCInstrInfo> MII;
@@ -235,6 +234,7 @@ class Generator {
MCCodeEmitter *MCE; // Owned by MCStreamer
MCStreamer *MS; // Owned by AsmPrinter
std::unique_ptr<TargetMachine> TM;
+ TargetLoweringObjectFile *TLOF; // Owned by TargetMachine;
std::unique_ptr<AsmPrinter> Asm;
BumpPtrAllocator Allocator;
std::unique_ptr<DwarfStringPool> StringPool; // Entries owned by Allocator.