[llvm] r355558 - [mips] Replace assertion by error message while lowering `RETURNADDR` and `FRAMEADDR`

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 14:40:28 PST 2019


Author: atanasyan
Date: Wed Mar  6 14:40:28 2019
New Revision: 355558

URL: http://llvm.org/viewvc/llvm-project?rev=355558&view=rev
Log:
[mips] Replace assertion by error message while lowering `RETURNADDR` and `FRAMEADDR`

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.

Added:
    llvm/trunk/test/CodeGen/Mips/frame-address-err.ll
    llvm/trunk/test/CodeGen/Mips/return_address_err.ll
Modified:
    llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp

Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=355558&r1=355557&r2=355558&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Wed Mar  6 14:40:28 2019
@@ -2376,8 +2376,11 @@ SDValue MipsTargetLowering::lowerFABS(SD
 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::lowerRETURNA
     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();

Added: llvm/trunk/test/CodeGen/Mips/frame-address-err.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/frame-address-err.ll?rev=355558&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/frame-address-err.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/frame-address-err.ll Wed Mar  6 14:40:28 2019
@@ -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
+}

Added: llvm/trunk/test/CodeGen/Mips/return_address_err.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/return_address_err.ll?rev=355558&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/return_address_err.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/return_address_err.ll Wed Mar  6 14:40:28 2019
@@ -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
+}




More information about the llvm-commits mailing list