Skip to content

Commit f4cbbd3

Browse files
committed
[RISCV][CFI] fix __riscv_restore
1 parent 6e6cfea commit f4cbbd3

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
@@ -827,7 +827,6 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
827827

828828
bool RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
829829
!hasReservedCallFrame(MF);
830-
831830
if (RVVStackSize) {
832831
// If RestoreFP the stack pointer will be restored using the frame pointer
833832
// value.
@@ -892,6 +891,19 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
892891
.setMIFlag(MachineInstr::FrameDestroy);
893892
}
894893

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

0 commit comments

Comments
 (0)