1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s -check-prefixes=CHECK
3 ; RUN: not --crash opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s 2>&1 | FileCheck %s -check-prefixes=ERROR
4 ; REQUIRES: webassembly-registered-target
5 target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
7 ; ERROR: LLVM ERROR: Cannot lower callbase instruction
9 @_ZTIi = external constant ptr
11 ; Function Attrs: mustprogress
12 define hidden void @test0(i32 noundef %x) #0 personality ptr @__gxx_wasm_personality_v0 {
13 ; CHECK-LABEL: @test0(
15 ; CHECK-NEXT: invoke void (...) @may_throw(i32 noundef [[X:%.*]])
16 ; CHECK-NEXT: to label [[TRY_CONT:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
17 ; CHECK: catch.dispatch:
18 ; CHECK-NEXT: [[TMP0:%.*]] = catchswitch within none [label %catch.start] unwind to caller
20 ; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[TMP0]] [ptr @_ZTIi]
21 ; CHECK-NEXT: [[TMP2:%.*]] = tail call ptr @llvm.wasm.get.exception(token [[TMP1]])
22 ; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @llvm.wasm.get.ehselector(token [[TMP1]])
23 ; CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIi)
24 ; CHECK-NEXT: [[MATCHES:%.*]] = icmp eq i32 [[TMP3]], [[TMP4]]
25 ; CHECK-NEXT: br i1 [[MATCHES]], label [[CATCH:%.*]], label [[RETHROW:%.*]]
27 ; CHECK-NEXT: [[TMP5:%.*]] = call ptr @__cxa_begin_catch(ptr [[TMP2]]) [ "funclet"(token [[TMP1]]) ]
28 ; CHECK-NEXT: call void (...) @dont_throw(i32 noundef [[X]]) [ "funclet"(token [[TMP1]]) ]
29 ; CHECK-NEXT: call void @__cxa_end_catch() [ "funclet"(token [[TMP1]]) ]
30 ; CHECK-NEXT: catchret from [[TMP1]] to label [[TRY_CONT]]
32 ; CHECK-NEXT: call void @llvm.wasm.rethrow() [ "funclet"(token [[TMP1]]) ]
33 ; CHECK-NEXT: unreachable
35 ; CHECK-NEXT: ret void
38 invoke void (...) @may_throw(i32 noundef %x)
39 to label %try.cont unwind label %catch.dispatch
41 catch.dispatch: ; preds = %entry
42 %0 = catchswitch within none [label %catch.start] unwind to caller
44 catch.start: ; preds = %catch.dispatch
45 %1 = catchpad within %0 [ptr @_ZTIi]
46 %2 = tail call ptr @llvm.wasm.get.exception(token %1)
47 %3 = tail call i32 @llvm.wasm.get.ehselector(token %1)
48 %4 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIi)
49 %matches = icmp eq i32 %3, %4
50 br i1 %matches, label %catch, label %rethrow
52 catch: ; preds = %catch.start
53 %5 = call ptr @__cxa_begin_catch(ptr %2) #6 [ "funclet"(token %1) ]
54 call void (...) @dont_throw(i32 noundef %x) #6 [ "funclet"(token %1) ]
55 call void @__cxa_end_catch() #6 [ "funclet"(token %1) ]
56 catchret from %1 to label %try.cont
58 rethrow: ; preds = %catch.start
59 call void @llvm.wasm.rethrow() #5 [ "funclet"(token %1) ]
62 try.cont: ; preds = %entry, %catch
66 declare void @may_throw(...)
68 declare i32 @__gxx_wasm_personality_v0(...)
70 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
71 declare ptr @llvm.wasm.get.exception(token)
73 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
74 declare i32 @llvm.wasm.get.ehselector(token)
76 ; Function Attrs: nofree nosync nounwind memory(none)
77 declare i32 @llvm.eh.typeid.for.p0(ptr)
79 declare ptr @__cxa_begin_catch(ptr)
81 ; Function Attrs: nounwind
82 declare void @dont_throw(...)
84 declare void @__cxa_end_catch()
86 ; Function Attrs: noreturn
87 declare void @llvm.wasm.rethrow()