[CodeGen] Mark setjmp/catchret MBBs address-taken
[oota-llvm.git] / test / CodeGen / X86 / win-catchpad-csrs.ll
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
3
4 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
5 %eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
6 %eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
7 %eh.ThrowInfo = type { i32, i8*, i8*, i8* }
8
9 $"\01??_R0H@8" = comdat any
10
11 @"\01??_7type_info@@6B@" = external constant i8*
12 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
13
14 declare i32 @getint()
15 declare void @useints(...)
16 declare void @f(i32 %p)
17 declare i32 @__CxxFrameHandler3(...)
18
19 define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
20 entry:
21   %a = call i32 @getint()
22   %b = call i32 @getint()
23   %c = call i32 @getint()
24   %d = call i32 @getint()
25   call void (...) @useints(i32 %a, i32 %b, i32 %c, i32 %d)
26   invoke void @f(i32 1)
27           to label %try.cont unwind label %catch.dispatch
28
29 catch.dispatch:                                   ; preds = %entry
30   %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
31           to label %catch unwind label %catchendblock
32
33 catch:
34   invoke void @f(i32 2)
35           to label %invoke.cont.2 unwind label %catchendblock
36
37 invoke.cont.2:                                    ; preds = %catch
38   catchret %0 to label %try.cont
39
40 try.cont:                                         ; preds = %entry, %invoke.cont.2, %invoke.cont.3
41   ret i32 0
42
43 catchendblock:                                    ; preds = %catch,
44   catchendpad unwind to caller
45 }
46
47 ; X86-LABEL: _try_catch_catch:
48 ; X86: pushl %ebp
49 ; X86: movl %esp, %ebp
50 ; X86: pushl %ebx
51 ; X86: pushl %edi
52 ; X86: pushl %esi
53 ; X86: subl ${{[0-9]+}}, %esp
54 ; X86: calll _getint
55 ; X86: calll _getint
56 ; X86: calll _getint
57 ; X86: calll _getint
58 ; X86: calll _useints
59 ; X86: movl $0, -{{[0-9]+}}(%ebp)
60 ; X86: movl $1, (%esp)
61 ; X86: calll _f
62 ; X86: [[contbb:LBB0_[0-9]+]]: # %try.cont
63 ; X86: popl %esi
64 ; X86: popl %edi
65 ; X86: popl %ebx
66 ; X86: popl %ebp
67 ; X86: retl
68
69 ; X86: [[restorebb:LBB0_[0-9]+]]:
70 ; X86: movl -16(%ebp), %esp
71 ; X86: addl $12, %ebp
72 ; X86: jmp [[contbb]]
73
74 ; X86: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
75 ; X86: LBB0_[[catch1bb]]: # %catch.dispatch{{$}}
76 ; X86: pushl %ebp
77 ; X86-NOT: pushl
78 ; X86: subl $16, %esp
79 ; X86: addl $12, %ebp
80 ; X86: movl $1, -{{[0-9]+}}(%ebp)
81 ; X86: movl $2, (%esp)
82 ; X86: calll _f
83 ; X86: movl $[[restorebb]], %eax
84 ; X86-NEXT: addl $16, %esp
85 ; X86-NEXT: popl %ebp
86 ; X86-NEXT: retl
87
88 ; X86: L__ehtable$try_catch_catch:
89 ; X86: $handlerMap$0$try_catch_catch:
90 ; X86:   .long   0
91 ; X86:   .long   "??_R0H@8"
92 ; X86:   .long   0
93 ; X86:   .long   "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"
94
95 ; X64-LABEL: try_catch_catch:
96 ; X64: pushq %rbp
97 ; X64: .seh_pushreg 5
98 ; X64: pushq %rsi
99 ; X64: .seh_pushreg 6
100 ; X64: pushq %rdi
101 ; X64: .seh_pushreg 7
102 ; X64: pushq %rbx
103 ; X64: .seh_pushreg 3
104 ; X64: subq $40, %rsp
105 ; X64: .seh_stackalloc 40
106 ; X64: leaq 32(%rsp), %rbp
107 ; X64: .seh_setframe 5, 32
108 ; X64: .seh_endprologue
109 ; X64: callq getint
110 ; X64: callq getint
111 ; X64: callq getint
112 ; X64: callq getint
113 ; X64: callq useints
114 ; X64: movl $1, %ecx
115 ; X64: callq f
116 ; X64: [[contbb:\.LBB0_[0-9]+]]: # Block address taken
117 ; X64-NEXT:                      # %try.cont
118 ; X64: addq $40, %rsp
119 ; X64: popq %rbp
120 ; X64: retq
121
122 ; X64: "?catch$[[catch1bb:[0-9]+]]@?0?try_catch_catch@4HA":
123 ; X64: LBB0_[[catch1bb]]: # %catch.dispatch{{$}}
124 ; X64: movq %rdx, 16(%rsp)
125 ; X64: pushq %rbp
126 ; X64: .seh_pushreg 5
127 ; X64: pushq %rsi
128 ; X64: .seh_pushreg 6
129 ; X64: pushq %rdi
130 ; X64: .seh_pushreg 7
131 ; X64: pushq %rbx
132 ; X64: .seh_pushreg 3
133 ; X64: subq $40, %rsp
134 ; X64: .seh_stackalloc 40
135 ; X64: leaq 32(%rdx), %rbp
136 ; X64: .seh_endprologue
137 ; X64: movl $2, %ecx
138 ; X64: callq f
139 ; X64: leaq [[contbb]](%rip), %rax
140 ; X64: addq $40, %rsp
141 ; X64: popq %rbx
142 ; X64: popq %rdi
143 ; X64: popq %rsi
144 ; X64: popq %rbp
145 ; X64: retq
146
147 ; X64: $handlerMap$0$try_catch_catch:
148 ; X64:   .long   0
149 ; X64:   .long   "??_R0H@8"@IMGREL
150 ; X64:   .long   0
151 ; X64:   .long   "?catch$[[catch1bb]]@?0?try_catch_catch@4HA"@IMGREL
152 ; X64:   .long   88
153
154 define i32 @try_one_csr() personality i32 (...)* @__CxxFrameHandler3 {
155 entry:
156   %a = call i32 @getint()
157   %b = call i32 @getint()
158   call void (...) @useints(i32 %a)
159   invoke void @f(i32 1)
160           to label %try.cont unwind label %catch.dispatch
161
162 catch.dispatch:                                   ; preds = %entry
163   %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
164           to label %catch unwind label %catchendblock
165
166 catch:
167   catchret %0 to label %try.cont
168
169 try.cont:                                         ; preds = %entry, %invoke.cont.2, %invoke.cont.3
170   ret i32 0
171
172 catchendblock:                                    ; preds = %catch,
173   catchendpad unwind to caller
174 }
175
176 ; X64-LABEL: try_one_csr:
177 ; X64: pushq %rbp
178 ; X64: .seh_pushreg 5
179 ; X64: pushq %rsi
180 ; X64: .seh_pushreg 6
181 ; X64-NOT: pushq
182 ; X64: subq $40, %rsp
183 ; X64: .seh_stackalloc 40
184 ; X64: leaq 32(%rsp), %rbp
185 ; X64: .seh_setframe 5, 32
186 ; X64: .seh_endprologue
187 ; X64: callq getint
188 ; X64: callq getint
189 ; X64: callq useints
190 ; X64: movl $1, %ecx
191 ; X64: callq f
192 ; X64: [[contbb:\.LBB1_[0-9]+]]: # Block address taken
193 ; X64-NEXT:                      # %try.cont
194 ; X64: addq $40, %rsp
195 ; X64-NOT: popq
196 ; X64: popq %rsi
197 ; X64: popq %rbp
198 ; X64: retq
199
200 ; X64: "?catch$[[catch1bb:[0-9]+]]@?0?try_one_csr@4HA":
201 ; X64: LBB1_[[catch1bb]]: # %catch.dispatch{{$}}
202 ; X64: movq %rdx, 16(%rsp)
203 ; X64: pushq %rbp
204 ; X64: .seh_pushreg 5
205 ; X64: pushq %rsi
206 ; X64: .seh_pushreg 6
207 ; X64: subq $40, %rsp
208 ; X64: .seh_stackalloc 40
209 ; X64: leaq 32(%rdx), %rbp
210 ; X64: .seh_endprologue
211 ; X64: leaq [[contbb]](%rip), %rax
212 ; X64: addq $40, %rsp
213 ; X64: popq %rsi
214 ; X64: popq %rbp
215 ; X64: retq
216
217 ; X64: $handlerMap$0$try_one_csr:
218 ; X64:   .long   0
219 ; X64:   .long   "??_R0H@8"@IMGREL
220 ; X64:   .long   0
221 ; X64:   .long   "?catch$[[catch1bb]]@?0?try_one_csr@4HA"@IMGREL
222 ; X64:   .long   72
223
224 define i32 @try_no_csr() personality i32 (...)* @__CxxFrameHandler3 {
225 entry:
226   invoke void @f(i32 1)
227           to label %try.cont unwind label %catch.dispatch
228
229 catch.dispatch:                                   ; preds = %entry
230   %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
231           to label %catch unwind label %catchendblock
232
233 catch:
234   catchret %0 to label %try.cont
235
236 try.cont:                                         ; preds = %entry, %invoke.cont.2, %invoke.cont.3
237   ret i32 0
238
239 catchendblock:                                    ; preds = %catch,
240   catchendpad unwind to caller
241 }
242
243 ; X64-LABEL: try_no_csr:
244 ; X64: pushq %rbp
245 ; X64: .seh_pushreg 5
246 ; X64-NOT: pushq
247 ; X64: subq $48, %rsp
248 ; X64: .seh_stackalloc 48
249 ; X64: leaq 48(%rsp), %rbp
250 ; X64: .seh_setframe 5, 48
251 ; X64: .seh_endprologue
252 ; X64: movl $1, %ecx
253 ; X64: callq f
254 ; X64: [[contbb:\.LBB2_[0-9]+]]: # Block address taken
255 ; X64-NEXT:                      # %try.cont
256 ; X64: addq $48, %rsp
257 ; X64-NOT: popq
258 ; X64: popq %rbp
259 ; X64: retq
260
261 ; X64: "?catch$[[catch1bb:[0-9]+]]@?0?try_no_csr@4HA":
262 ; X64: LBB2_[[catch1bb]]: # %catch.dispatch{{$}}
263 ; X64: movq %rdx, 16(%rsp)
264 ; X64: pushq %rbp
265 ; X64: .seh_pushreg 5
266 ; X64: subq $32, %rsp
267 ; X64: .seh_stackalloc 32
268 ; X64: leaq 48(%rdx), %rbp
269 ; X64: .seh_endprologue
270 ; X64: leaq [[contbb]](%rip), %rax
271 ; X64: addq $32, %rsp
272 ; X64: popq %rbp
273 ; X64: retq
274
275 ; X64: $handlerMap$0$try_no_csr:
276 ; X64:   .long   0
277 ; X64:   .long   "??_R0H@8"@IMGREL
278 ; X64:   .long   0
279 ; X64:   .long   "?catch$[[catch1bb]]@?0?try_no_csr@4HA"@IMGREL
280 ; X64:   .long   56