7c53085edc55746a059a2db3b691bc02a2eca8c7
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-prepared-catch.ll
1 ; RUN: llc < %s | FileCheck %s
2
3 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-windows-msvc"
5
6 ; This test case is equivalent to:
7 ; void f() {
8 ;   try {
9 ;     try {
10 ;       may_throw();
11 ;     } catch (int &) {
12 ;       may_throw();
13 ;     }
14 ;     may_throw();
15 ;   } catch (double) {
16 ;   }
17 ; }
18
19
20 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
21 %eh.CatchHandlerType = type { i32, i8* }
22
23 $"\01??_R0N@8" = comdat any
24
25 $"\01??_R0H@8" = comdat any
26
27 @"\01??_7type_info@@6B@" = external constant i8*
28 @"\01??_R0N@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".N\00" }, comdat
29 @llvm.eh.handlertype.N.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0N@8" to i8*) }, section "llvm.metadata"
30 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
31 @llvm.eh.handlertype.H.8 = private unnamed_addr constant %eh.CatchHandlerType { i32 8, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
32
33 define internal i8* @"\01?f@@YAXXZ.catch"(i8*, i8*) #4 {
34 entry:
35   %.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?f@@YAXXZ" to i8*), i8* %1, i32 0)
36   %bc2 = bitcast i8* %.i8 to i32**
37   %bc3 = bitcast i32** %bc2 to i8*
38   invoke void @"\01?may_throw@@YAXXZ"()
39           to label %invoke.cont2 unwind label %lpad1
40
41 invoke.cont2:                                     ; preds = %entry
42   ret i8* blockaddress(@"\01?f@@YAXXZ", %try.cont)
43
44 lpad1:                                            ; preds = %entry
45   %lp4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
46           cleanup
47           catch %eh.CatchHandlerType* @llvm.eh.handlertype.N.0
48   %recover = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.N.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?f@@YAXXZ.catch1")
49   indirectbr i8* %recover, [label %invoke.cont2]
50 }
51
52 ; CHECK-LABEL: "?f@@YAXXZ.catch":
53 ; CHECK:        .seh_handlerdata
54 ; CHECK:        .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
55
56
57 define internal i8* @"\01?f@@YAXXZ.catch1"(i8*, i8*) #4 {
58 entry:
59   %.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?f@@YAXXZ" to i8*), i8* %1, i32 1)
60   %2 = bitcast i8* %.i8 to double*
61   %3 = bitcast double* %2 to i8*
62   invoke void (...)* @llvm.donothing()
63           to label %done unwind label %lpad
64
65 done:
66   ret i8* blockaddress(@"\01?f@@YAXXZ", %try.cont8)
67
68 lpad:                                             ; preds = %entry
69   %4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
70           cleanup
71   unreachable
72 }
73
74 ; CHECK-LABEL: "?f@@YAXXZ.catch1":
75 ; CHECK: ".L?f@@YAXXZ.catch1$parent_frame_offset" = 16
76 ; CHECK:         movq    %rdx, 16(%rsp)
77 ; CHECK:        .seh_handlerdata
78 ; CHECK:        .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
79
80 define void @"\01?f@@YAXXZ"() #0 {
81 entry:
82   %exn.slot = alloca i8*
83   %ehselector.slot = alloca i32
84   %0 = alloca i32*, align 8
85   %1 = alloca double, align 8
86   call void (...)* @llvm.frameescape(i32** %0, double* %1)
87   invoke void @"\01?may_throw@@YAXXZ"()
88           to label %invoke.cont unwind label %lpad2
89
90 invoke.cont:                                      ; preds = %entry
91   br label %try.cont
92
93 lpad2:                                            ; preds = %entry
94   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
95           catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.8
96           catch %eh.CatchHandlerType* @llvm.eh.handlertype.N.0
97   %recover = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.8 to i8*), i32 0, i8* (i8*, i8*)* @"\01?f@@YAXXZ.catch", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.N.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?f@@YAXXZ.catch1")
98   indirectbr i8* %recover, [label %try.cont, label %try.cont8]
99
100 try.cont:                                         ; preds = %lpad2, %invoke.cont
101   invoke void @"\01?may_throw@@YAXXZ"()
102           to label %try.cont8 unwind label %lpad1
103
104 lpad1:
105   %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
106           catch %eh.CatchHandlerType* @llvm.eh.handlertype.N.0
107   %recover2 = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.N.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?f@@YAXXZ.catch1")
108   indirectbr i8* %recover2, [label %try.cont8]
109
110 try.cont8:                                        ; preds = %lpad2, %try.cont
111   ret void
112 }
113
114 ; CHECK-LABEL: "?f@@YAXXZ":
115 ; CHECK:             .seh_handlerdata
116 ; CHECK-NEXT:        .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
117 ; CHECK-NEXT:"$cppxdata$?f@@YAXXZ":
118 ; CHECK-NEXT:        .long   429065506
119 ; CHECK-NEXT:        .long   4
120 ; CHECK-NEXT:        .long   ("$stateUnwindMap$?f@@YAXXZ")@IMGREL
121 ; CHECK-NEXT:        .long   2
122 ; CHECK-NEXT:        .long   ("$tryMap$?f@@YAXXZ")@IMGREL
123 ; CHECK-NEXT:        .long   3
124 ; CHECK-NEXT:        .long   ("$ip2state$?f@@YAXXZ")@IMGREL
125 ; CHECK-NEXT:        .long   32
126 ; CHECK-NEXT:        .long   0
127 ; CHECK-NEXT:        .long   1
128 ; CHECK-NEXT:"$stateUnwindMap$?f@@YAXXZ":
129 ; CHECK-NEXT:        .long   -1
130 ; CHECK-NEXT:        .long   0
131 ; CHECK-NEXT:        .long   0
132 ; CHECK-NEXT:        .long   0
133 ; CHECK-NEXT:        .long   0
134 ; CHECK-NEXT:        .long   0
135 ; CHECK-NEXT:        .long   -1
136 ; CHECK-NEXT:        .long   0
137 ; CHECK-NEXT:"$tryMap$?f@@YAXXZ":
138 ; CHECK-NEXT:        .long   1
139 ; CHECK-NEXT:        .long   1
140 ; CHECK-NEXT:        .long   2
141 ; CHECK-NEXT:        .long   1
142 ; CHECK-NEXT:        .long   ("$handlerMap$0$?f@@YAXXZ")@IMGREL
143 ; CHECK-NEXT:        .long   0
144 ; CHECK-NEXT:        .long   2
145 ; CHECK-NEXT:        .long   3
146 ; CHECK-NEXT:        .long   1
147 ; CHECK-NEXT:        .long   ("$handlerMap$1$?f@@YAXXZ")@IMGREL
148 ; CHECK-NEXT:"$handlerMap$0$?f@@YAXXZ":
149 ; CHECK-NEXT:        .long   8
150 ; CHECK-NEXT:        .long   "??_R0H@8"@IMGREL
151 ; CHECK-NEXT:        .long   ".L?f@@YAXXZ$frame_escape_0"
152 ; CHECK-NEXT:        .long   "?f@@YAXXZ.catch"@IMGREL
153 ; CHECK-NEXT:        .long   ".L?f@@YAXXZ.catch$parent_frame_offset"
154 ; CHECK-NEXT:"$handlerMap$1$?f@@YAXXZ":
155 ; CHECK-NEXT:        .long   0
156 ; CHECK-NEXT:        .long   "??_R0N@8"@IMGREL
157 ; CHECK-NEXT:        .long   ".L?f@@YAXXZ$frame_escape_1"
158 ; CHECK-NEXT:        .long   "?f@@YAXXZ.catch1"@IMGREL
159 ; CHECK-NEXT:        .long   ".L?f@@YAXXZ.catch1$parent_frame_offset"
160 ; CHECK-NEXT:"$ip2state$?f@@YAXXZ":
161 ; CHECK-NEXT:        .long   .Ltmp0@IMGREL
162 ; CHECK-NEXT:        .long   0
163 ; CHECK-NEXT:        .long   .Ltmp13@IMGREL
164 ; CHECK-NEXT:        .long   1
165 ; CHECK-NEXT:        .long   .Ltmp16@IMGREL
166 ; CHECK-NEXT:        .long   0
167
168
169 declare void @"\01?may_throw@@YAXXZ"() #1
170
171 declare i32 @__CxxFrameHandler3(...)
172
173 ; Function Attrs: nounwind readnone
174 declare i32 @llvm.eh.typeid.for(i8*) #2
175
176 ; Function Attrs: nounwind
177 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
178
179 ; Function Attrs: nounwind
180 declare void @llvm.eh.endcatch() #3
181
182 ; Function Attrs: nounwind
183 declare i8* @llvm.eh.actions(...) #3
184
185 ; Function Attrs: nounwind
186 declare void @llvm.frameescape(...) #3
187
188 ; Function Attrs: nounwind readnone
189 declare i8* @llvm.framerecover(i8*, i8*, i32) #2
190
191 declare void @llvm.donothing(...)
192
193 attributes #0 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="\ 1?f@@YAXXZ" }
194 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
195 attributes #2 = { nounwind readnone }
196 attributes #3 = { nounwind }
197 attributes #4 = { "wineh-parent"="\ 1?f@@YAXXZ" }