7ab59ab7223ccfd5fdd90fc76f5731b470c8060e
[oota-llvm.git] / test / CodeGen / X86 / win-catchpad.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 ; Loosely based on IR for this C++ source code:
5 ;   void f(int p);
6 ;   int main() {
7 ;     try {
8 ;       f(1);
9 ;     } catch (int) {
10 ;       f(2);
11 ;     } catch (...) {
12 ;       f(3);
13 ;     }
14 ;   }
15
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* }
20 %eh.CatchHandlerType = type { i32, i8* }
21
22 $"\01??_R0H@8" = comdat any
23
24 @"\01??_7type_info@@6B@" = external constant i8*
25 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
26
27 @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"
28 @llvm.eh.handlertype.H.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
29
30 declare void @f(i32 %p, i32* %l)
31 declare i32 @__CxxFrameHandler3(...)
32 declare void @barrier()
33
34 define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
35 entry:
36   %local = alloca i32
37   invoke void @f(i32 1, i32* %local)
38           to label %try.cont unwind label %catch.dispatch
39
40 catch.dispatch:                                   ; preds = %entry
41   %0 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
42           to label %catch unwind label %catch.dispatch.2
43
44 catch:                                            ; preds = %catch.dispatch
45   ; FIXME: Remove this barrier once we add more real register allocation barriers.
46   invoke void @barrier()
47           to label %barrier.split unwind label %catchendblock
48 barrier.split:
49   invoke void @f(i32 2, i32* %local)
50           to label %invoke.cont.2 unwind label %catchendblock
51
52 invoke.cont.2:                                    ; preds = %catch
53   catchret %0 to label %try.cont
54
55 catch.dispatch.2:                                   ; preds = %catch.dispatch
56   %1 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
57           to label %catch.2 unwind label %catchendblock
58
59 catch.2:                                            ; preds = %catch.dispatch.2
60   invoke void @f(i32 3, i32* %local)
61           to label %invoke.cont.3 unwind label %catchendblock
62
63 invoke.cont.3:                                    ; preds = %catch.2
64   catchret %1 to label %try.cont
65
66 try.cont:                                         ; preds = %entry, %invoke.cont.2, %invoke.cont.3
67   ret i32 0
68
69 catchendblock:                                    ; preds = %catch, %catch.2, %catch.dispatch.2
70   catchendpad unwind to caller
71 }
72
73 ; X86-LABEL: _try_catch_catch:
74 ; X86: movl $0, -{{[0-9]+}}(%ebp)
75 ; X86: leal -[[local_offs:[0-9]+]](%ebp), %[[addr_reg:[a-z]+]]
76 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
77 ; X86-DAG: movl $1, (%esp)
78 ; X86: calll _f
79 ; X86: [[contbb:LBB0_[0-9]+]]:
80 ; X86: movl -{{[0-9]+}}(%ebp), %esp
81 ; X86: retl
82
83 ; X86: [[catch1bb:LBB0_[0-9]+]]: # %catch{{$}}
84 ; X86: addl $12, %ebp
85 ; X86: subl $8, %esp
86 ; X86: calll _barrier
87 ; X86: movl $1, -{{[0-9]+}}(%ebp)
88 ; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
89 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
90 ; X86-DAG: movl $2, (%esp)
91 ; X86: calll _f
92 ; X86: movl $[[contbb]], %eax
93 ; X86-NEXT: addl $8, %esp
94 ; X86-NEXT: retl
95
96 ; X86: [[catch2bb:LBB0_[0-9]+]]: # %catch.2{{$}}
97 ; X86: addl $12, %ebp
98 ; X86: subl $8, %esp
99 ; X86: movl $1, -{{[0-9]+}}(%ebp)
100 ; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
101 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
102 ; X86-DAG: movl $3, (%esp)
103 ; X86: calll _f
104 ; X86: movl $[[contbb]], %eax
105 ; X86-NEXT: addl $8, %esp
106 ; X86-NEXT: retl
107
108 ; X86: L__ehtable$try_catch_catch:
109 ; X86: $handlerMap$0$try_catch_catch:
110 ; X86:   .long   0
111 ; X86:   .long   "??_R0H@8"
112 ; X86:   .long   0
113 ; X86:   .long   [[catch1bb]]
114 ; X86:   .long   0
115 ; X86:   .long   "??_R0H@8"
116 ; X86:   .long   0
117 ; X86:   .long   [[catch2bb]]
118
119 ; X64-LABEL: try_catch_catch:
120 ; X64: pushq %rbp
121 ; X64: .seh_pushreg 5
122 ; X64: subq $48, %rsp
123 ; X64: .seh_stackalloc 48
124 ; X64: leaq 48(%rsp), %rbp
125 ; X64: .seh_setframe 5, 48
126 ; X64-DAG: leaq -[[local_offs:[0-9]+]](%rbp), %rdx
127 ; X64-DAG: movl $1, %ecx
128 ; X64: callq f
129 ; X64: [[contbb:\.LBB0_[0-9]+]]:
130 ; X64: addq $48, %rsp
131 ; X64: popq %rbp
132 ; X64: retq
133
134 ; X64: [[catch1bb:\.LBB0_[0-9]+]]: # %catch{{$}}
135 ; X64: movq %rdx, 16(%rsp)
136 ; X64: pushq %rbp
137 ; X64: movq %rdx, %rbp
138 ; X64: subq $32, %rsp
139 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
140 ; X64-DAG: movl $2, %ecx
141 ; X64: callq f
142 ; X64: leaq [[contbb]](%rip), %rax
143 ; X64: addq $32, %rsp
144 ; X64: popq %rbp
145 ; X64: retq
146
147 ; X64: [[catch2bb:\.LBB0_[0-9]+]]: # %catch.2{{$}}
148 ; X64: movq %rdx, 16(%rsp)
149 ; X64: pushq %rbp
150 ; X64: movq %rdx, %rbp
151 ; X64: subq $32, %rsp
152 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
153 ; X64-DAG: movl $3, %ecx
154 ; X64: callq f
155 ; X64: leaq [[contbb]](%rip), %rax
156 ; X64: addq $32, %rsp
157 ; X64: popq %rbp
158 ; X64: retq
159
160 ; X64: $handlerMap$0$try_catch_catch:
161 ; X64:   .long   0
162 ; X64:   .long   "??_R0H@8"@IMGREL
163 ; X64:   .long   0
164 ; X64:   .long   [[catch1bb]]@IMGREL
165 ; X64:   .long   56
166 ; X64:   .long   0
167 ; X64:   .long   "??_R0H@8"@IMGREL
168 ; X64:   .long   0
169 ; X64:   .long   [[catch2bb]]@IMGREL
170 ; X64:   .long   56