1 ; RUN: opt < %s -inline -S | FileCheck %s
3 ; Test that the inliner correctly handles inlining into invoke sites
4 ; by appending selectors and forwarding _Unwind_Resume directly to the
5 ; enclosing landing pad.
7 ;; Test 0 - basic functionality.
9 %struct.A = type { i8 }
11 @_ZTIi = external constant i8*
13 declare void @_ZN1AC1Ev(%struct.A*)
15 declare void @_ZN1AD1Ev(%struct.A*)
17 declare void @use(i32) nounwind
19 declare i8* @llvm.eh.exception() nounwind readonly
21 declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
23 declare i32 @llvm.eh.typeid.for(i8*) nounwind
25 declare void @llvm.eh.resume(i8*, i32)
27 declare i32 @__gxx_personality_v0(...)
29 declare i8* @__cxa_begin_catch(i8*)
31 declare void @__cxa_end_catch()
33 declare void @_ZSt9terminatev()
35 define internal void @test0_in() alwaysinline uwtable ssp {
37 %a = alloca %struct.A, align 1
38 %b = alloca %struct.A, align 1
39 call void @_ZN1AC1Ev(%struct.A* %a)
40 invoke void @_ZN1AC1Ev(%struct.A* %b)
41 to label %invoke.cont unwind label %lpad
44 invoke void @_ZN1AD1Ev(%struct.A* %b)
45 to label %invoke.cont1 unwind label %lpad
48 call void @_ZN1AD1Ev(%struct.A* %a)
52 %exn = call i8* @llvm.eh.exception() nounwind
53 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0) nounwind
54 invoke void @_ZN1AD1Ev(%struct.A* %a)
55 to label %invoke.cont2 unwind label %terminate.lpad
58 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
62 %exn3 = call i8* @llvm.eh.exception() nounwind
63 %eh.selector4 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn3, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind
64 call void @_ZSt9terminatev() noreturn nounwind
68 define void @test0_out() uwtable ssp {
70 invoke void @test0_in()
71 to label %ret unwind label %lpad
76 lpad: ; preds = %entry
77 %exn = call i8* @llvm.eh.exception() nounwind
78 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*)) nounwind
79 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
80 %1 = icmp eq i32 %eh.selector, %0
81 br i1 %1, label %catch, label %eh.resume
84 %ignored = call i8* @__cxa_begin_catch(i8* %exn) nounwind
85 call void @__cxa_end_catch() nounwind
89 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
93 ; CHECK: define void @test0_out()
94 ; CHECK: [[A:%.*]] = alloca %struct.A,
95 ; CHECK: [[B:%.*]] = alloca %struct.A,
96 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
97 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
98 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
99 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
100 ; CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* {{%.*}}, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
101 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
102 ; CHECK-NEXT: to label %[[LBL:[^\s]+]] unwind
104 ; CHECK-NEXT: br label %[[LPAD:[^\s]+]]
106 ; CHECK: call i8* @llvm.eh.exception()
107 ; CHECK-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* {{%.*}}, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*))
108 ; CHECK-NEXT: br label %[[LPAD]]
110 ; CHECK-NEXT: phi i8* [
111 ; CHECK-NEXT: phi i32 [
112 ; CHECK-NEXT: call i32 @llvm.eh.typeid.for(
115 ;; Test 1 - Correctly handle phis in outer landing pads.
117 define void @test1_out() uwtable ssp {
119 invoke void @test0_in()
120 to label %cont unwind label %lpad
123 invoke void @test0_in()
124 to label %ret unwind label %lpad
130 %x = phi i32 [ 0, %entry ], [ 1, %cont ]
131 %y = phi i32 [ 1, %entry ], [ 4, %cont ]
132 %exn = call i8* @llvm.eh.exception() nounwind
133 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*)) nounwind
134 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
135 %1 = icmp eq i32 %eh.selector, %0
136 br i1 %1, label %catch, label %eh.resume
139 %ignored = call i8* @__cxa_begin_catch(i8* %exn) nounwind
140 call void @use(i32 %x)
141 call void @use(i32 %y)
142 call void @__cxa_end_catch() nounwind
146 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
150 ; CHECK: define void @test1_out()
151 ; CHECK: [[A2:%.*]] = alloca %struct.A,
152 ; CHECK: [[B2:%.*]] = alloca %struct.A,
153 ; CHECK: [[A1:%.*]] = alloca %struct.A,
154 ; CHECK: [[B1:%.*]] = alloca %struct.A,
155 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A1]])
156 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
157 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B1]])
158 ; CHECK-NEXT: unwind label %[[LPAD1:[^\s]+]]
159 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B1]])
160 ; CHECK-NEXT: unwind label %[[LPAD1]]
161 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
162 ; CHECK-NEXT: unwind label %[[LPAD]]
164 ; Inner landing pad from first inlining.
166 ; CHECK-NEXT: [[EXN1:%.*]] = call i8* @llvm.eh.exception()
167 ; CHECK-NEXT: [[SEL1:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN1]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
168 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
169 ; CHECK-NEXT: to label %[[RESUME1:[^\s]+]] unwind
170 ; CHECK: [[RESUME1]]:
171 ; CHECK-NEXT: br label %[[LPAD_JOIN1:[^\s]+]]
173 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A2]])
174 ; CHECK-NEXT: unwind label %[[LPAD]]
175 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B2]])
176 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
177 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B2]])
178 ; CHECK-NEXT: unwind label %[[LPAD2]]
179 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
180 ; CHECK-NEXT: unwind label %[[LPAD]]
182 ; Inner landing pad from second inlining.
184 ; CHECK-NEXT: [[EXN2:%.*]] = call i8* @llvm.eh.exception()
185 ; CHECK-NEXT: [[SEL2:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN2]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
186 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
187 ; CHECK-NEXT: to label %[[RESUME2:[^\s]+]] unwind
188 ; CHECK: [[RESUME2]]:
189 ; CHECK-NEXT: br label %[[LPAD_JOIN2:[^\s]+]]
194 ; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, %entry ], [ 0, {{%.*}} ], [ 1, %cont ], [ 1, {{%.*}} ]
195 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 1, %entry ], [ 1, {{%.*}} ], [ 4, %cont ], [ 4, {{%.*}} ]
196 ; CHECK-NEXT: [[EXN:%.*]] = call i8* @llvm.eh.exception()
197 ; CHECK-NEXT: [[SEL:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*))
198 ; CHECK-NEXT: br label %[[LPAD_JOIN2]]
200 ; CHECK: [[LPAD_JOIN2]]:
201 ; CHECK-NEXT: [[XJ2:%.*]] = phi i32 [ [[X]], %[[LPAD]] ], [ 1, %[[RESUME2]] ]
202 ; CHECK-NEXT: [[YJ2:%.*]] = phi i32 [ [[Y]], %[[LPAD]] ], [ 4, %[[RESUME2]] ]
203 ; CHECK-NEXT: [[EXNJ2:%.*]] = phi i8* [ [[EXN]], %[[LPAD]] ], [ [[EXN2]], %[[RESUME2]] ]
204 ; CHECK-NEXT: [[SELJ2:%.*]] = phi i32 [ [[SEL]], %[[LPAD]] ], [ [[SEL2]], %[[RESUME2]] ]
205 ; CHECK-NEXT: br label %[[LPAD_JOIN1]]
207 ; CHECK: [[LPAD_JOIN1]]:
208 ; CHECK-NEXT: [[XJ1:%.*]] = phi i32 [ [[XJ2]], %[[LPAD_JOIN2]] ], [ 0, %[[RESUME1]] ]
209 ; CHECK-NEXT: [[YJ1:%.*]] = phi i32 [ [[YJ2]], %[[LPAD_JOIN2]] ], [ 1, %[[RESUME1]] ]
210 ; CHECK-NEXT: [[EXNJ1:%.*]] = phi i8* [ [[EXNJ2]], %[[LPAD_JOIN2]] ], [ [[EXN1]], %[[RESUME1]] ]
211 ; CHECK-NEXT: [[SELJ1:%.*]] = phi i32 [ [[SELJ2]], %[[LPAD_JOIN2]] ], [ [[SEL1]], %[[RESUME1]] ]
212 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.eh.typeid.for(
213 ; CHECK-NEXT: icmp eq i32 [[SELJ1]], [[T]]
215 ; CHECK: call void @use(i32 [[XJ1]])
216 ; CHECK: call void @use(i32 [[YJ1]])
218 ; CHECK: call void @llvm.eh.resume(i8* [[EXNJ1]], i32 [[SELJ1]])
220 ;; Test 2 - Don't make invalid IR for inlines into landing pads without eh.exception calls
222 define void @test2_out() uwtable ssp {
224 invoke void @test0_in()
225 to label %ret unwind label %lpad
231 call void @_ZSt9terminatev()
235 ; CHECK: define void @test2_out()
236 ; CHECK: [[A:%.*]] = alloca %struct.A,
237 ; CHECK: [[B:%.*]] = alloca %struct.A,
238 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
239 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
240 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
241 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
242 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
243 ; CHECK-NEXT: unwind label %[[LPAD2]]
244 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
245 ; CHECK-NEXT: unwind label %[[LPAD]]