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 { ptr, ptr, [3 x i8] }
20 %eh.CatchHandlerType = type { i32, ptr }
22 declare void @may_throw(i32)
23 declare i32 @__CxxFrameHandler3(...)
24 declare i32 @llvm.eh.typeid.for(ptr)
26 $"\01??_R0H@8" = comdat any
28 @"\01??_7type_info@@6B@" = external constant ptr
29 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { ptr @"\01??_7type_info@@6B@", ptr null, [3 x i8] c".H\00" }, comdat
30 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, ptr @"\01??_R0H@8" }, section "llvm.metadata"
32 define void @f() #0 personality ptr @__CxxFrameHandler3 {
34 invoke void @may_throw(i32 1)
35 to label %invoke.cont unwind label %lpad.1
37 invoke.cont: ; preds = %entry
38 invoke void @may_throw(i32 2)
39 to label %try.cont.9 unwind label %lpad
41 try.cont.9: ; preds = %invoke.cont.3, %invoke.cont, %catch.7
44 lpad: ; preds = %catch, %entry
45 %cs1 = catchswitch within none [label %catch] unwind label %lpad.1
47 catch: ; preds = %lpad.1
48 %p1 = catchpad within %cs1 [ptr @"\01??_R0H@8", i32 0, ptr null]
49 invoke void @may_throw(i32 3) [ "funclet"(token %p1) ]
50 to label %invoke.cont.3 unwind label %lpad.1
52 invoke.cont.3: ; preds = %catch
53 catchret from %p1 to label %try.cont.9
55 lpad.1: ; preds = %invoke.cont
56 %cs2 = catchswitch within none [label %catch.7] unwind to caller
59 %p2 = catchpad within %cs2 [ptr @"\01??_R0H@8", i32 0, ptr null]
60 call void @may_throw(i32 4) [ "funclet"(token %p2) ]
61 catchret from %p2 to label %try.cont.9
65 ; X86: movl $-1, [[state:[-0-9]+]](%ebp)
66 ; X86: movl $___ehhandler$f, {{.*}}
68 ; X86: movl $0, [[state]](%ebp)
70 ; X86: calll _may_throw
72 ; X86: movl $1, [[state]](%ebp)
74 ; X86: calll _may_throw
76 ; X86: movl $2, [[state]](%ebp)
78 ; X86: calll _may_throw
80 ; X86: movl $3, [[state]](%ebp)
82 ; X86: calll _may_throw
86 ; X64-LABEL: $ip2state$f:
87 ; X64-NEXT: .long .Lfunc_begin0@IMGREL
89 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
91 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
93 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
95 ; X64-NEXT: .long "?catch${{.*}}@?0?f@4HA"@IMGREL
97 ; X64-NEXT: .long "?catch${{.*}}@?0?f@4HA"@IMGREL
100 ; Based on this source:
101 ; extern "C" void may_throw(int);
102 ; struct S { ~S(); };
117 %struct.S = type { i8 }
118 declare void @"\01??1S@@QEAA@XZ"(ptr)
120 define void @g() personality ptr @__CxxFrameHandler3 {
122 %x = alloca %struct.S, align 1
123 %y = alloca %struct.S, align 1
124 invoke void @may_throw(i32 -1)
125 to label %unreachable unwind label %catch.dispatch
127 catch.dispatch: ; preds = %entry
128 %0 = catchswitch within none [label %catch] unwind label %ehcleanup5
130 catch: ; preds = %catch.dispatch
131 %1 = catchpad within %0 [ptr null, i32 64, ptr null]
132 invoke void @may_throw(i32 0) [ "funclet"(token %1) ]
133 to label %invoke.cont unwind label %ehcleanup5
135 invoke.cont: ; preds = %catch
136 invoke void @may_throw(i32 1) [ "funclet"(token %1) ]
137 to label %invoke.cont2 unwind label %ehcleanup
139 invoke.cont2: ; preds = %invoke.cont
140 invoke void @"\01??1S@@QEAA@XZ"(ptr nonnull %y) [ "funclet"(token %1) ]
141 to label %invoke.cont3 unwind label %ehcleanup5
143 invoke.cont3: ; preds = %invoke.cont2
144 invoke void @may_throw(i32 2) [ "funclet"(token %1) ]
145 to label %invoke.cont4 unwind label %ehcleanup5
147 invoke.cont4: ; preds = %invoke.cont3
148 catchret from %1 to label %try.cont
150 try.cont: ; preds = %invoke.cont4
151 call void @"\01??1S@@QEAA@XZ"(ptr nonnull %x)
154 ehcleanup: ; preds = %invoke.cont
155 %2 = cleanuppad within %1 []
156 call void @"\01??1S@@QEAA@XZ"(ptr nonnull %y) [ "funclet"(token %2) ]
157 cleanupret from %2 unwind label %ehcleanup5
159 ehcleanup5: ; preds = %invoke.cont2, %invoke.cont3, %ehcleanup, %catch, %catch.dispatch
160 %3 = cleanuppad within none []
161 call void @"\01??1S@@QEAA@XZ"(ptr nonnull %x) [ "funclet"(token %3) ]
162 cleanupret from %3 unwind to caller
164 unreachable: ; preds = %entry
169 ; X86: movl $-1, [[state:[-0-9]+]](%ebp)
170 ; X86: movl $___ehhandler$g, {{.*}}
172 ; X86: movl $1, [[state]](%ebp)
174 ; X86: calll _may_throw
176 ; X86: movl $2, [[state]](%ebp)
178 ; X86: calll _may_throw
180 ; X86: movl $3, [[state]](%ebp)
182 ; X86: calll _may_throw
184 ; X86: movl $2, [[state]](%ebp)
186 ; X86: calll _may_throw
189 ; X64-LABEL: $ip2state$g:
190 ; X64-NEXT: .long .Lfunc_begin1@IMGREL
192 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
194 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
196 ; X64-NEXT: .long "?catch${{.*}}@?0?g@4HA"@IMGREL
198 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
200 ; X64-NEXT: .long .Ltmp{{.*}}@IMGREL+1
204 ; X86: .safeseh ___ehhandler$f
205 ; X86: .safeseh ___ehhandler$g