xref: /llvm-project/llvm/test/CodeGen/X86/unwindraise.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc < %s -verify-machineinstrs
2; PR13188
3;
4; The _Unwind_RaiseException function can return normally and via eh.return.
5; This causes confusion about the function live-out registers, since the two
6; different ways of returning have different return values.
7;
8target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-freebsd9.0"
10
11%struct._Unwind_Context = type { [18 x ptr], ptr, ptr, ptr, %struct.dwarf_eh_bases, i64, i64, i64, [18 x i8] }
12%struct.dwarf_eh_bases = type { ptr, ptr, ptr }
13%struct._Unwind_FrameState = type { %struct.frame_state_reg_info, i64, i64, ptr, i32, ptr, ptr, i64, i64, i64, i8, i8, i8, i8, ptr }
14%struct.frame_state_reg_info = type { [18 x %struct.anon], ptr }
15%struct.anon = type { %union.anon, i32 }
16%union.anon = type { i64 }
17%struct._Unwind_Exception = type { i64, ptr, i64, i64 }
18
19@dwarf_reg_size_table = external hidden unnamed_addr global [18 x i8], align 16
20
21declare void @abort() noreturn
22
23declare fastcc i32 @uw_frame_state_for(ptr, ptr) uwtable
24
25define hidden i32 @_Unwind_RaiseException(ptr %exc) uwtable {
26entry:
27  %fs.i = alloca %struct._Unwind_FrameState, align 8
28  %this_context = alloca %struct._Unwind_Context, align 8
29  %cur_context = alloca %struct._Unwind_Context, align 8
30  %fs = alloca %struct._Unwind_FrameState, align 8
31  call void @llvm.eh.unwind.init()
32  %0 = call ptr @llvm.eh.dwarf.cfa(i32 0)
33  %1 = call ptr @llvm.returnaddress(i32 0)
34  call fastcc void @uw_init_context_1(ptr %this_context, ptr %0, ptr %1)
35  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %cur_context, ptr align 8 %this_context, i64 240, i1 false)
36  %personality = getelementptr inbounds %struct._Unwind_FrameState, ptr %fs, i64 0, i32 6
37  %retaddr_column.i = getelementptr inbounds %struct._Unwind_FrameState, ptr %fs, i64 0, i32 9
38  %flags.i.i.i.i = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 5
39  %ra.i = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 2
40  br label %while.body
41
42while.body:                                       ; preds = %uw_update_context.exit, %entry
43  %call = call fastcc i32 @uw_frame_state_for(ptr %cur_context, ptr %fs)
44  switch i32 %call, label %do.end21 [
45    i32 5, label %do.end21.loopexit46
46    i32 0, label %if.end3
47  ]
48
49if.end3:                                          ; preds = %while.body
50  %2 = load ptr, ptr %personality, align 8
51  %tobool = icmp eq ptr %2, null
52  br i1 %tobool, label %if.end13, label %if.then4
53
54if.then4:                                         ; preds = %if.end3
55  %3 = load i64, ptr %exc, align 8
56  %call6 = call i32 %2(i32 1, i32 1, i64 %3, ptr %exc, ptr %cur_context)
57  switch i32 %call6, label %do.end21.loopexit46 [
58    i32 6, label %while.end
59    i32 8, label %if.end13
60  ]
61
62if.end13:                                         ; preds = %if.then4, %if.end3
63  call fastcc void @uw_update_context_1(ptr %cur_context, ptr %fs)
64  %4 = load i64, ptr %retaddr_column.i, align 8
65  %conv.i = trunc i64 %4 to i32
66  %cmp.i.i.i = icmp slt i32 %conv.i, 18
67  br i1 %cmp.i.i.i, label %cond.end.i.i.i, label %cond.true.i.i.i
68
69cond.true.i.i.i:                                  ; preds = %if.end13
70  call void @abort() noreturn
71  unreachable
72
73cond.end.i.i.i:                                   ; preds = %if.end13
74  %sext.i = shl i64 %4, 32
75  %idxprom.i.i.i = ashr exact i64 %sext.i, 32
76  %arrayidx.i.i.i = getelementptr inbounds [18 x i8], ptr @dwarf_reg_size_table, i64 0, i64 %idxprom.i.i.i
77  %5 = load i8, ptr %arrayidx.i.i.i, align 1
78  %arrayidx2.i.i.i = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 0, i64 %idxprom.i.i.i
79  %6 = load ptr, ptr %arrayidx2.i.i.i, align 8
80  %7 = load i64, ptr %flags.i.i.i.i, align 8
81  %and.i.i.i.i = and i64 %7, 4611686018427387904
82  %tobool.i.i.i = icmp eq i64 %and.i.i.i.i, 0
83  br i1 %tobool.i.i.i, label %if.end.i.i.i, label %land.lhs.true.i.i.i
84
85land.lhs.true.i.i.i:                              ; preds = %cond.end.i.i.i
86  %arrayidx4.i.i.i = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 8, i64 %idxprom.i.i.i
87  %8 = load i8, ptr %arrayidx4.i.i.i, align 1
88  %tobool6.i.i.i = icmp eq i8 %8, 0
89  br i1 %tobool6.i.i.i, label %if.end.i.i.i, label %if.then.i.i.i
90
91if.then.i.i.i:                                    ; preds = %land.lhs.true.i.i.i
92  %9 = ptrtoint ptr %6 to i64
93  br label %uw_update_context.exit
94
95if.end.i.i.i:                                     ; preds = %land.lhs.true.i.i.i, %cond.end.i.i.i
96  %cmp8.i.i.i = icmp eq i8 %5, 8
97  br i1 %cmp8.i.i.i, label %if.then10.i.i.i, label %cond.true14.i.i.i
98
99if.then10.i.i.i:                                  ; preds = %if.end.i.i.i
100  %10 = load i64, ptr %6, align 8
101  br label %uw_update_context.exit
102
103cond.true14.i.i.i:                                ; preds = %if.end.i.i.i
104  call void @abort() noreturn
105  unreachable
106
107uw_update_context.exit:                           ; preds = %if.then10.i.i.i, %if.then.i.i.i
108  %retval.0.i.i.i = phi i64 [ %9, %if.then.i.i.i ], [ %10, %if.then10.i.i.i ]
109  %11 = inttoptr i64 %retval.0.i.i.i to ptr
110  store ptr %11, ptr %ra.i, align 8
111  br label %while.body
112
113while.end:                                        ; preds = %if.then4
114  %private_1 = getelementptr inbounds %struct._Unwind_Exception, ptr %exc, i64 0, i32 2
115  store i64 0, ptr %private_1, align 8
116  %12 = load ptr, ptr %ra.i, align 8
117  %13 = ptrtoint ptr %12 to i64
118  %private_2 = getelementptr inbounds %struct._Unwind_Exception, ptr %exc, i64 0, i32 3
119  store i64 %13, ptr %private_2, align 8
120  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %cur_context, ptr align 8 %this_context, i64 240, i1 false)
121  call void @llvm.lifetime.start.p0(i64 -1, ptr %fs.i)
122  %personality.i = getelementptr inbounds %struct._Unwind_FrameState, ptr %fs.i, i64 0, i32 6
123  %retaddr_column.i22 = getelementptr inbounds %struct._Unwind_FrameState, ptr %fs.i, i64 0, i32 9
124  br label %while.body.i
125
126while.body.i:                                     ; preds = %uw_update_context.exit44, %while.end
127  %call.i = call fastcc i32 @uw_frame_state_for(ptr %cur_context, ptr %fs.i)
128  %14 = load ptr, ptr %ra.i, align 8
129  %15 = ptrtoint ptr %14 to i64
130  %16 = load i64, ptr %private_2, align 8
131  %cmp.i = icmp eq i64 %15, %16
132  %cmp2.i = icmp eq i32 %call.i, 0
133  br i1 %cmp2.i, label %if.end.i, label %do.end21
134
135if.end.i:                                         ; preds = %while.body.i
136  %17 = load ptr, ptr %personality.i, align 8
137  %tobool.i = icmp eq ptr %17, null
138  br i1 %tobool.i, label %if.end12.i, label %if.then3.i
139
140if.then3.i:                                       ; preds = %if.end.i
141  %or.i = select i1 %cmp.i, i32 6, i32 2
142  %18 = load i64, ptr %exc, align 8
143  %call5.i = call i32 %17(i32 1, i32 %or.i, i64 %18, ptr %exc, ptr %cur_context)
144  switch i32 %call5.i, label %do.end21 [
145    i32 7, label %do.body19
146    i32 8, label %if.end12.i
147  ]
148
149if.end12.i:                                       ; preds = %if.then3.i, %if.end.i
150  br i1 %cmp.i, label %cond.true.i, label %cond.end.i
151
152cond.true.i:                                      ; preds = %if.end12.i
153  call void @abort() noreturn
154  unreachable
155
156cond.end.i:                                       ; preds = %if.end12.i
157  call fastcc void @uw_update_context_1(ptr %cur_context, ptr %fs.i)
158  %19 = load i64, ptr %retaddr_column.i22, align 8
159  %conv.i23 = trunc i64 %19 to i32
160  %cmp.i.i.i24 = icmp slt i32 %conv.i23, 18
161  br i1 %cmp.i.i.i24, label %cond.end.i.i.i33, label %cond.true.i.i.i25
162
163cond.true.i.i.i25:                                ; preds = %cond.end.i
164  call void @abort() noreturn
165  unreachable
166
167cond.end.i.i.i33:                                 ; preds = %cond.end.i
168  %sext.i26 = shl i64 %19, 32
169  %idxprom.i.i.i27 = ashr exact i64 %sext.i26, 32
170  %arrayidx.i.i.i28 = getelementptr inbounds [18 x i8], ptr @dwarf_reg_size_table, i64 0, i64 %idxprom.i.i.i27
171  %20 = load i8, ptr %arrayidx.i.i.i28, align 1
172  %arrayidx2.i.i.i29 = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 0, i64 %idxprom.i.i.i27
173  %21 = load ptr, ptr %arrayidx2.i.i.i29, align 8
174  %22 = load i64, ptr %flags.i.i.i.i, align 8
175  %and.i.i.i.i31 = and i64 %22, 4611686018427387904
176  %tobool.i.i.i32 = icmp eq i64 %and.i.i.i.i31, 0
177  br i1 %tobool.i.i.i32, label %if.end.i.i.i39, label %land.lhs.true.i.i.i36
178
179land.lhs.true.i.i.i36:                            ; preds = %cond.end.i.i.i33
180  %arrayidx4.i.i.i34 = getelementptr inbounds %struct._Unwind_Context, ptr %cur_context, i64 0, i32 8, i64 %idxprom.i.i.i27
181  %23 = load i8, ptr %arrayidx4.i.i.i34, align 1
182  %tobool6.i.i.i35 = icmp eq i8 %23, 0
183  br i1 %tobool6.i.i.i35, label %if.end.i.i.i39, label %if.then.i.i.i37
184
185if.then.i.i.i37:                                  ; preds = %land.lhs.true.i.i.i36
186  %24 = ptrtoint ptr %21 to i64
187  br label %uw_update_context.exit44
188
189if.end.i.i.i39:                                   ; preds = %land.lhs.true.i.i.i36, %cond.end.i.i.i33
190  %cmp8.i.i.i38 = icmp eq i8 %20, 8
191  br i1 %cmp8.i.i.i38, label %if.then10.i.i.i40, label %cond.true14.i.i.i41
192
193if.then10.i.i.i40:                                ; preds = %if.end.i.i.i39
194  %25 = load i64, ptr %21, align 8
195  br label %uw_update_context.exit44
196
197cond.true14.i.i.i41:                              ; preds = %if.end.i.i.i39
198  call void @abort() noreturn
199  unreachable
200
201uw_update_context.exit44:                         ; preds = %if.then10.i.i.i40, %if.then.i.i.i37
202  %retval.0.i.i.i42 = phi i64 [ %24, %if.then.i.i.i37 ], [ %25, %if.then10.i.i.i40 ]
203  %26 = inttoptr i64 %retval.0.i.i.i42 to ptr
204  store ptr %26, ptr %ra.i, align 8
205  br label %while.body.i
206
207do.body19:                                        ; preds = %if.then3.i
208  call void @llvm.lifetime.end.p0(i64 -1, ptr %fs.i)
209  %call20 = call fastcc i64 @uw_install_context_1(ptr %this_context, ptr %cur_context)
210  %27 = load ptr, ptr %ra.i, align 8
211  call void @llvm.eh.return.i64(i64 %call20, ptr %27)
212  unreachable
213
214do.end21.loopexit46:                              ; preds = %if.then4, %while.body
215  %retval.0.ph = phi i32 [ 3, %if.then4 ], [ 5, %while.body ]
216  br label %do.end21
217
218do.end21:                                         ; preds = %do.end21.loopexit46, %if.then3.i, %while.body.i, %while.body
219  %retval.0 = phi i32 [ %retval.0.ph, %do.end21.loopexit46 ], [ 3, %while.body ], [ 2, %while.body.i ], [ 2, %if.then3.i ]
220  ret i32 %retval.0
221}
222
223declare void @llvm.eh.unwind.init() nounwind
224
225declare fastcc void @uw_init_context_1(ptr, ptr, ptr) uwtable
226
227declare ptr @llvm.eh.dwarf.cfa(i32) nounwind
228
229declare ptr @llvm.returnaddress(i32) nounwind readnone
230
231declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
232
233declare fastcc i64 @uw_install_context_1(ptr, ptr) uwtable
234
235declare void @llvm.eh.return.i64(i64, ptr) nounwind
236
237declare fastcc void @uw_update_context_1(ptr, ptr nocapture) uwtable
238
239declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
240
241declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
242