seh-finally.ll
9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
; RUN: llc -mtriple arm64-windows -o - %s | FileCheck %s
; struct S { int x; };
; void foo(int n);
; void foo(struct S o);
; void simple_seh() {
; struct S o;
;
; __try { foo(o.x); }
; __finally { foo(o.x); }
; }
; void stack_realign() {
; struct S __declspec(align(32)) o;
;
; __try { foo(o.x); }
; __finally { foo(o.x); }
; }
; void vla_present(int n) {
; int vla[n];
;
; __try { foo(n); }
; __finally { foo(n); }
; }
; void vla_and_realign(int n) {
; struct S __declspec(align(32)) o;
; int vla[n];
;
; __try { foo(o.x); }
; __finally { foo(o.x); }
; }
%struct.S = type { i32 }
; Test simple SEH (__try/__finally).
define void @simple_seh() #0 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
entry:
; CHECK-LABEL: simple_seh
; CHECK: add x29, sp, #16
; CHECK: mov x0, #-2
; CHECK: stur x0, [x29, #16]
; CHECK: .set .Lsimple_seh$frame_escape_0, -8
; CHECK: ldur w0, [x29, #-8]
; CHECK: bl foo
%o = alloca %struct.S, align 4
call void (...) @llvm.localescape(%struct.S* %o)
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%0 = load i32, i32* %x, align 4
invoke void @foo(i32 %0) #5
to label %invoke.cont unwind label %ehcleanup
invoke.cont: ; preds = %entry
%1 = call i8* @llvm.localaddress()
call void @fin_simple_seh(i8 0, i8* %1)
ret void
ehcleanup: ; preds = %entry
%2 = cleanuppad within none []
%3 = call i8* @llvm.localaddress()
call void @fin_simple_seh(i8 1, i8* %3) [ "funclet"(token %2) ]
cleanupret from %2 unwind to caller
}
define void @fin_simple_seh(i8 %abnormal_termination, i8* %frame_pointer) {
entry:
; CHECK-LABEL: fin_simple_seh
; CHECK: movz x8, #:abs_g1_s:.Lsimple_seh$frame_escape_0
; CHECK: movk x8, #:abs_g0_nc:.Lsimple_seh$frame_escape_0
; CHECK: strb w0, [sp, #15]
; CHECK: ldr w0, [x1, x8]
; CHECK: bl foo
%frame_pointer.addr = alloca i8*, align 8
%abnormal_termination.addr = alloca i8, align 1
%0 = call i8* @llvm.localrecover(i8* bitcast (void ()* @simple_seh to i8*), i8* %frame_pointer, i32 0)
%o = bitcast i8* %0 to %struct.S*
store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%1 = load i32, i32* %x, align 4
call void @foo(i32 %1)
ret void
}
; Test SEH when stack realignment is needed in case highly aligned stack objects are present.
define void @stack_realign() #0 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
entry:
; CHECK-LABEL: stack_realign
; CHECK: add x29, sp, #8
; CHECK: sub x9, sp, #16
; CHECK: and sp, x9, #0xffffffffffffffe0
; CHECK: mov x19, sp
; CHECK: mov x0, #-2
; CHECK: stur x0, [x29, #24]
; CHECK: .set .Lstack_realign$frame_escape_0, 0
; CHECK: ldr w0, [x19]
; CHECK: bl foo
%o = alloca %struct.S, align 32
call void (...) @llvm.localescape(%struct.S* %o)
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%0 = load i32, i32* %x, align 32
invoke void @foo(i32 %0) #5
to label %invoke.cont unwind label %ehcleanup
invoke.cont: ; preds = %entry
%1 = call i8* @llvm.localaddress()
call void @fin_stack_realign(i8 0, i8* %1)
ret void
ehcleanup: ; preds = %entry
%2 = cleanuppad within none []
%3 = call i8* @llvm.localaddress()
call void @fin_stack_realign(i8 1, i8* %3) [ "funclet"(token %2) ]
cleanupret from %2 unwind to caller
}
define void @fin_stack_realign(i8 %abnormal_termination, i8* %frame_pointer) {
entry:
; CHECK-LABEL: fin_stack_realign
; CHECK: movz x8, #:abs_g1_s:.Lstack_realign$frame_escape_0
; CHECK: movk x8, #:abs_g0_nc:.Lstack_realign$frame_escape_0
; CHECK: strb w0, [sp, #15]
; CHECK: ldr w0, [x1, x8]
; CHECK: bl foo
%frame_pointer.addr = alloca i8*, align 8
%abnormal_termination.addr = alloca i8, align 1
%0 = call i8* @llvm.localrecover(i8* bitcast (void ()* @stack_realign to i8*), i8* %frame_pointer, i32 0)
%o = bitcast i8* %0 to %struct.S*
store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%1 = load i32, i32* %x, align 32
call void @foo(i32 %1)
ret void
}
; Test SEH when variable size objects are present on the stack. Note: Escaped vla's are current not supported by SEH.
define void @vla_present(i32 %n) #0 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
entry:
; CHECK-LABEL: vla_present
; CHECK: add x29, sp, #32
; CHECK: mov x1, #-2
; CHECK: stur x1, [x29, #16]
; CHECK: .set .Lvla_present$frame_escape_0, -4
; CHECK: stur w0, [x29, #-4]
; CHECK: ldur w8, [x29, #-4]
; CHECK: mov x9, sp
; CHECK: stur x9, [x29, #-16]
; CHECK: stur x8, [x29, #-24]
; CHECK: ldur w0, [x29, #-4]
; CHECK: bl foo
%n.addr = alloca i32, align 4
%saved_stack = alloca i8*, align 8
%__vla_expr0 = alloca i64, align 8
call void (...) @llvm.localescape(i32* %n.addr)
store i32 %n, i32* %n.addr, align 4
%0 = load i32, i32* %n.addr, align 4
%1 = zext i32 %0 to i64
%2 = call i8* @llvm.stacksave()
store i8* %2, i8** %saved_stack, align 8
%vla = alloca i32, i64 %1, align 4
store i64 %1, i64* %__vla_expr0, align 8
%3 = load i32, i32* %n.addr, align 4
invoke void @foo(i32 %3) #5
to label %invoke.cont unwind label %ehcleanup
invoke.cont: ; preds = %entry
%4 = call i8* @llvm.localaddress()
call void @fin_vla_present(i8 0, i8* %4)
%5 = load i8*, i8** %saved_stack, align 8
call void @llvm.stackrestore(i8* %5)
ret void
ehcleanup: ; preds = %entry
%6 = cleanuppad within none []
%7 = call i8* @llvm.localaddress()
call void @fin_vla_present(i8 1, i8* %7) [ "funclet"(token %6) ]
cleanupret from %6 unwind to caller
}
define void @fin_vla_present(i8 %abnormal_termination, i8* %frame_pointer) {
entry:
; CHECK-LABEL: fin_vla_present
; CHECK: movz x8, #:abs_g1_s:.Lvla_present$frame_escape_0
; CHECK: movk x8, #:abs_g0_nc:.Lvla_present$frame_escape_0
; CHECK: strb w0, [sp, #15]
; CHECK: ldr w0, [x1, x8]
; CHECK: bl foo
%frame_pointer.addr = alloca i8*, align 8
%abnormal_termination.addr = alloca i8, align 1
%0 = call i8* @llvm.localrecover(i8* bitcast (void (i32)* @vla_present to i8*), i8* %frame_pointer, i32 0)
%n.addr = bitcast i8* %0 to i32*
store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
%1 = load i32, i32* %n.addr, align 4
call void @foo(i32 %1)
ret void
}
; Test when both vla's and highly aligned objects are present on stack.
define void @vla_and_realign(i32 %n) #0 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
entry:
; CHECK-LABEL: vla_and_realign
; CHECK: add x29, sp, #8
; CHECK: sub x9, sp, #48
; CHECK: and sp, x9, #0xffffffffffffffe0
; CHECK: mov x19, sp
; CHECK: mov x1, #-2
; CHECK: stur x1, [x29, #24]
; CHECK: .set .Lvla_and_realign$frame_escape_0, 32
; CHECK: str w0, [x29, #36]
; CHECK: ldr w8, [x29, #36]
; CHECK: mov x9, sp
; CHECK: str x9, [x29, #16]
; CHECK: str x8, [x19, #24]
; CHECK: ldr w0, [x19, #32]
; CHECK: bl foo
%n.addr = alloca i32, align 4
%o = alloca %struct.S, align 32
%saved_stack = alloca i8*, align 8
%__vla_expr0 = alloca i64, align 8
call void (...) @llvm.localescape(%struct.S* %o)
store i32 %n, i32* %n.addr, align 4
%0 = load i32, i32* %n.addr, align 4
%1 = zext i32 %0 to i64
%2 = call i8* @llvm.stacksave()
store i8* %2, i8** %saved_stack, align 8
%vla = alloca i32, i64 %1, align 4
store i64 %1, i64* %__vla_expr0, align 8
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%3 = load i32, i32* %x, align 32
invoke void @foo(i32 %3) #5
to label %invoke.cont unwind label %ehcleanup
invoke.cont: ; preds = %entry
%4 = call i8* @llvm.localaddress()
call void @fin_vla_and_realign(i8 0, i8* %4)
%5 = load i8*, i8** %saved_stack, align 8
call void @llvm.stackrestore(i8* %5)
ret void
ehcleanup: ; preds = %entry
%6 = cleanuppad within none []
%7 = call i8* @llvm.localaddress()
call void @fin_vla_and_realign(i8 1, i8* %7) [ "funclet"(token %6) ]
cleanupret from %6 unwind to caller
}
define void @fin_vla_and_realign(i8 %abnormal_termination, i8* %frame_pointer) {
entry:
; CHECK-LABEL: fin_vla_and_realign
; CHECK: movz x8, #:abs_g1_s:.Lvla_and_realign$frame_escape_0
; CHECK: movk x8, #:abs_g0_nc:.Lvla_and_realign$frame_escape_0
; CHECK: strb w0, [sp, #15]
; CHECK: ldr w0, [x1, x8]
; CHECK: bl foo
%frame_pointer.addr = alloca i8*, align 8
%abnormal_termination.addr = alloca i8, align 1
%0 = call i8* @llvm.localrecover(i8* bitcast (void (i32)* @vla_and_realign to i8*), i8* %frame_pointer, i32 0)
%o = bitcast i8* %0 to %struct.S*
store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
%x = getelementptr inbounds %struct.S, %struct.S* %o, i32 0, i32 0
%1 = load i32, i32* %x, align 32
call void @foo(i32 %1)
ret void
}
declare void @foo(i32)
declare void @llvm.stackrestore(i8*)
declare i8* @llvm.stacksave()
declare i8* @llvm.localrecover(i8*, i8*, i32)
declare i8* @llvm.localaddress()
declare void @llvm.localescape(...)
declare i32 @__C_specific_handler(...)
attributes #0 = { noinline optnone }