summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRoger Ferrer Ibanez <rofirrim@gmail.com>2018-08-14 08:30:42 +0000
committerRoger Ferrer Ibanez <rofirrim@gmail.com>2018-08-14 08:30:42 +0000
commitc8f4dbbc63b682e1f88ae83755fc62e4d200b501 (patch)
treebdbe74bb2fb907fe293d07852a619b1103ba5e79 /llvm/lib
parent5a42441d8192827bcf12fea1dd04f7c0f599b114 (diff)
downloadbcm5719-llvm-c8f4dbbc63b682e1f88ae83755fc62e4d200b501.tar.gz
bcm5719-llvm-c8f4dbbc63b682e1f88ae83755fc62e4d200b501.zip
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 5a56ddf0656..3a5257206bf 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -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,
OpenPOWER on IntegriCloud