Skip to content

Commit 7b5a479

Browse files
authored
Merge pull request #85795 from gottesmm/pr-f54feb20e8e8bcda1ba5d3e95cd49d9159c64ea2
[irgen] Add test for b6dfb30.
2 parents 95cc52d + e1cc41a commit 7b5a479

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/IRGen/non_nested.sil

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %sil-llvm-gen %s -output-kind=llvm-as -o - | %FileCheck %s
2+
3+
import Builtin
4+
5+
sil @use_value : $@convention(thin) <T> (@inout T) -> ()
6+
sil @use_pack : $@convention(thin) <each τ_0_0> (@pack_guaranteed Pack{repeat each τ_0_0}) -> ()
7+
8+
// CHECK: define {{.*}}swiftcc void @test_alloc_stack(ptr noalias [[IN:%.*]], ptr [[META:%.*]]){{.*}} {
9+
// CHECK: [[VALUE_WITNESS_TABLE_PTR:%.*]] = getelementptr inbounds ptr, ptr [[META]], {{.*}} -1
10+
// CHECK: [[VALUE_WITNESS_TABLE:%.*]] = load ptr, ptr [[VALUE_WITNESS_TABLE_PTR]]
11+
// CHECK: [[SIZE_VALUE_WITNESS:%.*]] = getelementptr {{.*}} %swift.vwtable, ptr [[VALUE_WITNESS_TABLE]], i32 0, i32 8
12+
// CHECK: [[SIZE:%.*]] = load {{.*}}ptr [[SIZE_VALUE_WITNESS]]
13+
// CHECK: [[MALLOC:%.*]] = call ptr @malloc({{.*}} [[SIZE]])
14+
// CHECK: call void @llvm.lifetime.start.p0({{.*}} -1, ptr [[MALLOC]])
15+
// CHECK: [[INIT_WITH_COPY_PTR:%.*]] = getelementptr inbounds ptr, ptr [[VALUE_WITNESS_TABLE]], i32 2
16+
// CHECK: [[INIT_WITH_COPY:%.*]] = load ptr, ptr [[INIT_WITH_COPY_PTR]]
17+
// CHECK: call ptr %InitializeWithCopy(ptr {{.*}}[[MALLOC]], ptr {{.*}}[[IN]], ptr [[META]])
18+
// CHECK: call swiftcc void @use_value(ptr [[MALLOC]], ptr [[META]])
19+
// CHECK: call void @llvm.lifetime.end.p0({{.*}} -1, ptr [[MALLOC]])
20+
// CHECK: call void @free(ptr [[MALLOC]])
21+
// CHECK-NEXT: ret void
22+
sil @test_alloc_stack : $@convention(thin) <T> (@in_guaranteed T) -> () {
23+
bb0(%0 : $*T):
24+
%1 = alloc_stack [non_nested] $T
25+
copy_addr %0 to [init] %1
26+
%f = function_ref @use_value : $@convention(thin) <T> (@inout T) -> ()
27+
apply %f<T>(%1) : $@convention(thin) <T> (@inout T) -> ()
28+
dealloc_stack %1
29+
%9999 = tuple ()
30+
return %9999 : $()
31+
}
32+
33+
// CHECK: define {{.*}}swiftcc void @test_alloc_stack_name(ptr noalias [[IN:%.*]], ptr [[META:%.*]]){{.*}} {
34+
// CHECK: [[VALUE_WITNESS_TABLE_PTR:%.*]] = getelementptr inbounds ptr, ptr [[META]], {{.*}} -1
35+
// CHECK: [[VALUE_WITNESS_TABLE:%.*]] = load ptr, ptr [[VALUE_WITNESS_TABLE_PTR]]
36+
// CHECK: [[SIZE_VALUE_WITNESS:%.*]] = getelementptr {{.*}} %swift.vwtable, ptr [[VALUE_WITNESS_TABLE]], i32 0, i32 8
37+
// CHECK: [[SIZE:%.*]] = load {{.*}}ptr [[SIZE_VALUE_WITNESS]]
38+
// CHECK: [[MALLOC:%.*]] = call ptr @malloc({{.*}} [[SIZE]])
39+
// CHECK: call void @llvm.lifetime.start.p0({{.*}} -1, ptr [[MALLOC]])
40+
// CHECK: [[INIT_WITH_COPY_PTR:%.*]] = getelementptr inbounds ptr, ptr [[VALUE_WITNESS_TABLE]], i32 2
41+
// CHECK: [[INIT_WITH_COPY:%.*]] = load ptr, ptr [[INIT_WITH_COPY_PTR]]
42+
// CHECK: call ptr %InitializeWithCopy(ptr {{.*}}[[MALLOC]], ptr {{.*}}[[IN]], ptr [[META]])
43+
// CHECK: call swiftcc void @use_value(ptr [[MALLOC]], ptr [[META]])
44+
// CHECK: call void @llvm.lifetime.end.p0({{.*}} -1, ptr [[MALLOC]])
45+
// CHECK: call void @free(ptr [[MALLOC]])
46+
// CHECK-NEXT: ret void
47+
sil @test_alloc_stack_name : $@convention(thin) <T> (@in_guaranteed T) -> () {
48+
bb0(%0 : $*T):
49+
%1 = alloc_stack [non_nested] $T, var, name "name"
50+
copy_addr %0 to [init] %1
51+
%f = function_ref @use_value : $@convention(thin) <T> (@inout T) -> ()
52+
apply %f<T>(%1) : $@convention(thin) <T> (@inout T) -> ()
53+
dealloc_stack %1
54+
%9999 = tuple ()
55+
return %9999 : $()
56+
}

0 commit comments

Comments
 (0)