1 ; RUN: opt -mtriple=i386-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'
27 target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
28 target triple = "i386-pc-windows-msvc"
30 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
31 %struct.A = type { i32 }
33 $"\01??_R0H@8" = comdat any
35 @"\01??_7type_info@@6B@" = external constant i8*
36 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
38 ; The function entry should be rewritten like this.
39 ; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
41 ; CHECK: %.tmp.reg2mem = alloca <{ %struct.A }>*
42 ; CHECK: %.tmp = select i1 true, <{ %struct.A }>* %0, <{ %struct.A }>* undef
43 ; CHECK: store <{ %struct.A }>* %.tmp, <{ %struct.A }>** %.tmp.reg2mem
44 ; CHECK: %retval = alloca i32, align 4
45 ; CHECK: %exn.slot = alloca i8*
46 ; CHECK: %ehselector.slot = alloca i32
47 ; CHECK: %e = alloca i32, align 4
48 ; CHECK: %cleanup.dest.slot = alloca i32
49 ; CHECK: call void (...)* @llvm.frameescape(i32* %e, <{ %struct.A }>** %.tmp.reg2mem, i32* %retval, i32* %cleanup.dest.slot)
50 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
51 ; CHECK: to label %invoke.cont unwind label %lpad
53 define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
55 %retval = alloca i32, align 4
56 %exn.slot = alloca i8*
57 %ehselector.slot = alloca i32
58 %e = alloca i32, align 4
59 %cleanup.dest.slot = alloca i32
60 invoke void @"\01?may_throw@@YAXXZ"()
61 to label %invoke.cont unwind label %lpad
63 invoke.cont: ; preds = %entry
66 lpad: ; preds = %entry
67 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
69 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
70 %2 = extractvalue { i8*, i32 } %1, 0
71 store i8* %2, i8** %exn.slot
72 %3 = extractvalue { i8*, i32 } %1, 1
73 store i32 %3, i32* %ehselector.slot
74 br label %catch.dispatch
76 catch.dispatch: ; preds = %lpad
77 %sel = load i32, i32* %ehselector.slot
78 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
79 %matches = icmp eq i32 %sel, %4
80 br i1 %matches, label %catch, label %ehcleanup
82 catch: ; preds = %catch.dispatch
83 %exn = load i8*, i8** %exn.slot
84 %e.i8 = bitcast i32* %e to i8*
85 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
86 %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
87 %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
88 %tmp8 = load i32, i32* %a1, align 4
89 %tmp9 = load i32, i32* %e, align 4
90 %add = add nsw i32 %tmp8, %tmp9
91 store i32 %add, i32* %retval
92 store i32 1, i32* %cleanup.dest.slot
93 call void @llvm.eh.endcatch() #3
96 try.cont: ; preds = %invoke.cont
97 store i32 0, i32* %retval
98 store i32 1, i32* %cleanup.dest.slot
101 ; The cleanup block should be re-written like this.
102 ; CHECK: cleanup: ; preds = %try.cont, %catch
103 ; CHECK-NOT: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
104 ; CHECK: %.tmp.reload1 = load volatile <{ %struct.A }>*, <{ %struct.A }>** %.tmp.reg2mem
105 ; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.tmp.reload1, i32 0, i32 0
106 ; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #2
107 ; CHECK: %tmp10 = load i32, i32* %retval
108 ; CHECK: ret i32 %tmp10
110 cleanup: ; preds = %try.cont, %catch
111 %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
112 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
113 %tmp10 = load i32, i32* %retval
116 ehcleanup: ; preds = %catch.dispatch
117 %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
118 call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
121 eh.resume: ; preds = %ehcleanup
122 %exn2 = load i8*, i8** %exn.slot
123 %sel3 = load i32, i32* %ehselector.slot
124 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
125 %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
126 resume { i8*, i32 } %lpad.val4
129 ; The following catch handler should be outlined.
130 ; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*) {
132 ; CHECK: %e.i81 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 0)
133 ; CHECK: %e = bitcast i8* %e.i81 to i32*
134 ; CHECK: %eh.temp.alloca.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 1)
135 ; CHECK: %eh.temp.alloca = bitcast i8* %eh.temp.alloca.i8 to <{ %struct.A }>**
136 ; CHECK: %.reload = load <{ %struct.A }>*, <{ %struct.A }>** %eh.temp.alloca
137 ; CHECK: %retval.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 2)
138 ; CHECK: %retval = bitcast i8* %retval.i8 to i32*
139 ; CHECK: %cleanup.dest.slot.i8 = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1, i32 3)
140 ; CHECK: %cleanup.dest.slot = bitcast i8* %cleanup.dest.slot.i8 to i32*
141 ; CHECK: %e.i8 = bitcast i32* %e to i8*
142 ; CHECK: %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.reload, i32 0, i32 0
143 ; CHECK: %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
144 ; CHECK: %tmp8 = load i32, i32* %a1, align 4
145 ; CHECK: %tmp9 = load i32, i32* %e, align 4
146 ; CHECK: %add = add nsw i32 %tmp8, %tmp9
147 ; CHECK: store i32 %add, i32* %retval
148 ; CHECK: store i32 1, i32* %cleanup.dest.slot
149 ; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
152 declare void @"\01?may_throw@@YAXXZ"() #0
154 declare i32 @__CxxFrameHandler3(...)
156 ; Function Attrs: nounwind readnone
157 declare i32 @llvm.eh.typeid.for(i8*) #1
159 declare void @llvm.eh.begincatch(i8*, i8*)
161 declare void @llvm.eh.endcatch()
163 ; Function Attrs: nounwind
164 declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
166 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" }
167 attributes #1 = { nounwind readnone }
168 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" }
169 attributes #3 = { nounwind }
173 !0 = !{!"clang version 3.7.0 (trunk 228868)"}