1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is built from the following code:
23 ; The test was built for a 32-bit Windows target and then the reference to
24 ; the inalloca instruction was manually sunk into the landingpad.
26 ; ModuleID = 'cppeh-inalloca.cpp'
28 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
29 %struct.A = type { i32 }
31 $"\01??_R0H@8" = comdat any
33 @"\01??_7type_info@@6B@" = external constant i8*
34 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
36 ; The function entry should be rewritten like this.
37 ; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca)
39 ; CHECK: [[TMP_REGMEM:\%.+]] = alloca <{ %struct.A }>*
40 ; CHECK: store <{ %struct.A }>* %0, <{ %struct.A }>** [[TMP_REGMEM]]
41 ; CHECK: [[RETVAL:\%.+]] = alloca i32, align 4
42 ; CHECK: [[E_PTR:\%.+]] = alloca i32, align 4
43 ; CHECK: [[CLEANUP_SLOT:\%.+]] = alloca i32
44 ; CHECK: call void (...) @llvm.frameescape(i32* %e, <{ %struct.A }>** [[TMP_REGMEM]], i32* [[RETVAL]], i32* [[CLEANUP_SLOT]])
45 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
46 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
48 define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
50 %retval = alloca i32, align 4
51 %exn.slot = alloca i8*
52 %ehselector.slot = alloca i32
53 %e = alloca i32, align 4
54 %cleanup.dest.slot = alloca i32
55 invoke void @"\01?may_throw@@YAXXZ"()
56 to label %invoke.cont unwind label %lpad
58 invoke.cont: ; preds = %entry
61 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
62 ; CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
64 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
65 ; CHECK-NEXT: [[RECOVER:\%recover.*]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAHUA@@@Z.catch", i32 0, void (i8*, i8*)* @"\01?test@@YAHUA@@@Z.cleanup")
66 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %cleanup]
68 lpad: ; preds = %entry
69 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
71 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
72 %2 = extractvalue { i8*, i32 } %1, 0
73 store i8* %2, i8** %exn.slot
74 %3 = extractvalue { i8*, i32 } %1, 1
75 store i32 %3, i32* %ehselector.slot
76 br label %catch.dispatch
78 ; CHECK-NOT: catch.dispatch:
80 catch.dispatch: ; preds = %lpad
81 %sel = load i32, i32* %ehselector.slot
82 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
83 %matches = icmp eq i32 %sel, %4
84 br i1 %matches, label %catch, label %ehcleanup
88 catch: ; preds = %catch.dispatch
89 %exn = load i8*, i8** %exn.slot
90 %e.i8 = bitcast i32* %e to i8*
91 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
92 %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
93 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
94 %tmp8 = load i32, i32* %a1, align 4
95 %tmp9 = load i32, i32* %e, align 4
96 %add = add nsw i32 %tmp8, %tmp9
97 store i32 %add, i32* %retval
98 store i32 1, i32* %cleanup.dest.slot
99 call void @llvm.eh.endcatch() #3
102 try.cont: ; preds = %invoke.cont
103 store i32 0, i32* %retval
104 store i32 1, i32* %cleanup.dest.slot
107 ; The cleanup block should be re-written like this.
108 ; CHECK: cleanup:{{[ ]+}}; preds = %[[LPAD_LABEL]], %try.cont
109 ; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
110 ; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2)
111 ; CHECK: [[TMP1:\%.+]] = load i32, i32* [[RETVAL]]
112 ; CHECK: ret i32 [[TMP1]]
114 cleanup: ; preds = %try.cont, %catch
115 %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
116 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
117 %tmp10 = load i32, i32* %retval
120 ; CHECK-NOT: ehcleanup:
122 ehcleanup: ; preds = %catch.dispatch
123 %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
124 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
127 ; CHECK-NOT: eh.resume:
129 eh.resume: ; preds = %ehcleanup
130 %exn2 = load i8*, i8** %exn.slot
131 %sel3 = load i32, i32* %ehselector.slot
132 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
133 %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
134 resume { i8*, i32 } %lpad.val4
139 ; The following catch handler should be outlined.
140 ; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*)
142 ; CHECK: [[RECOVER_E:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 0)
143 ; CHECK: [[E_PTR:\%.+]] = bitcast i8* [[RECOVER_E]] to i32*
144 ; CHECK: [[RECOVER_EH_TEMP:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
145 ; CHECK: [[EH_TEMP:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
146 ; CHECK: [[RECOVER_RETVAL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 2)
147 ; CHECK: [[RETVAL1:\%.+]] = bitcast i8* [[RECOVER_RETVAL]] to i32*
148 ; CHECK: [[RECOVER_CLEANUPSLOT:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 3)
149 ; CHECK: [[CLEANUPSLOT1:\%.+]] = bitcast i8* [[RECOVER_CLEANUPSLOT]] to i32*
150 ; CHECK: [[E_I8PTR:\%.+]] = bitcast i32* [[E_PTR]] to i8*
151 ; CHECK: [[TMP_RELOAD:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP]]
152 ; CHECK: [[RECOVER_A:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD]], i32 0, i32 0
153 ; CHECK: [[A1:\%.+]] = getelementptr inbounds %struct.A, %struct.A* [[RECOVER_A]], i32 0, i32 0
154 ; CHECK: [[TMP2:\%.+]] = load i32, i32* [[A1]], align 4
155 ; CHECK: [[TMP3:\%.+]] = load i32, i32* [[E_PTR]], align 4
156 ; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP2]], [[TMP3]]
157 ; CHECK: store i32 [[ADD]], i32* [[RETVAL1]]
158 ; CHECK: store i32 1, i32* [[CLEANUPSLOT1]]
159 ; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
162 ; The following cleanup handler should be outlined.
163 ; CHECK: define internal void @"\01?test@@YAHUA@@@Z.cleanup"(i8*, i8*)
165 ; CHECK: [[RECOVER_EH_TEMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
166 ; CHECK: [[EH_TEMP1:\%.+]] = bitcast i8* [[RECOVER_EH_TEMP]] to <{ %struct.A }>**
167 ; CHECK: [[TMP_RELOAD1:\%.+]] = load <{ %struct.A }>*, <{ %struct.A }>** [[EH_TEMP1]]
168 ; CHECK: [[A3:\%.+]] = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* [[TMP_RELOAD1]], i32 0, i32 0
169 ; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* [[A3]])
173 declare void @"\01?may_throw@@YAXXZ"() #0
175 declare i32 @__CxxFrameHandler3(...)
177 ; Function Attrs: nounwind readnone
178 declare i32 @llvm.eh.typeid.for(i8*) #1
180 declare void @llvm.eh.begincatch(i8*, i8*)
182 declare void @llvm.eh.endcatch()
184 ; Function Attrs: nounwind
185 declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
187 attributes #0 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
188 attributes #1 = { nounwind readnone }
189 attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
190 attributes #3 = { nounwind }
194 !0 = !{!"clang version 3.7.0 (trunk 228868)"}