forked from apple/swift
/
borrow.sil
67 lines (60 loc) · 2.85 KB
/
borrow.sil
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
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name borrow
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.2.sib -module-name borrow
// RUN: %target-sil-opt %t/tmp.2.sib -module-name borrow | %FileCheck %s
sil_stage canonical
import Builtin
// CHECK-LABEL: sil [serialized] [ossa] @begin_borrow_test
// CHECK: begin_borrow [defined] {{%[^,]+}}
// CHECK: begin_borrow {{%[^,]+}}
// CHECK: } // end sil function 'begin_borrow_test'
sil [serialized] [ossa] @begin_borrow_test : $@convention(thin) () -> () {
%instance = alloc_ref $C
%guaranteed_c = begin_borrow [defined] %instance : $C
end_borrow %guaranteed_c : $C
%guaranteed_c2 = begin_borrow %instance : $C
end_borrow %guaranteed_c2 : $C
destroy_value %instance : $C
%res = tuple ()
return %res : $()
}
// CHECK-LABEL: sil [serialized] [ossa] @alloc_stack_test
// CHECK: alloc_stack $Builtin.NativeObject
// CHECK: alloc_stack [dynamic_lifetime]
// CHECK: alloc_stack [lexical]
// CHECK: alloc_stack [dynamic_lifetime] [lexical]
// CHECK: } // end sil function 'alloc_stack_test'
sil [serialized] [ossa] @alloc_stack_test : $@convention(thin) () -> () {
%instance = alloc_stack $Builtin.NativeObject
dealloc_stack %instance : $*Builtin.NativeObject
%instance2 = alloc_stack [dynamic_lifetime] $Builtin.NativeObject
dealloc_stack %instance2 : $*Builtin.NativeObject
%instance3 = alloc_stack [lexical] $Builtin.NativeObject
dealloc_stack %instance3 : $*Builtin.NativeObject
%instance4 = alloc_stack [lexical] [dynamic_lifetime] $Builtin.NativeObject
dealloc_stack %instance4 : $*Builtin.NativeObject
%res = tuple ()
return %res : $()
}
// We do not verify here, but just make sure that all of the combinations parse and print correctly.
// CHECK-LABEL: sil [serialized] [ossa] @borrow_test : $@convention(thin) (@in Builtin.NativeObject, @guaranteed Builtin.NativeObject) -> () {
// CHECK: bb0([[ARG1:%[0-9]+]] : $*Builtin.NativeObject, [[ARG2:%[0-9]+]] : @guaranteed $Builtin.NativeObject):
// CHECK: [[BORROWED_ARG2:%.*]] = begin_borrow [[ARG2]]
// CHECK: end_borrow [[BORROWED_ARG2]]
// CHECK: [[MEM:%.*]] = alloc_stack $Builtin.NativeObject
// CHECK: store_borrow [[ARG2]] to [[MEM]] : $*Builtin.NativeObject
// CHECK: } // end sil function 'borrow_test'
sil [serialized] [ossa] @borrow_test : $@convention(thin) (@in Builtin.NativeObject, @guaranteed Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject, %1 : @guaranteed $Builtin.NativeObject):
%2 = begin_borrow %1 : $Builtin.NativeObject
end_borrow %2 : $Builtin.NativeObject
%3 = alloc_stack $Builtin.NativeObject
store_borrow %1 to %3 : $*Builtin.NativeObject
end_borrow %3 : $*Builtin.NativeObject
dealloc_stack %3 : $*Builtin.NativeObject
destroy_addr %0 : $*Builtin.NativeObject
%4 = tuple()
return %4 : $()
}
class C {}