This attribute calls a function instead of emitting a trap instruction.
Differential Revision: https://reviews.llvm.org/D110098
return true;
}
+ case Intrinsic::trap:
+ case Intrinsic::debugtrap:
+ case Intrinsic::ubsantrap: {
+ StringRef TrapFuncName =
+ CI.getAttributes().getFnAttr("trap-func-name").getValueAsString();
+ if (TrapFuncName.empty())
+ break; // Use the default handling.
+ CallLowering::CallLoweringInfo Info;
+ if (ID == Intrinsic::ubsantrap) {
+ Info.OrigArgs.push_back({getOrCreateVRegs(*CI.getArgOperand(0)),
+ CI.getArgOperand(0)->getType(), 0});
+ }
+ Info.Callee =
+ MachineOperand::CreateES(MF->createExternalSymbolName(TrapFuncName));
+ Info.CB = &CI;
+ Info.OrigRet = {Register(), Type::getVoidTy(CI.getContext()), 0};
+ return CLI->lowerCall(MIRBuilder, Info);
+ }
#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
case Intrinsic::INTRINSIC:
#include "llvm/IR/ConstrainedOps.def"
; RUN: llc < %s -mtriple=arm64-eabi | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-eabi -global-isel | FileCheck %s
define void @foo() nounwind {
-; CHECK: foo
+; CHECK-LABEL: foo
; CHECK: brk #0x1
tail call void @llvm.trap()
ret void
}
declare void @llvm.trap() nounwind
+
+; CHECK-LABEL: {{\_?}}foo_trap_func:
+; CHECK: bl trap_func
+
+define void @foo_trap_func() {
+ call void @llvm.trap() #0
+ unreachable
+}
+
+attributes #0 = { "trap-func-name"="trap_func" }
; RUN: llc -mtriple=aarch64-windows %s -o -| FileCheck %s
-; RUN: llc -mtriple=aarch64-windows -fast-isel %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-windows -fast-isel %s -o - | FileCheck %s --check-prefix=FASTISEL
; RUN: llc -mtriple=aarch64-windows -global-isel %s -o - | FileCheck %s
; RUN: llc -mtriple=aarch64-linux-gnu %s -o -| FileCheck %s
; RUN: llc -mtriple=arm64-apple-ios -global-isel %s -o - | FileCheck %s
-; RUN: llc -mtriple=arm64-apple-macosx -fast-isel %s -o - | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-macosx -fast-isel %s -o - | FileCheck %s --check-prefix=FASTISEL
; CHECK-LABEL: test1:
; CHECK: brk #0xf000
+; FASTISEL: brk #0xf000
define void @test1() noreturn nounwind {
entry:
tail call void @llvm.debugtrap( )
}
declare void @llvm.debugtrap() nounwind
+
+; CHECK-LABEL: test_trap_func:
+; CHECK: bl {{.*}}wibble
+
+; FastISel doesn't handle trap-func-name for debugtrap.
+; FASTISEL: brk
+define void @test_trap_func() noreturn nounwind {
+entry:
+ tail call void @llvm.debugtrap( ) "trap-func-name"="wibble"
+ ret void
+}
\ No newline at end of file
; RUN: llc -mtriple=arm64-apple-ios %s -o - | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-ios -global-isel %s -o - | FileCheck %s
define void @test_ubsantrap() {
; CHECK-LABEL: test_ubsantrap