mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
[MC] Fix memory leak when allocating MCInst with bump allocator
Adds the function createMCInst() to MCContext that creates a MCInst using a typed bump alloctor. MCInst contains a SmallVector<MCOperand, 8>. The SmallVector is POD only for <= 8 operands. The default untyped bump pointer allocator of MCContext does not delete the MCInst, so if the SmallVector grows, it's a leak. This fixes https://bugs.llvm.org/show_bug.cgi?id=46900.
This commit is contained in:
parent
c2ae55c000
commit
1fccd57ea4
@ -97,6 +97,7 @@ namespace llvm {
|
||||
SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
|
||||
SpecificBumpPtrAllocator<MCSectionWasm> WasmAllocator;
|
||||
SpecificBumpPtrAllocator<MCSectionXCOFF> XCOFFAllocator;
|
||||
SpecificBumpPtrAllocator<MCInst> MCInstAllocator;
|
||||
|
||||
/// Bindings of names to symbols.
|
||||
SymbolTable Symbols;
|
||||
@ -380,6 +381,11 @@ namespace llvm {
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name McInst Management
|
||||
|
||||
/// Create and return a new MC instruction.
|
||||
MCInst *createMCInst();
|
||||
|
||||
/// \name Symbol Management
|
||||
/// @{
|
||||
|
||||
|
@ -90,6 +90,7 @@ void MCContext::reset() {
|
||||
ELFAllocator.DestroyAll();
|
||||
MachOAllocator.DestroyAll();
|
||||
XCOFFAllocator.DestroyAll();
|
||||
MCInstAllocator.DestroyAll();
|
||||
|
||||
MCSubtargetAllocator.DestroyAll();
|
||||
InlineAsmUsedLabelNames.clear();
|
||||
@ -126,6 +127,14 @@ void MCContext::reset() {
|
||||
HadError = false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// MCInst Management
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MCInst *MCContext::createMCInst() {
|
||||
return new (MCInstAllocator.Allocate()) MCInst;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Symbol Manipulation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -641,7 +641,7 @@ bool HexagonAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
||||
return true;
|
||||
return finishBundle(IDLoc, Out);
|
||||
}
|
||||
MCInst *SubInst = new (getParser().getContext()) MCInst;
|
||||
MCInst *SubInst = getParser().getContext().createMCInst();
|
||||
if (matchOneInstruction(*SubInst, IDLoc, Operands, ErrorInfo,
|
||||
MatchingInlineAsm)) {
|
||||
if (InBrackets)
|
||||
|
@ -175,7 +175,7 @@ DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
while (Result == Success && !Complete) {
|
||||
if (Bytes.size() < HEXAGON_INSTR_SIZE)
|
||||
return MCDisassembler::Fail;
|
||||
MCInst *Inst = new (getContext()) MCInst;
|
||||
MCInst *Inst = getContext().createMCInst();
|
||||
Result = getSingleInstruction(*Inst, MI, Bytes, Address, cs, Complete);
|
||||
MI.addOperand(MCOperand::createInst(Inst));
|
||||
Size += HEXAGON_INSTR_SIZE;
|
||||
@ -384,8 +384,8 @@ DecodeStatus HexagonDisassembler::getSingleInstruction(MCInst &MI, MCInst &MCB,
|
||||
break;
|
||||
}
|
||||
MI.setOpcode(Hexagon::DuplexIClass0 + duplexIClass);
|
||||
MCInst *MILow = new (getContext()) MCInst;
|
||||
MCInst *MIHigh = new (getContext()) MCInst;
|
||||
MCInst *MILow = getContext().createMCInst();
|
||||
MCInst *MIHigh = getContext().createMCInst();
|
||||
auto TmpExtender = CurrentExtender;
|
||||
CurrentExtender =
|
||||
nullptr; // constant extenders in duplex must always be in slot 1
|
||||
|
@ -104,7 +104,7 @@ void llvm::HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
|
||||
HexagonMCInstrInfo::setOuterLoop(MCB);
|
||||
return;
|
||||
}
|
||||
MCInst *MCI = new (AP.OutContext) MCInst;
|
||||
MCInst *MCI = AP.OutContext.createMCInst();
|
||||
MCI->setOpcode(MI->getOpcode());
|
||||
assert(MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode()) &&
|
||||
"MCI opcode should have been set on construction");
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
|
||||
void setExtender(MCContext &Context) const {
|
||||
if (Extender == nullptr)
|
||||
const_cast<HexagonAsmBackend *>(this)->Extender = new (Context) MCInst;
|
||||
const_cast<HexagonAsmBackend *>(this)->Extender = Context.createMCInst();
|
||||
}
|
||||
|
||||
MCInst *takeExtender() const {
|
||||
@ -736,7 +736,7 @@ public:
|
||||
auto &Inst = const_cast<MCInst &>(RF.getInst());
|
||||
while (Size > 0 &&
|
||||
HexagonMCInstrInfo::bundleSize(Inst) < MaxPacketSize) {
|
||||
MCInst *Nop = new (Context) MCInst;
|
||||
MCInst *Nop = Context.createMCInst();
|
||||
Nop->setOpcode(Hexagon::A2_nop);
|
||||
Inst.addOperand(MCOperand::createInst(Nop));
|
||||
Size -= 4;
|
||||
|
@ -210,7 +210,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
case Hexagon::A2_tfrsi:
|
||||
Rt = L.getOperand(0);
|
||||
compoundOpcode = J4_jumpseti;
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
|
||||
CompoundInsn->addOperand(Rt);
|
||||
@ -223,7 +223,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
Rs = L.getOperand(1);
|
||||
|
||||
compoundOpcode = J4_jumpsetr;
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rt);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
@ -237,7 +237,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
Rt = L.getOperand(2);
|
||||
|
||||
compoundOpcode = cmpeqBitOpcode[getCompoundOp(R)];
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(Rt);
|
||||
@ -250,7 +250,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
Rt = L.getOperand(2);
|
||||
|
||||
compoundOpcode = cmpgtBitOpcode[getCompoundOp(R)];
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(Rt);
|
||||
@ -263,7 +263,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
Rt = L.getOperand(2);
|
||||
|
||||
compoundOpcode = cmpgtuBitOpcode[getCompoundOp(R)];
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(Rt);
|
||||
@ -281,7 +281,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
compoundOpcode = cmpeqiBitOpcode[getCompoundOp(R)];
|
||||
|
||||
Rs = L.getOperand(1);
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(L.getOperand(2));
|
||||
@ -299,7 +299,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
compoundOpcode = cmpgtiBitOpcode[getCompoundOp(R)];
|
||||
|
||||
Rs = L.getOperand(1);
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(L.getOperand(2));
|
||||
@ -310,7 +310,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
LLVM_DEBUG(dbgs() << "CX: C2_cmpgtui\n");
|
||||
Rs = L.getOperand(1);
|
||||
compoundOpcode = cmpgtuiBitOpcode[getCompoundOp(R)];
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(L.getOperand(2));
|
||||
@ -321,7 +321,7 @@ static MCInst *getCompoundInsn(MCContext &Context, MCInst const &L,
|
||||
LLVM_DEBUG(dbgs() << "CX: S2_tstbit_i\n");
|
||||
Rs = L.getOperand(1);
|
||||
compoundOpcode = tstBitOpcode[getCompoundOp(R)];
|
||||
CompoundInsn = new (Context) MCInst;
|
||||
CompoundInsn = Context.createMCInst();
|
||||
CompoundInsn->setOpcode(compoundOpcode);
|
||||
CompoundInsn->addOperand(Rs);
|
||||
CompoundInsn->addOperand(R.getOperand(1));
|
||||
|
Loading…
Reference in New Issue
Block a user