[mips] Replace assertion by error message while lowering `RETURNADDR` and `FRAMEADDR`
authorSimon Atanasyan <simon@atanasyan.com>
Wed, 6 Mar 2019 22:40:28 +0000 (22:40 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Wed, 6 Mar 2019 22:40:28 +0000 (22:40 +0000)
MIPS target supports lowering `RETURNADDR` and `FRAMEADDR` for a current
frame only. It's better to show an error message then crash on assertion
if `__builtin_return_address` is invoked with non-zero argument.

llvm-svn: 355558

llvm/lib/Target/Mips/MipsISelLowering.cpp
llvm/test/CodeGen/Mips/frame-address-err.ll [new file with mode: 0644]
llvm/test/CodeGen/Mips/return_address_err.ll [new file with mode: 0644]

index d69effb..e0243a0 100644 (file)
@@ -2376,8 +2376,11 @@ SDValue MipsTargetLowering::lowerFABS(SDValue Op, SelectionDAG &DAG) const {
 SDValue MipsTargetLowering::
 lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const {
   // check the depth
-  assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
-         "Frame address can only be determined for current frame.");
+  if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() != 0) {
+    DAG.getContext()->emitError(
+        "return address can be determined only for current frame");
+    return SDValue();
+  }
 
   MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
   MFI.setFrameAddressIsTaken(true);
@@ -2394,8 +2397,11 @@ SDValue MipsTargetLowering::lowerRETURNADDR(SDValue Op,
     return SDValue();
 
   // check the depth
-  assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
-         "Return address can be determined only for current frame.");
+  if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() != 0) {
+    DAG.getContext()->emitError(
+        "return address can be determined only for current frame");
+    return SDValue();
+  }
 
   MachineFunction &MF = DAG.getMachineFunction();
   MachineFrameInfo &MFI = MF.getFrameInfo();
diff --git a/llvm/test/CodeGen/Mips/frame-address-err.ll b/llvm/test/CodeGen/Mips/frame-address-err.ll
new file mode 100644 (file)
index 0000000..086f628
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: not llc -march=mips < %s 2>&1 | FileCheck %s
+
+declare i8* @llvm.frameaddress(i32) nounwind readnone
+
+define i8* @f() nounwind {
+entry:
+  %0 = call i8* @llvm.frameaddress(i32 1)
+  ret i8* %0
+
+; CHECK: error: return address can be determined only for current frame
+}
diff --git a/llvm/test/CodeGen/Mips/return_address_err.ll b/llvm/test/CodeGen/Mips/return_address_err.ll
new file mode 100644 (file)
index 0000000..b250765
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: not llc -march=mips < %s 2>&1 | FileCheck %s
+
+declare i8* @llvm.returnaddress(i32) nounwind readnone
+
+define i8* @f() nounwind {
+entry:
+  %0 = call i8* @llvm.returnaddress(i32 1)
+  ret i8* %0
+
+; CHECK: error: return address can be determined only for current frame
+}