1 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck %s --check-prefix=X86
2 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s --check-prefix=X64
4 ; Based on this source:
5 ; extern "C" void may_throw(int);
19 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
20 %eh.CatchHandlerType = type { i32, i8* }
22 declare void @may_throw(i32)
23 declare i32 @__CxxFrameHandler3(...)
24 declare void @llvm.eh.begincatch(i8*, i8*)
25 declare void @llvm.eh.endcatch()
26 declare i32 @llvm.eh.typeid.for(i8*)
28 $"\01??_R0H@8" = comdat any
30 @"\01??_7type_info@@6B@" = external constant i8*
31 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
32 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
34 define void @f() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
36 invoke void @may_throw(i32 1)
37 to label %invoke.cont unwind label %lpad.1
39 invoke.cont: ; preds = %entry
40 invoke void @may_throw(i32 2)
41 to label %try.cont.9 unwind label %lpad
43 try.cont.9: ; preds = %invoke.cont.3, %invoke.cont, %catch.7
46 lpad: ; preds = %catch, %entry
47 %cs1 = catchswitch within none [label %catch] unwind label %lpad.1
49 catch: ; preds = %lpad.1
50 %p1 = catchpad within %cs1 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
51 invoke void @may_throw(i32 3) [ "funclet"(token %p1) ]
52 to label %invoke.cont.3 unwind label %lpad.1
54 invoke.cont.3: ; preds = %catch
55 catchret from %p1 to label %try.cont.9
57 lpad.1: ; preds = %invoke.cont
58 %cs2 = catchswitch within none [label %catch.7] unwind to caller
61 %p2 = catchpad within %cs2 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
62 call void @may_throw(i32 4) [ "funclet"(token %p2) ]
63 catchret from %p2 to label %try.cont.9
67 ; X86: movl $-1, [[state:[-0-9]+]](%ebp)
68 ; X86: movl $___ehhandler$f, {{.*}}
70 ; X86: movl $0, [[state]](%ebp)
72 ; X86: calll _may_throw
74 ; X86: movl $1, [[state]](%ebp)
76 ; X86: calll _may_throw
78 ; X86: movl $2, [[state]](%ebp)
80 ; X86: calll _may_throw
82 ; X86: movl $3, [[state]](%ebp)
84 ; X86: calll _may_throw
88 ; X64-LABEL: $ip2state$f:
89 ; X64-NEXT: .long .Lfunc_begin0@IMGREL
91 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
93 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
95 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
97 ; X64-NEXT: .long "?catch${{.*}}@?0?f@4HA"@IMGREL
99 ; X64-NEXT: .long "?catch${{.*}}@?0?f@4HA"@IMGREL
102 ; Based on this source:
103 ; extern "C" void may_throw(int);
104 ; struct S { ~S(); };
119 %struct.S = type { i8 }
120 declare void @"\01??1S@@QEAA@XZ"(%struct.S*)
122 define void @g() personality i32 (...)* @__CxxFrameHandler3 {
124 %x = alloca %struct.S, align 1
125 %y = alloca %struct.S, align 1
126 invoke void @may_throw(i32 -1)
127 to label %unreachable unwind label %catch.dispatch
129 catch.dispatch: ; preds = %entry
130 %0 = catchswitch within none [label %catch] unwind label %ehcleanup5
132 catch: ; preds = %catch.dispatch
133 %1 = catchpad within %0 [i8* null, i32 64, i8* null]
134 invoke void @may_throw(i32 0) [ "funclet"(token %1) ]
135 to label %invoke.cont unwind label %ehcleanup5
137 invoke.cont: ; preds = %catch
138 invoke void @may_throw(i32 1) [ "funclet"(token %1) ]
139 to label %invoke.cont2 unwind label %ehcleanup
141 invoke.cont2: ; preds = %invoke.cont
142 invoke void @"\01??1S@@QEAA@XZ"(%struct.S* nonnull %y) [ "funclet"(token %1) ]
143 to label %invoke.cont3 unwind label %ehcleanup5
145 invoke.cont3: ; preds = %invoke.cont2
146 invoke void @may_throw(i32 2) [ "funclet"(token %1) ]
147 to label %invoke.cont4 unwind label %ehcleanup5
149 invoke.cont4: ; preds = %invoke.cont3
150 catchret from %1 to label %try.cont
152 try.cont: ; preds = %invoke.cont4
153 call void @"\01??1S@@QEAA@XZ"(%struct.S* nonnull %x)
156 ehcleanup: ; preds = %invoke.cont
157 %2 = cleanuppad within %1 []
158 call void @"\01??1S@@QEAA@XZ"(%struct.S* nonnull %y) [ "funclet"(token %2) ]
159 cleanupret from %2 unwind label %ehcleanup5
161 ehcleanup5: ; preds = %invoke.cont2, %invoke.cont3, %ehcleanup, %catch, %catch.dispatch
162 %3 = cleanuppad within none []
163 call void @"\01??1S@@QEAA@XZ"(%struct.S* nonnull %x) [ "funclet"(token %3) ]
164 cleanupret from %3 unwind to caller
166 unreachable: ; preds = %entry
171 ; X86: movl $-1, [[state:[-0-9]+]](%ebp)
172 ; X86: movl $___ehhandler$g, {{.*}}
174 ; X86: movl $1, [[state]](%ebp)
176 ; X86: calll _may_throw
178 ; X86: movl $2, [[state]](%ebp)
180 ; X86: calll _may_throw
182 ; X86: movl $3, [[state]](%ebp)
184 ; X86: calll _may_throw
186 ; X86: movl $2, [[state]](%ebp)
188 ; X86: calll _may_throw
191 ; X64-LABEL: $ip2state$g:
192 ; X64-NEXT: .long .Lfunc_begin1@IMGREL
194 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
196 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
198 ; X64-NEXT: .long "?catch${{.*}}@?0?g@4HA"@IMGREL
200 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
202 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
206 ; X86: .safeseh ___ehhandler$f
207 ; X86: .safeseh ___ehhandler$g