Skip to content

Commit 64d1cea

Browse files
authored
Add command line option --no-trap-after-noreturn (#67051)
Add the command line option --no-trap-after-noreturn, which exposes the pre-existing TargetOption `NoTrapAfterNoreturn`. This pull request was split off from this one: #65876
1 parent c373a1f commit 64d1cea

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ static cl::opt<bool>
3737
EnableTrapUnreachable("trap-unreachable", cl::Hidden,
3838
cl::desc("Enable generating trap for unreachable"));
3939

40+
static cl::opt<bool> EnableNoTrapAfterNoreturn(
41+
"no-trap-after-noreturn", cl::Hidden,
42+
cl::desc("Do not emit a trap instruction for 'unreachable' IR instructions "
43+
"after noreturn calls, even if --trap-unreachable is set."));
44+
4045
void LLVMTargetMachine::initAsmInfo() {
4146
MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
4247
assert(MRI && "Unable to create reg info");
@@ -95,6 +100,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
95100

96101
if (EnableTrapUnreachable)
97102
this->Options.TrapUnreachable = true;
103+
if (EnableNoTrapAfterNoreturn)
104+
this->Options.NoTrapAfterNoreturn = true;
98105
}
99106

100107
TargetTransformInfo
Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
1-
; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s
2-
; CHECK: .inst.n 0xdefe
1+
; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s --check-prefixes CHECK,TRAP_UNREACHABLE
2+
; RUN: llc -mtriple=thumbv7 -trap-unreachable -no-trap-after-noreturn < %s | FileCheck %s --check-prefixes CHECK,NTANR
33

4-
define void @test() #0 {
4+
define void @test_trap_unreachable() #0 {
5+
; CHECK-LABEL: test_trap_unreachable:
6+
; CHECK: @ %bb.0:
7+
; CHECK-NEXT: .inst.n 0xdefe
58
unreachable
69
}
710

811
attributes #0 = { nounwind }
12+
13+
declare void @no_return() noreturn
14+
declare void @could_return()
15+
16+
define void @test_ntanr_noreturn() {
17+
; CHECK-LABEL: test_ntanr_noreturn:
18+
; CHECK: @ %bb.0:
19+
; CHECK-NEXT: push {r7, lr}
20+
; CHECK-NEXT: bl no_return
21+
; TRAP_UNREACHABLE-NEXT: .inst.n 0xdefe
22+
; NTANR-NOT: .inst.n 0xdefe
23+
;
24+
call void @no_return()
25+
unreachable
26+
}
27+
28+
define void @test_ntanr_could_return() {
29+
; CHECK-LABEL: test_ntanr_could_return:
30+
; CHECK: @ %bb.0:
31+
; CHECK-NEXT: push {r7, lr}
32+
; CHECK-NEXT: bl could_return
33+
; CHECK-NEXT: .inst.n 0xdefe
34+
call void @could_return()
35+
unreachable
36+
}

0 commit comments

Comments
 (0)