Skip to content

Commit a72c6f3

Browse files
committed
[RISCV][CFI] fix __riscv_restore
1 parent 2d6ac42 commit a72c6f3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
824824

825825
bool RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
826826
!hasReservedCallFrame(MF);
827-
828827
if (RVVStackSize) {
829828
// If RestoreFP the stack pointer will be restored using the frame pointer
830829
// value.
@@ -889,6 +888,19 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
889888
.setMIFlag(MachineInstr::FrameDestroy);
890889
}
891890

891+
if (getLibCallID(MF, CSI) != -1) {
892+
// tail __riscv_restore_[0-12] instruction is considered as a terminator,
893+
// therefor it is unnecessary to place any CFI instructions after it. Just
894+
// deallocate stack if needed and return.
895+
if (StackSize != 0)
896+
deallocateStack(MF, MBB, MBBI, DL, StackSize,
897+
RVFI->getLibCallStackSize());
898+
899+
// Emit epilogue for shadow call stack.
900+
emitSCSEpilogue(MF, MBB, MBBI, DL);
901+
return;
902+
}
903+
892904
bool ApplyPop = RVFI->isPushable(MF) && MBBI != MBB.end() &&
893905
MBBI->getOpcode() == RISCV::CM_POP;
894906
if (ApplyPop) {

0 commit comments

Comments
 (0)