1 ; RUN: llc -stack-symbol-ordering=0 -verify-machineinstrs -mtriple=i686-pc-windows-msvc < %s | FileCheck --check-prefix=X86 %s
2 ; RUN: llc -stack-symbol-ordering=0 -verify-machineinstrs -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 { ptr, ptr, [3 x i8] }
17 %eh.CatchableType = type { i32, ptr, i32, i32, i32, i32, ptr }
18 %eh.CatchableTypeArray.1 = type { i32, [1 x ptr] }
19 %eh.ThrowInfo = type { i32, ptr, ptr, ptr }
21 $"\01??_R0H@8" = comdat any
23 @"\01??_7type_info@@6B@" = external constant ptr
24 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { ptr @"\01??_7type_info@@6B@", ptr null, [3 x i8] c".H\00" }, comdat
27 declare void @f(i32 %p, ptr %l)
29 declare i32 @__CxxFrameHandler3(...)
31 define i32 @try_catch_catch() personality ptr @__CxxFrameHandler3 {
35 invoke void @f(i32 1, ptr %local)
36 to label %try.cont unwind label %catch.dispatch
38 catch.dispatch: ; preds = %entry
39 %cs = catchswitch within none [label %handler1, label %handler2] unwind to caller
42 %h1 = catchpad within %cs [ptr @"\01??_R0H@8", i32 0, ptr %e.addr]
43 %e = load i32, ptr %e.addr
44 call void @f(i32 %e, ptr %local) [ "funclet"(token %h1) ]
45 catchret from %h1 to label %try.cont
48 %h2 = catchpad within %cs [ptr null, i32 64, ptr null]
49 call void @f(i32 3, ptr %local) [ "funclet"(token %h2) ]
50 catchret from %h2 to label %try.cont
56 ; X86-LABEL: _try_catch_catch:
57 ; X86: movl %esp, -[[sp_offset:[0-9]+]](%ebp)
58 ; X86: movl $0, -{{[0-9]+}}(%ebp)
59 ; X86: leal -[[local_offs:[0-9]+]](%ebp), %[[addr_reg:[a-z]+]]
60 ; X86-DAG: pushl %[[addr_reg]]
63 ; X86: [[contbb:LBB0_[0-9]+]]: # %try.cont
66 ; FIXME: These should be de-duplicated.
67 ; X86: [[restorebb1:LBB0_[0-9]+]]: # Block address taken
68 ; X86-NEXT: # %handler1
69 ; X86-NEXT: addl $12, %ebp
72 ; X86: [[restorebb2:LBB0_[0-9]+]]: # Block address taken
73 ; X86-NEXT: # %handler2
74 ; X86-NEXT: addl $12, %ebp
77 ; X86: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
78 ; X86: LBB0_[[catch1bb]]: # %handler1{{$}}
82 ; X86: movl %esp, -[[sp_offset]](%ebp)
83 ; X86-DAG: movl -32(%ebp), %[[e_reg:[a-z]+]]
84 ; X86-DAG: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
85 ; X86-DAG: movl $1, -{{[0-9]+}}(%ebp)
86 ; X86: pushl %[[addr_reg]]
87 ; X86: pushl %[[e_reg]]
90 ; X86: movl $[[restorebb1]], %eax
95 ; X86: "?catch$[[catch2bb:[0-9]+]]@?0?try_catch_catch@4HA":
96 ; X86: LBB0_[[catch2bb]]: # %handler2{{$}}
100 ; X86: movl %esp, -[[sp_offset]](%ebp)
101 ; X86-DAG: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
102 ; X86-DAG: movl $1, -{{[0-9]+}}(%ebp)
103 ; X86: pushl %[[addr_reg]]
107 ; X86: movl $[[restorebb2]], %eax
112 ; X86: L__ehtable$try_catch_catch:
113 ; X86: $handlerMap$0$try_catch_catch:
115 ; X86-NEXT: .long "??_R0H@8"
116 ; X86-NEXT: .long -20
117 ; X86-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"
121 ; X86-NEXT: .long "?catch$[[catch2bb]]@?0?try_catch_catch@4HA"
123 ; X64-LABEL: try_catch_catch:
126 ; X64: .seh_pushreg %rbp
127 ; X64: subq $[[STCK_ALLOC:.*]], %rsp
128 ; X64: .seh_stackalloc [[STCK_ALLOC]]
129 ; X64: leaq [[STCK_ALLOC]](%rsp), %rbp
130 ; X64: .seh_setframe %rbp, [[STCK_ALLOC]]
131 ; X64: .seh_endprologue
132 ; X64: movq $-2, -16(%rbp)
134 ; X64-DAG: leaq -[[local_offs:[0-9]+]](%rbp), %rdx
135 ; X64-DAG: movl $1, %ecx
137 ; X64: [[contbb:\.LBB0_[0-9]+]]: # Block address taken
138 ; X64-NEXT: # %try.cont
139 ; X64: addq $[[STCK_ALLOC]], %rsp
143 ; X64: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
144 ; X64: LBB0_[[catch1bb]]: # %handler1{{$}}
145 ; X64: movq %rdx, 16(%rsp)
147 ; X64: .seh_pushreg %rbp
148 ; X64: subq $32, %rsp
149 ; X64: .seh_stackalloc 32
150 ; X64: leaq [[STCK_ALLOC]](%rdx), %rbp
151 ; X64: .seh_endprologue
152 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
153 ; X64-DAG: movl -4(%rbp), %ecx
155 ; X64: leaq [[contbb]](%rip), %rax
156 ; X64-NEXT: addq $32, %rsp
157 ; X64-NEXT: popq %rbp
160 ; X64: "?catch$[[catch2bb:[0-9]+]]@?0?try_catch_catch@4HA":
161 ; X64: LBB0_[[catch2bb]]: # %handler2{{$}}
162 ; X64: movq %rdx, 16(%rsp)
164 ; X64: .seh_pushreg %rbp
165 ; X64: subq $32, %rsp
166 ; X64: .seh_stackalloc 32
167 ; X64: leaq [[STCK_ALLOC]](%rdx), %rbp
168 ; X64: .seh_endprologue
169 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
170 ; X64-DAG: movl $3, %ecx
172 ; X64: leaq [[contbb]](%rip), %rax
173 ; X64-NEXT: addq $32, %rsp
174 ; X64-NEXT: popq %rbp
177 ; X64: $cppxdata$try_catch_catch:
178 ; X64-NEXT: .long 429065506
180 ; X64-NEXT: .long ($stateUnwindMap$try_catch_catch)@IMGREL
182 ; X64-NEXT: .long ($tryMap$try_catch_catch)@IMGREL
184 ; X64-NEXT: .long ($ip2state$try_catch_catch)@IMGREL
189 ; X64: $tryMap$try_catch_catch:
194 ; X64-NEXT: .long ($handlerMap$0$try_catch_catch)@IMGREL
196 ; X64: $handlerMap$0$try_catch_catch:
198 ; X64-NEXT: .long "??_R0H@8"@IMGREL
200 ; X64-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"@IMGREL
205 ; X64-NEXT: .long "?catch$[[catch2bb]]@?0?try_catch_catch@4HA"@IMGREL
208 ; X64: $ip2state$try_catch_catch:
209 ; X64-NEXT: .long .Lfunc_begin0@IMGREL
211 ; X64-NEXT: .long .Ltmp0@IMGREL+1
213 ; X64-NEXT: .long .Ltmp1@IMGREL+1
215 ; X64-NEXT: .long "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"@IMGREL
217 ; X64-NEXT: .long "?catch$[[catch2bb]]@?0?try_catch_catch@4HA"@IMGREL
221 define i32 @branch_to_normal_dest() personality ptr @__CxxFrameHandler3 {
223 invoke void @f(i32 1, ptr null)
224 to label %try.cont unwind label %catch.dispatch
227 %cs1 = catchswitch within none [label %catch] unwind to caller
230 %cp1 = catchpad within %cs1 [ptr null, i32 64, ptr null]
234 %V = call i1 @getbool() [ "funclet"(token %cp1) ]
235 br i1 %V, label %loop, label %catch.done
238 catchret from %cp1 to label %try.cont
244 ; X86-LABEL: _branch_to_normal_dest:
247 ; X86: [[contbb:LBB1_[0-9]+]]: # %try.cont
250 ; X86: [[restorebb:LBB1_[0-9]+]]: # Block address taken
251 ; X86-NEXT: # %catch.done
252 ; X86-NEXT: addl $12, %ebp
253 ; X86: jmp [[contbb]]
255 ; X86: "?catch$[[catchbb:[0-9]+]]@?0?branch_to_normal_dest@4HA":
256 ; X86: LBB1_[[catchbb]]: # %catch{{$}}
259 ; X86: addl $12, %ebp
260 ; X86: movl $1, -16(%ebp)
261 ; X86: LBB1_[[loopbb:[0-9]+]]: # %loop
262 ; X86: calll _getbool
264 ; X86: jne LBB1_[[loopbb]]
266 ; X86-NEXT: movl $[[restorebb]], %eax
267 ; X86-NEXT: addl $8, %esp
268 ; X86-NEXT: popl %ebp
271 ; X86: L__ehtable$branch_to_normal_dest:
272 ; X86: $handlerMap$0$branch_to_normal_dest:
276 ; X86-NEXT: .long "?catch$[[catchbb]]@?0?branch_to_normal_dest@4HA"
278 ; X64-LABEL: branch_to_normal_dest:
281 ; X64: .seh_pushreg %rbp
282 ; X64: subq $48, %rsp
283 ; X64: .seh_stackalloc 48
284 ; X64: leaq 48(%rsp), %rbp
285 ; X64: .seh_setframe %rbp, 48
286 ; X64: .seh_endprologue
287 ; X64: .Ltmp[[before_call:[0-9]+]]:
289 ; X64: .Ltmp[[after_call:[0-9]+]]:
290 ; X64: [[contbb:\.LBB1_[0-9]+]]: # Block address taken
291 ; X64-NEXT: # %try.cont
292 ; X64: addq $48, %rsp
296 ; X64: "?catch$[[catchbb:[0-9]+]]@?0?branch_to_normal_dest@4HA":
297 ; X64: LBB1_[[catchbb]]: # %catch{{$}}
298 ; X64: movq %rdx, 16(%rsp)
300 ; X64: .seh_pushreg %rbp
301 ; X64: subq $32, %rsp
302 ; X64: .seh_stackalloc 32
303 ; X64: leaq 48(%rdx), %rbp
304 ; X64: .seh_endprologue
305 ; X64: .LBB1_[[normal_dest_bb:[0-9]+]]: # %loop
308 ; X64: jne .LBB1_[[normal_dest_bb]]
310 ; X64: leaq [[contbb]](%rip), %rax
311 ; X64-NEXT: addq $32, %rsp
312 ; X64-NEXT: popq %rbp
315 ; X64-LABEL: $cppxdata$branch_to_normal_dest:
316 ; X64-NEXT: .long 429065506
318 ; X64-NEXT: .long ($stateUnwindMap$branch_to_normal_dest)@IMGREL
320 ; X64-NEXT: .long ($tryMap$branch_to_normal_dest)@IMGREL
322 ; X64-NEXT: .long ($ip2state$branch_to_normal_dest)@IMGREL
327 ; X64-LABEL: $stateUnwindMap$branch_to_normal_dest:
333 ; X64-LABEL: $tryMap$branch_to_normal_dest:
338 ; X64-NEXT: .long ($handlerMap$0$branch_to_normal_dest)@IMGREL
340 ; X64-LABEL: $handlerMap$0$branch_to_normal_dest:
344 ; X64-NEXT: .long "?catch$[[catchbb]]@?0?branch_to_normal_dest@4HA"@IMGREL
347 ; X64-LABEL: $ip2state$branch_to_normal_dest:
348 ; X64-NEXT: .long .Lfunc_begin1@IMGREL
350 ; X64-NEXT: .long .Ltmp[[before_call]]@IMGREL+1
352 ; X64-NEXT: .long .Ltmp[[after_call]]@IMGREL+1
354 ; X64-NEXT: .long "?catch$[[catchbb]]@?0?branch_to_normal_dest@4HA"@IMGREL