xref: /llvm-project/llvm/test/Transforms/ExpandVariadics/invoke.ll (revision 8516f54e6a984a79d1a988ec66a414b5cfbd7ec7)
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
5target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
6
7; ERROR: LLVM ERROR: Cannot lower callbase instruction
8
9@_ZTIi = external constant ptr
10
11; Function Attrs: mustprogress
12define hidden void @test0(i32 noundef %x) #0 personality ptr @__gxx_wasm_personality_v0 {
13; CHECK-LABEL: @test0(
14; CHECK-NEXT:  entry:
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
19; CHECK:       catch.start:
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:%.*]]
26; CHECK:       catch:
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]]
31; CHECK:       rethrow:
32; CHECK-NEXT:    call void @llvm.wasm.rethrow() [ "funclet"(token [[TMP1]]) ]
33; CHECK-NEXT:    unreachable
34; CHECK:       try.cont:
35; CHECK-NEXT:    ret void
36;
37entry:
38  invoke void (...) @may_throw(i32 noundef %x)
39  to label %try.cont unwind label %catch.dispatch
40
41catch.dispatch:                                   ; preds = %entry
42  %0 = catchswitch within none [label %catch.start] unwind to caller
43
44catch.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
51
52catch:                                            ; 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
57
58rethrow:                                          ; preds = %catch.start
59  call void @llvm.wasm.rethrow() #5 [ "funclet"(token %1) ]
60  unreachable
61
62try.cont:                                         ; preds = %entry, %catch
63  ret void
64}
65
66declare void @may_throw(...)
67
68declare i32 @__gxx_wasm_personality_v0(...)
69
70; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
71declare ptr @llvm.wasm.get.exception(token)
72
73; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
74declare i32 @llvm.wasm.get.ehselector(token)
75
76; Function Attrs: nofree nosync nounwind memory(none)
77declare i32 @llvm.eh.typeid.for.p0(ptr)
78
79declare ptr @__cxa_begin_catch(ptr)
80
81; Function Attrs: nounwind
82declare void @dont_throw(...)
83
84declare void @__cxa_end_catch()
85
86; Function Attrs: noreturn
87declare void @llvm.wasm.rethrow()
88
89
90