diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp --- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp @@ -239,11 +239,11 @@ } // Currently only support lowering frame address for current frame. - unsigned Depth = cast(Op.getOperand(0))->getZExtValue(); - assert((Depth == 0) && - "Frame address can only be determined for current frame."); - if (Depth != 0) + if (cast(Op.getOperand(0))->getZExtValue() != 0) { + DAG.getContext()->emitError( + "frame address can only be determined for the current frame"); return SDValue(); + } MachineFunction &MF = DAG.getMachineFunction(); MF.getFrameInfo().setFrameAddressIsTaken(true); @@ -259,11 +259,11 @@ return SDValue(); // Currently only support lowering return address for current frame. - unsigned Depth = cast(Op.getOperand(0))->getZExtValue(); - assert((Depth == 0) && - "Return address can only be determined for current frame."); - if (Depth != 0) + if (cast(Op.getOperand(0))->getZExtValue() != 0) { + DAG.getContext()->emitError( + "return address can only be determined for the current frame"); return SDValue(); + } MachineFunction &MF = DAG.getMachineFunction(); MF.getFrameInfo().setReturnAddressIsTaken(true); diff --git a/llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll b/llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll --- a/llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll +++ b/llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll @@ -16,3 +16,16 @@ ret ptr %1 } +define ptr @non_zero_frameaddress() nounwind { +; CHECK: frame address can only be determined for the current frame + %1 = call ptr @llvm.frameaddress(i32 1) + ret ptr %1 +} + + +define ptr @non_zero_returnaddress() nounwind { +; CHECK: return address can only be determined for the current frame + %1 = call ptr @llvm.returnaddress(i32 1) + ret ptr %1 +} +