xref: /llvm-project/clang/test/CodeGen/WebAssembly/wasm-eh.ll (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1; REQUIRES: webassembly-registered-target
2; RUN: %clang %s -target wasm32-unknown-unknown -fwasm-exceptions -c -S -o - | FileCheck %s
3
4; This tests whether clang driver can take -fwasm-exceptions and compile bitcode
5; files using Wasm EH.
6
7; CHECK-LABEL: test
8; CHECK: try
9; CHECK:   call foo
10; CHECK: catch __cpp_exception
11; CHECK: end
12define void @test() personality ptr @__gxx_wasm_personality_v0 {
13entry:
14  invoke void @foo()
15          to label %try.cont unwind label %catch.dispatch
16
17catch.dispatch:                                   ; preds = %entry
18  %0 = catchswitch within none [label %catch.start] unwind to caller
19
20catch.start:                                      ; preds = %catch.dispatch
21  %1 = catchpad within %0 [ptr null]
22  %2 = call ptr @llvm.wasm.get.exception(token %1)
23  %3 = call i32 @llvm.wasm.get.ehselector(token %1)
24  %4 = call ptr @__cxa_begin_catch(ptr %2) #2 [ "funclet"(token %1) ]
25  call void @__cxa_end_catch() [ "funclet"(token %1) ]
26  catchret from %1 to label %try.cont
27
28try.cont:                                         ; preds = %entry, %catch.start
29  ret void
30}
31
32declare void @foo()
33declare i32 @__gxx_wasm_personality_v0(...)
34declare ptr @llvm.wasm.get.exception(token)
35declare i32 @llvm.wasm.get.ehselector(token)
36declare ptr @__cxa_begin_catch(ptr)
37declare void @__cxa_end_catch()
38
39