[PATCH] D136917: [LoongArch] Replace assertion by error message while lowering RETURNADDR and FRAMEADDR
Gong LingQin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 23:36:45 PDT 2022
gonglingqin created this revision.
gonglingqin added reviewers: xen0n, xry111, SixWeining, wangleiat, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
gonglingqin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If __builtin_frame_address or__builtin_return_address is invoked with
non-zero argument, show an error message instead of a crash.
Reference: https://reviews.llvm.org/rG83b88441ad951fe99c30402930ef3cd661f2fd2b
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136917
Files:
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll
Index: llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll
===================================================================
--- llvm/test/CodeGen/LoongArch/frameaddr-returnaddr-error.ll
+++ 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 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 current frame
+ %1 = call ptr @llvm.returnaddress(i32 1)
+ ret ptr %1
+}
+
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -239,11 +239,11 @@
}
// Currently only support lowering frame address for current frame.
- unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- assert((Depth == 0) &&
- "Frame address can only be determined for current frame.");
- if (Depth != 0)
+ if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() != 0) {
+ DAG.getContext()->emitError(
+ "frame address can only be determined for 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<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- assert((Depth == 0) &&
- "Return address can only be determined for current frame.");
- if (Depth != 0)
+ if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() != 0) {
+ DAG.getContext()->emitError(
+ "return address can only be determined for current frame");
return SDValue();
+ }
MachineFunction &MF = DAG.getMachineFunction();
MF.getFrameInfo().setReturnAddressIsTaken(true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136917.471407.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/b0b3c38a/attachment.bin>
More information about the llvm-commits
mailing list