1 ; RUN: llc -mtriple=i686-pc-windows-msvc < %s | FileCheck --check-prefix=X86 %s
2 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck --check-prefix=X64 %s
4 ; Loosely based on IR for this C++ source code:
16 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
17 %eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
18 %eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
19 %eh.ThrowInfo = type { i32, i8*, i8*, i8* }
21 $"\01??_R0H@8" = comdat any
23 @"\01??_7type_info@@6B@" = external constant i8*
24 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
27 declare void @f(i32 %p, i32* %l)
29 declare i32 @__CxxFrameHandler3(...)
31 define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
35 invoke void @f(i32 1, i32* %local)
36 to label %try.cont unwind label %catch.dispatch
38 catch.dispatch: ; preds = %entry
39 %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e.addr]
40 to label %catch unwind label %catch.dispatch.2
42 catch: ; preds = %catch.dispatch
43 %e = load i32, i32* %e.addr
44 invoke void @f(i32 %e, i32* %local)
45 to label %invoke.cont.2 unwind label %catchendblock
47 invoke.cont.2: ; preds = %catch
48 catchret %0 to label %try.cont
50 catch.dispatch.2: ; preds = %catch.dispatch
51 %1 = catchpad [i8* null, i32 u0x40, i8* null]
52 to label %catch.2 unwind label %catchendblock
54 catch.2: ; preds = %catch.dispatch.2
55 invoke void @f(i32 3, i32* %local)
56 to label %invoke.cont.3 unwind label %catchendblock
58 invoke.cont.3: ; preds = %catch.2
59 catchret %1 to label %try.cont
61 try.cont: ; preds = %entry, %invoke.cont.2, %invoke.cont.3
64 catchendblock: ; preds = %catch, %catch.2, %catch.dispatch.2
65 catchendpad unwind to caller
68 ; X86-LABEL: _try_catch_catch:
69 ; X86: movl $0, -{{[0-9]+}}(%ebp)
70 ; X86: leal -[[local_offs:[0-9]+]](%ebp), %[[addr_reg:[a-z]+]]
71 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
72 ; X86-DAG: movl $1, (%esp)
74 ; X86: [[contbb:LBB0_[0-9]+]]: # %try.cont
77 ; X86: [[restorebb1:LBB0_[0-9]+]]: # Block address taken
78 ; X86-NEXT: # %invoke.cont.2
79 ; X86: movl -16(%ebp), %esp
83 ; FIXME: These should be de-duplicated.
84 ; X86: [[restorebb2:LBB0_[0-9]+]]: # Block address taken
85 ; X86-NEXT: # %invoke.cont.3
86 ; X86: movl -16(%ebp), %esp
90 ; X86: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
91 ; X86: LBB0_[[catch1bb]]: # %catch.dispatch{{$}}
95 ; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
96 ; X86: movl -32(%ebp), %[[e_reg:[a-z]+]]
97 ; X86: movl $1, -{{[0-9]+}}(%ebp)
98 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
99 ; X86-DAG: movl %[[e_reg]], (%esp)
101 ; X86-NEXT: movl $[[restorebb1]], %eax
102 ; X86-NEXT: addl $8, %esp
103 ; X86-NEXT: popl %ebp
106 ; X86: "?catch$[[catch2bb:[0-9]+]]@?0?try_catch_catch@4HA":
107 ; X86: LBB0_[[catch2bb]]: # %catch.dispatch.2{{$}}
110 ; X86: addl $12, %ebp
111 ; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
112 ; X86: movl $1, -{{[0-9]+}}(%ebp)
113 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
114 ; X86-DAG: movl $3, (%esp)
116 ; X86-NEXT: movl $[[restorebb2]], %eax
117 ; X86-NEXT: addl $8, %esp
118 ; X86-NEXT: popl %ebp
121 ; X86: L__ehtable$try_catch_catch:
122 ; X86: $handlerMap$0$try_catch_catch:
124 ; X86-NEXT: .long "??_R0H@8"
125 ; X86-NEXT: .long -20
126 ; X86-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"
130 ; X86-NEXT: .long "?catch$[[catch2bb]]@?0?try_catch_catch@4HA"
132 ; X64-LABEL: try_catch_catch:
135 ; X64: .seh_pushreg 5
136 ; X64: subq $48, %rsp
137 ; X64: .seh_stackalloc 48
138 ; X64: leaq 48(%rsp), %rbp
139 ; X64: .seh_setframe 5, 48
140 ; X64: .seh_endprologue
142 ; X64-DAG: leaq -[[local_offs:[0-9]+]](%rbp), %rdx
143 ; X64-DAG: movl $1, %ecx
145 ; X64: [[contbb:\.LBB0_[0-9]+]]: # Block address taken
146 ; X64-NEXT: # %try.cont
147 ; X64: addq $48, %rsp
151 ; X64: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
152 ; X64: LBB0_[[catch1bb]]: # %catch.dispatch{{$}}
153 ; X64: movq %rdx, 16(%rsp)
155 ; X64: .seh_pushreg 5
156 ; X64: subq $32, %rsp
157 ; X64: .seh_stackalloc 32
158 ; X64: leaq 48(%rdx), %rbp
159 ; X64: .seh_endprologue
161 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
162 ; X64-DAG: movl -4(%rbp), %ecx
164 ; X64: leaq [[contbb]](%rip), %rax
165 ; X64-NEXT: addq $32, %rsp
166 ; X64-NEXT: popq %rbp
169 ; X64: "?catch$[[catch2bb:[0-9]+]]@?0?try_catch_catch@4HA":
170 ; X64: LBB0_[[catch2bb]]: # %catch.dispatch.2{{$}}
171 ; X64: movq %rdx, 16(%rsp)
173 ; X64: .seh_pushreg 5
174 ; X64: subq $32, %rsp
175 ; X64: .seh_stackalloc 32
176 ; X64: leaq 48(%rdx), %rbp
177 ; X64: .seh_endprologue
178 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
179 ; X64-DAG: movl $3, %ecx
182 ; X64: leaq [[contbb]](%rip), %rax
183 ; X64-NEXT: addq $32, %rsp
184 ; X64-NEXT: popq %rbp
187 ; X64: $cppxdata$try_catch_catch:
188 ; X64-NEXT: .long 429065506
190 ; X64-NEXT: .long ($stateUnwindMap$try_catch_catch)@IMGREL
192 ; X64-NEXT: .long ($tryMap$try_catch_catch)@IMGREL
194 ; X64-NEXT: .long ($ip2state$try_catch_catch)@IMGREL
199 ; X64: $tryMap$try_catch_catch:
204 ; X64-NEXT: .long ($handlerMap$0$try_catch_catch)@IMGREL
206 ; X64: $handlerMap$0$try_catch_catch:
208 ; X64-NEXT: .long "??_R0H@8"@IMGREL
209 ; FIXME: This should probably be offset from rsp, not rbp.
211 ; X64-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"@IMGREL
216 ; X64-NEXT: .long "?catch$[[catch2bb]]@?0?try_catch_catch@4HA"@IMGREL
219 ; X64: $ip2state$try_catch_catch:
220 ; X64-NEXT: .long .Lfunc_begin0@IMGREL
222 ; X64-NEXT: .long .Ltmp0@IMGREL+1
224 ; X64-NEXT: .long .Ltmp4@IMGREL+1
226 ; X64-NEXT: .long .Ltmp3@IMGREL+1
230 define i32 @branch_to_normal_dest() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
232 invoke void @f(i32 1, i32* null)
233 to label %try.cont unwind label %catch.dispatch
236 %0 = catchpad [i8* null, i32 64, i8* null]
237 to label %catch unwind label %catchendblock
240 %V = call i1 @getbool()
241 br i1 %V, label %catch, label %catch.done
244 catchret %0 to label %try.cont
250 catchendpad unwind to caller
253 ; X86-LABEL: _branch_to_normal_dest:
256 ; X86: [[contbb:LBB1_[0-9]+]]: # %try.cont
259 ; X86: [[restorebb:LBB1_[0-9]+]]: # Block address taken
260 ; X86-NEXT: # %catch.done
261 ; X86: movl -16(%ebp), %esp
262 ; X86: addl $12, %ebp
263 ; X86: jmp [[contbb]]
265 ; X86: "?catch$[[catchdispbb:[0-9]+]]@?0?branch_to_normal_dest@4HA":
266 ; X86: LBB1_[[catchdispbb]]: # %catch.dispatch{{$}}
269 ; X86: addl $12, %ebp
271 ; X86: LBB1_[[catchbb:[0-9]+]]: # %catch
272 ; X86: movl $-1, -16(%ebp)
273 ; X86: calll _getbool
275 ; X86: jne LBB1_[[catchbb]]
277 ; X86-NEXT: movl $[[restorebb]], %eax
278 ; X86-NEXT: addl $8, %esp
279 ; X86-NEXT: popl %ebp
282 ; X86: L__ehtable$branch_to_normal_dest:
283 ; X86: $handlerMap$0$branch_to_normal_dest:
287 ; X86-NEXT: .long "?catch$[[catchdispbb]]@?0?branch_to_normal_dest@4HA"
289 ; X64-LABEL: branch_to_normal_dest:
292 ; X64: .seh_pushreg 5
293 ; X64: subq $48, %rsp
294 ; X64: .seh_stackalloc 48
295 ; X64: leaq 48(%rsp), %rbp
296 ; X64: .seh_setframe 5, 48
297 ; X64: .seh_endprologue
298 ; X64: .Ltmp[[before_call:[0-9]+]]:
300 ; X64: .Ltmp[[after_call:[0-9]+]]:
301 ; X64: [[contbb:\.LBB1_[0-9]+]]: # Block address taken
302 ; X64-NEXT: # %try.cont
303 ; X64: addq $48, %rsp
307 ; X64: "?catch$[[catchbb:[0-9]+]]@?0?branch_to_normal_dest@4HA":
308 ; X64: LBB1_[[catchbb]]: # %catch.dispatch{{$}}
309 ; X64: movq %rdx, 16(%rsp)
311 ; X64: .seh_pushreg 5
312 ; X64: subq $32, %rsp
313 ; X64: .seh_stackalloc 32
314 ; X64: leaq 48(%rdx), %rbp
315 ; X64: .seh_endprologue
316 ; X64: .LBB1_[[normal_dest_bb:[0-9]+]]: # %catch
319 ; X64: jne .LBB1_[[normal_dest_bb]]
321 ; X64: leaq [[contbb]](%rip), %rax
322 ; X64-NEXT: addq $32, %rsp
323 ; X64-NEXT: popq %rbp
326 ; X64-LABEL: $cppxdata$branch_to_normal_dest:
327 ; X64-NEXT: .long 429065506
329 ; X64-NEXT: .long ($stateUnwindMap$branch_to_normal_dest)@IMGREL
331 ; X64-NEXT: .long ($tryMap$branch_to_normal_dest)@IMGREL
333 ; X64-NEXT: .long ($ip2state$branch_to_normal_dest)@IMGREL
338 ; X64-LABEL: $stateUnwindMap$branch_to_normal_dest:
344 ; X64-LABEL: $tryMap$branch_to_normal_dest:
349 ; X64-NEXT: .long ($handlerMap$0$branch_to_normal_dest)@IMGREL
351 ; X64-LABEL: $handlerMap$0$branch_to_normal_dest:
355 ; X64-NEXT: .long "?catch$[[catchbb]]@?0?branch_to_normal_dest@4HA"@IMGREL
358 ; X64-LABEL: $ip2state$branch_to_normal_dest:
359 ; X64-NEXT: .long .Lfunc_begin1@IMGREL
361 ; X64-NEXT: .long .Ltmp[[before_call]]@IMGREL+1
363 ; X64-NEXT: .long .Ltmp[[after_call]]@IMGREL+1