1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[AMDGPU][llvm-objdump] Fix memory leak in recent commit

Hopefully stops sanitizer fail in AMDGPU llvm-objdump test.

Change-Id: I7331151d1cb65292bd06b6ae283349fe7231cf6b
This commit is contained in:
Tim Renouf 2021-04-26 18:49:33 +01:00
parent 91e09faea4
commit 3d2965b9ee

View File

@ -975,11 +975,11 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, const MCInstrAnalysis *MIA,
// Create an MCSymbolizer for the target and add it to the MCDisassembler. // Create an MCSymbolizer for the target and add it to the MCDisassembler.
// This is currently only used on AMDGPU, and assumes the format of the // This is currently only used on AMDGPU, and assumes the format of the
// void * argument passed to AMDGPU's createMCSymbolizer. // void * argument passed to AMDGPU's createMCSymbolizer.
static void addSymbolizer(MCContext &Ctx, const Target *Target, static void addSymbolizer(
StringRef TripleName, MCDisassembler *DisAsm, MCContext &Ctx, const Target *Target, StringRef TripleName,
uint64_t SectionAddr, ArrayRef<uint8_t> Bytes, MCDisassembler *DisAsm, uint64_t SectionAddr, ArrayRef<uint8_t> Bytes,
SectionSymbolsTy &Symbols, SectionSymbolsTy &Symbols,
std::vector<std::string *> &SynthesizedLabelNames) { std::vector<std::unique_ptr<std::string>> &SynthesizedLabelNames) {
std::unique_ptr<MCRelocationInfo> RelInfo( std::unique_ptr<MCRelocationInfo> RelInfo(
Target->createMCRelocationInfo(TripleName, Ctx)); Target->createMCRelocationInfo(TripleName, Ctx));
@ -1015,8 +1015,9 @@ static void addSymbolizer(MCContext &Ctx, const Target *Target,
LabelAddrs.begin()); LabelAddrs.begin());
// Add the labels. // Add the labels.
for (unsigned LabelNum = 0; LabelNum != LabelAddrs.size(); ++LabelNum) { for (unsigned LabelNum = 0; LabelNum != LabelAddrs.size(); ++LabelNum) {
SynthesizedLabelNames.push_back( std::unique_ptr<std::string> Name(new std::string);
new std::string((Twine("L") + Twine(LabelNum)).str())); *Name = (Twine("L") + Twine(LabelNum)).str();
SynthesizedLabelNames.push_back(std::move(Name));
Symbols.push_back(SymbolInfoTy( Symbols.push_back(SymbolInfoTy(
LabelAddrs[LabelNum], *SynthesizedLabelNames.back(), ELF::STT_NOTYPE)); LabelAddrs[LabelNum], *SynthesizedLabelNames.back(), ELF::STT_NOTYPE));
} }
@ -1193,7 +1194,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
ArrayRef<uint8_t> Bytes = arrayRefFromStringRef( ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(
unwrapOrError(Section.getContents(), Obj->getFileName())); unwrapOrError(Section.getContents(), Obj->getFileName()));
std::vector<std::string *> SynthesizedLabelNames; std::vector<std::unique_ptr<std::string>> SynthesizedLabelNames;
if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) { if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
// AMDGPU disassembler uses symbolizer for printing labels // AMDGPU disassembler uses symbolizer for printing labels
addSymbolizer(Ctx, TheTarget, TripleName, DisAsm, SectionAddr, Bytes, addSymbolizer(Ctx, TheTarget, TripleName, DisAsm, SectionAddr, Bytes,