1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
14 ; Parts of the IR have been hand-edited to simplify the test case.
15 ; The full IR will be restored when Windows C++ EH support is complete.
17 ;ModuleID = 'cppeh-catch-scalar.cpp'
18 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-pc-windows-msvc"
21 @_ZTIi = external constant i8*
23 ; The function entry will be rewritten like this.
24 ; CHECK: define void @_Z4testv()
26 ; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
27 ; CHECK: call void (...) @llvm.localescape(i32* [[I_PTR]])
28 ; CHECK: invoke void @_Z9may_throwv()
29 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
31 ; Function Attrs: uwtable
32 define void @_Z4testv() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
34 %exn.slot = alloca i8*
35 %ehselector.slot = alloca i32
36 %i = alloca i32, align 4
37 invoke void @_Z9may_throwv()
38 to label %invoke.cont unwind label %lpad
40 invoke.cont: ; preds = %entry
43 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
44 ; CHECK: landingpad { i8*, i32 }
45 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
46 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (i8** @_ZTIi to i8*), i32 0, i8* (i8*, i8*)* @_Z4testv.catch)
47 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont]
49 lpad: ; preds = %entry
50 %tmp = landingpad { i8*, i32 }
51 catch i8* bitcast (i8** @_ZTIi to i8*)
52 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
53 store i8* %tmp1, i8** %exn.slot
54 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
55 store i32 %tmp2, i32* %ehselector.slot
56 br label %catch.dispatch
58 ; CHECK-NOT: catch-dispatch:
60 catch.dispatch: ; preds = %lpad
61 %sel = load i32, i32* %ehselector.slot
62 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
63 %matches = icmp eq i32 %sel, %tmp3
64 br i1 %matches, label %catch, label %eh.resume
68 catch: ; preds = %catch.dispatch
69 %exn11 = load i8*, i8** %exn.slot
70 %i.i8 = bitcast i32* %i to i8*
71 call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
72 %tmp7 = load i32, i32* %i, align 4
73 call void @_Z10handle_inti(i32 %tmp7)
74 br label %invoke.cont2
76 ; CHECK-NOT: invoke.cont2:
78 invoke.cont2: ; preds = %catch
79 call void @llvm.eh.endcatch() #3
82 try.cont: ; preds = %invoke.cont2, %invoke.cont
85 ; CHECK-NOT: eh.resume:
87 eh.resume: ; preds = %catch.dispatch
88 %exn3 = load i8*, i8** %exn.slot
89 %sel4 = load i32, i32* %ehselector.slot
90 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
91 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
92 resume { i8*, i32 } %lpad.val5
97 ; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*)
99 ; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
100 ; CHECK: [[I_PTR1:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
101 ; CHECK: [[TMP:\%.+]] = load i32, i32* [[I_PTR1]], align 4
102 ; CHECK: call void @_Z10handle_inti(i32 [[TMP]])
103 ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
106 declare void @_Z9may_throwv() #1
108 declare i32 @__CxxFrameHandler3(...)
110 ; Function Attrs: nounwind readnone
111 declare i32 @llvm.eh.typeid.for(i8*) #2
113 declare void @llvm.eh.begincatch(i8*, i8*)
115 declare void @llvm.eh.endcatch()
117 declare void @_Z10handle_inti(i32) #1
119 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
120 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
121 attributes #2 = { nounwind readnone }
122 attributes #3 = { nounwind }
126 !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}