1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[RISCV] Fix incorrect use of MCInstBuilder

This is a fix for r339314.

MCInstBuilder uses the named parameter idiom and an 'operator MCInst&' to ease
the creation of MCInsts. As the object of MCInstBuilder owns the MCInst is
manipulating, the lifetime of the MCInst is bound to that of MCInstBuilder.

In r339314 I bound a reference to the MCInst in an initializer. The
temporary of MCInstBuilder (and also its MCInst) is destroyed at the end of
the declaration leading to a dangling reference.

Fix this by using MCInstBuilder inside an argument of a function call.
Temporaries in function calls are destroyed in the enclosing full expression,
so the the reference to MCInst is still valid when emitToStreamer executes.

llvm-svn: 339654
This commit is contained in:
Roger Ferrer Ibanez 2018-08-14 08:30:42 +00:00
parent fa7de2a35e
commit 2fc0db182e

View File

@ -1227,19 +1227,17 @@ void RISCVAsmParser::emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc,
const RISCVMCExpr *Symbol = RISCVMCExpr::create(
Inst.getOperand(1).getExpr(), RISCVMCExpr::VK_RISCV_PCREL_HI, Ctx);
MCInst &AUIPC =
MCInstBuilder(RISCV::AUIPC).addOperand(DestReg).addExpr(Symbol);
emitToStreamer(Out, AUIPC);
emitToStreamer(
Out, MCInstBuilder(RISCV::AUIPC).addOperand(DestReg).addExpr(Symbol));
const MCExpr *RefToLinkTmpLabel =
RISCVMCExpr::create(MCSymbolRefExpr::create(TmpLabel, Ctx),
RISCVMCExpr::VK_RISCV_PCREL_LO, Ctx);
MCInst &ADDI = MCInstBuilder(RISCV::ADDI)
.addOperand(DestReg)
.addOperand(DestReg)
.addExpr(RefToLinkTmpLabel);
emitToStreamer(Out, ADDI);
emitToStreamer(Out, MCInstBuilder(RISCV::ADDI)
.addOperand(DestReg)
.addOperand(DestReg)
.addExpr(RefToLinkTmpLabel));
}
bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,