Remove StringRef->std::string->StringRef conversions.
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-nested-1.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2 ; XFAIL: *
3
4 ; This test is based on the following code:
5 ;
6 ;void test()
7 ;{
8 ;  try {
9 ;    try {
10 ;       may_throw();
11 ;    } catch (int i) {
12 ;      handle_int(i);
13 ;    }
14 ;  } catch (float f) {
15 ;    handle_float(f);
16 ;  }
17 ;  done();
18 ;}
19
20 ; ModuleID = 'cppeh-nested-1.cpp'
21 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
22 target triple = "x86_64-pc-windows-msvc"
23
24 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
25
26 $"\01??_R0M@8" = comdat any
27
28 $"\01??_R0H@8" = comdat any
29
30 @"\01??_7type_info@@6B@" = external constant i8*
31 @"\01??_R0M@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".M\00" }, comdat
32 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
33
34 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
35 ; CHECK: entry:
36 ; CHECK:   %i = alloca i32, align 4
37 ; CHECK:   %f = alloca float, align 4
38 ; CHECK:   call void (...)* @llvm.frameescape(i32* %i, float* %f)
39 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
40 ; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
41
42 ; Function Attrs: uwtable
43 define void @"\01?test@@YAXXZ"() #0 {
44 entry:
45   %exn.slot = alloca i8*
46   %ehselector.slot = alloca i32
47   %i = alloca i32, align 4
48   %f = alloca float, align 4
49   invoke void @"\01?may_throw@@YAXXZ"()
50           to label %invoke.cont unwind label %lpad
51
52 invoke.cont:                                      ; preds = %entry
53   br label %try.cont
54
55 ; CHECK: [[LPAD_LABEL]]:
56 ; CHECK:   [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
57 ; CHECK:           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
58 ; CHECK:           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
59 ; CHECK:   [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* %i, i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch" to i8*), i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*), float* %f, i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1" to i8*))
60 ; CHECK:   indirectbr i8* [[RECOVER]], [label %try.cont, label %try.cont10]
61
62 lpad:                                             ; preds = %entry
63   %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
64           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
65           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
66   %1 = extractvalue { i8*, i32 } %0, 0
67   store i8* %1, i8** %exn.slot
68   %2 = extractvalue { i8*, i32 } %0, 1
69   store i32 %2, i32* %ehselector.slot
70   br label %catch.dispatch
71
72 ; CHECK-NOT: catch.dispatch:
73 catch.dispatch:                                   ; preds = %lpad
74   %sel = load i32, i32* %ehselector.slot
75   %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
76   %matches = icmp eq i32 %sel, %3
77   br i1 %matches, label %catch, label %catch.dispatch3
78
79 ; CHECK-NOT: catch:
80 catch:                                            ; preds = %catch.dispatch
81   %exn = load i8*, i8** %exn.slot
82   %4 = bitcast i32* %i to i8*
83   call void @llvm.eh.begincatch(i8* %exn, i8* %4) #3
84   %5 = load i32, i32* %i, align 4
85   invoke void @"\01?handle_int@@YAXH@Z"(i32 %5)
86           to label %invoke.cont2 unwind label %lpad1
87
88 ; CHECK-NOT: invoke.cont2:
89 invoke.cont2:                                     ; preds = %catch
90   call void @llvm.eh.endcatch() #3
91   br label %try.cont
92
93 try.cont:                                         ; preds = %invoke.cont2, %invoke.cont
94   br label %try.cont10
95
96 ; CHECK-NOT: lpad1:
97 lpad1:                                            ; preds = %catch
98   %6 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
99           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
100   %7 = extractvalue { i8*, i32 } %6, 0
101   store i8* %7, i8** %exn.slot
102   %8 = extractvalue { i8*, i32 } %6, 1
103   store i32 %8, i32* %ehselector.slot
104   call void @llvm.eh.endcatch() #3
105   br label %catch.dispatch3
106
107 ; CHECK-NOT: catch.dispatch3:
108 catch.dispatch3:                                  ; preds = %lpad1, %catch.dispatch
109   %sel4 = load i32, i32* %ehselector.slot
110   %9 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)) #3
111   %matches5 = icmp eq i32 %sel4, %9
112   br i1 %matches5, label %catch6, label %eh.resume
113
114 ; CHECK-NOT: catch6:
115 catch6:                                           ; preds = %catch.dispatch3
116   %exn7 = load i8*, i8** %exn.slot
117   %10 = bitcast float* %f to i8*
118   call void @llvm.eh.begincatch(i8* %exn7, i8* %10) #3
119   %11 = load float, float* %f, align 4
120   call void @"\01?handle_float@@YAXM@Z"(float %11)
121   call void @llvm.eh.endcatch() #3
122   br label %try.cont10
123
124 try.cont10:                                       ; preds = %catch6, %try.cont
125   call void @"\01?done@@YAXXZ"()
126   ret void
127
128 ; CHECK-NOT: eh.resume:
129 eh.resume:                                        ; %catch.dispatch3
130   %exn11 = load i8*, i8** %exn.slot
131   %sel12 = load i32, i32* %ehselector.slot
132   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn11, 0
133   %lpad.val13 = insertvalue { i8*, i32 } %lpad.val, i32 %sel12, 1
134   resume { i8*, i32 } %lpad.val13
135 ; CHECK: }
136 }
137
138 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
139 ; CHECK: entry:
140 ; CHECK:   [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
141 ; CHECK:   [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
142 ; ------------================= FAIL here =================------------
143 ; CHECK:   [[RECOVER_F:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
144 ; CHECK:   [[F_PTR:\%.+]] = bitcast i8* [[RECOVER_F]] to float*
145 ; CHECK:   [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
146 ; CHECK:   invoke void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]])
147 ; CHECK:           to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
148 ;
149 ; CHECK: invoke.cont2:
150 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
151 ;
152 ; CHECK: [[LPAD1_LABEL]]:{{[ ]+}}; preds = %entry
153 ; CHECK:   [[LPAD1_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
154 ; CHECK:           catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
155 ; ------------================= FAIL here =================------------
156 ; CHECK:   [[RECOVER1:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD1_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*), float* [[F_PTR]], i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1" to i8*))
157 ; CHECK:   indirectbr i8* [[RECOVER1]], []
158 ;
159 ; CHECK: }
160
161 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) {
162 ; CHECK: entry:
163 ; CHECK:   [[RECOVER_F1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
164 ; CHECK:   [[F_PTR1:\%.+]] = bitcast i8* [[RECOVER_F1]] to float*
165 ; CHECK:   [[TMP2:\%.+]] = load float, float* [[F_PTR1]], align 4
166 ; CHECK:   call void @"\01?handle_float@@YAXM@Z"(float [[TMP2]])
167 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont10)
168 ; CHECK: }
169
170
171 declare void @"\01?may_throw@@YAXXZ"() #1
172
173 declare i32 @__CxxFrameHandler3(...)
174
175 ; Function Attrs: nounwind readnone
176 declare i32 @llvm.eh.typeid.for(i8*) #2
177
178 ; Function Attrs: nounwind
179 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
180
181 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
182
183 ; Function Attrs: nounwind
184 declare void @llvm.eh.endcatch() #3
185
186 declare void @"\01?handle_float@@YAXM@Z"(float) #1
187
188 declare void @"\01?done@@YAXXZ"() #1
189
190 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
191 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
192 attributes #2 = { nounwind readnone }
193 attributes #3 = { nounwind }
194
195 !llvm.module.flags = !{!0}
196 !llvm.ident = !{!1}
197
198 !0 = !{i32 1, !"PIC Level", i32 2}
199 !1 = !{!"clang version 3.7.0 (trunk 232069) (llvm/trunk 232070)"}