Skip to content

Commit 7e83469

Browse files
committed
Ensure NoTrapAfterNoreturn is false for wasm
1 parent 7c43c80 commit 7e83469

File tree

2 files changed

+25
-63
lines changed

2 files changed

+25
-63
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
127127
// LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
128128
// 'unreachable' instructions which is meant for that case.
129129
this->Options.TrapUnreachable = true;
130+
this->Options.NoTrapAfterNoreturn = false;
130131

131132
// WebAssembly treats each function as an independent unit. Force
132133
// -ffunction-sections, effectively, so that we can emit them independently.

llvm/test/CodeGen/WebAssembly/unreachable.ll

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
; RUN: llc < %s -verify-machineinstrs | FileCheck %s --check-prefixes CHECK,NORMAL
2-
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs | FileCheck %s --check-prefixes CHECK,NORMAL
3-
; RUN: llc < %s -verify-machineinstrs --trap-unreachable | FileCheck %s --check-prefixes CHECK,NORMAL
4-
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable | FileCheck %s --check-prefixes CHECK,NORMAL
5-
; RUN: llc < %s -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s --check-prefixes CHECK,NTANR
6-
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s --check-prefixes CHECK,FNTANR
1+
; RUN: llc < %s -verify-machineinstrs | FileCheck %s
2+
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs | FileCheck %s
3+
; RUN: llc < %s -verify-machineinstrs --trap-unreachable | FileCheck %s
4+
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable | FileCheck %s
5+
; RUN: llc < %s -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s
6+
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s
77

88
target triple = "wasm32-unknown-unknown"
99

@@ -37,25 +37,12 @@ define void @dtrap_ret_void() {
3737

3838
; Test that LLVM trap followed by LLVM unreachable becomes exactly one wasm unreachable.
3939
define void @trap_unreach() {
40-
; NORMAL-LABEL: trap_unreach:
41-
; NORMAL: .functype trap_unreach () -> ()
42-
; NORMAL-NEXT: # %bb.0:
43-
; NORMAL-NEXT: unreachable
44-
; NORMAL-NEXT: unreachable
45-
; NORMAL-NEXT: end_function
46-
;
47-
; NTANR-LABEL: trap_unreach:
48-
; NTANR: .functype trap_unreach () -> ()
49-
; NTANR-NEXT: # %bb.0:
50-
; NTANR-NEXT: unreachable
51-
; NTANR-NEXT: end_function
52-
;
53-
; FNTANR-LABEL: trap_unreach:
54-
; FNTANR: .functype trap_unreach () -> ()
55-
; FNTANR-NEXT: # %bb.0:
56-
; FNTANR-NEXT: unreachable
57-
; FNTANR-NEXT: unreachable
58-
; FNTANR-NEXT: end_function
40+
; CHECK-LABEL: trap_unreach:
41+
; CHECK: .functype trap_unreach () -> ()
42+
; CHECK-NEXT: # %bb.0:
43+
; CHECK-NEXT: unreachable
44+
; CHECK-NEXT: unreachable
45+
; CHECK-NEXT: end_function
5946
call void @llvm.trap()
6047
unreachable
6148
}
@@ -83,25 +70,12 @@ define i32 @missing_ret_unreach() {
8370
; This is similar to the above test, but ensures wasm unreachable is emitted even
8471
; after a noreturn call.
8572
define i32 @missing_ret_noreturn_unreach() {
86-
; NORMAL-LABEL: missing_ret_noreturn_unreach:
87-
; NORMAL: .functype missing_ret_noreturn_unreach () -> (i32)
88-
; NORMAL-NEXT: # %bb.0:
89-
; NORMAL-NEXT: call ext_never_return
90-
; NORMAL-NEXT: unreachable
91-
; NORMAL-NEXT: end_function
92-
;
93-
; NTANR-LABEL: missing_ret_noreturn_unreach:
94-
; NTANR: .functype missing_ret_noreturn_unreach () -> (i32)
95-
; NTANR-NEXT: # %bb.0:
96-
; NTANR-NEXT: call ext_never_return
97-
; NTANR-NEXT: end_function
98-
;
99-
; FNTANR-LABEL: missing_ret_noreturn_unreach:
100-
; FNTANR: .functype missing_ret_noreturn_unreach () -> (i32)
101-
; FNTANR-NEXT: # %bb.0:
102-
; FNTANR-NEXT: call ext_never_return
103-
; FNTANR-NEXT: unreachable
104-
; FNTANR-NEXT: end_function
73+
; CHECK-LABEL: missing_ret_noreturn_unreach:
74+
; CHECK: .functype missing_ret_noreturn_unreach () -> (i32)
75+
; CHECK-NEXT: # %bb.0:
76+
; CHECK-NEXT: call ext_never_return
77+
; CHECK-NEXT: unreachable
78+
; CHECK-NEXT: end_function
10579
call void @ext_never_return()
10680
unreachable
10781
}
@@ -133,25 +107,12 @@ define i32 @i32_sig_match_unreach() {
133107
}
134108

135109
define void @void_sig_match_noreturn_unreach() {
136-
; NORMAL-LABEL: void_sig_match_noreturn_unreach:
137-
; NORMAL: .functype void_sig_match_noreturn_unreach () -> ()
138-
; NORMAL-NEXT: # %bb.0:
139-
; NORMAL-NEXT: call ext_never_return
140-
; NORMAL-NEXT: unreachable
141-
; NORMAL-NEXT: end_function
142-
;
143-
; NTANR-LABEL: void_sig_match_noreturn_unreach:
144-
; NTANR: .functype void_sig_match_noreturn_unreach () -> ()
145-
; NTANR-NEXT: # %bb.0:
146-
; NTANR-NEXT: call ext_never_return
147-
; NTANR-NEXT: end_function
148-
;
149-
; FNTANR-LABEL: void_sig_match_noreturn_unreach:
150-
; FNTANR: .functype void_sig_match_noreturn_unreach () -> ()
151-
; FNTANR-NEXT: # %bb.0:
152-
; FNTANR-NEXT: call ext_never_return
153-
; FNTANR-NEXT: unreachable
154-
; FNTANR-NEXT: end_function
110+
; CHECK-LABEL: void_sig_match_noreturn_unreach:
111+
; CHECK: .functype void_sig_match_noreturn_unreach () -> ()
112+
; CHECK-NEXT: # %bb.0:
113+
; CHECK-NEXT: call ext_never_return
114+
; CHECK-NEXT: unreachable
115+
; CHECK-NEXT: end_function
155116
call void @ext_never_return()
156117
unreachable
157118
}

0 commit comments

Comments
 (0)