Skip to content

Commit

Permalink
[RISCV][CFI] fix __riscv_restore
Browse files Browse the repository at this point in the history
  • Loading branch information
dlav-sc committed Oct 3, 2024
1 parent 36489be commit c02801e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,

bool RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
!hasReservedCallFrame(MF);

if (RVVStackSize) {
// If restoreFP the stack pointer will be restored using the frame pointer
// value.
Expand Down Expand Up @@ -892,6 +891,19 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
.setMIFlag(MachineInstr::FrameDestroy);
}

if (getLibCallID(MF, CSI) + 1) {
// tail __riscv_restore_[0-12] instruction is considered as a terminator,
// therefor it is unnecessary to place any CFI instructions after it. Just
// deallocate stack if needed and return.
if (StackSize != 0)
deallocateStack(MF, MBB, MBBI, DL, StackSize,
RVFI->getLibCallStackSize());

// Emit epilogue for shadow call stack.
emitSCSEpilogue(MF, MBB, MBBI, DL);
return;
}

bool ApplyPop = RVFI->isPushable(MF) && MBBI != MBB.end() &&
MBBI->getOpcode() == RISCV::CM_POP;
if (ApplyPop) {
Expand Down

0 comments on commit c02801e

Please sign in to comment.