-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathborrow.sil
82 lines (75 loc) · 3.72 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt -sil-print-types %s -emit-sib -o %t/tmp.sib -module-name borrow
// RUN: %target-sil-opt -sil-print-types %t/tmp.sib -o %t/tmp.2.sib -module-name borrow
// RUN: %target-sil-opt -sil-print-types %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 [lexical] {{%[^,]+}}
// CHECK: begin_borrow {{%[^,]+}}
// CHECK: begin_borrow [var_decl] {{%[^,]+}}
// CHECK: } // end sil function 'begin_borrow_test'
sil [serialized] [ossa] @begin_borrow_test : $@convention(thin) () -> () {
%instance = alloc_ref $C
%guaranteed_c = begin_borrow [lexical] %instance : $C
end_borrow %guaranteed_c : $C
%guaranteed_c2 = begin_borrow %instance : $C
end_borrow %guaranteed_c2 : $C
%guaranteed_c3 = begin_borrow [var_decl] %instance : $C
end_borrow %guaranteed_c3 : $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 [var_decl]
// CHECK: alloc_stack [dynamic_lifetime] [lexical]
// CHECK: alloc_stack [dynamic_lifetime] [var_decl]
// CHECK: alloc_stack [lexical] [var_decl]
// CHECK: alloc_stack [dynamic_lifetime] [lexical] [var_decl]
// 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
%instance5 = alloc_stack [var_decl] $Builtin.NativeObject
dealloc_stack %instance5 : $*Builtin.NativeObject
%instance4 = alloc_stack [lexical] [dynamic_lifetime] $Builtin.NativeObject
dealloc_stack %instance4 : $*Builtin.NativeObject
%instance6 = alloc_stack [dynamic_lifetime] [var_decl] $Builtin.NativeObject
dealloc_stack %instance6 : $*Builtin.NativeObject
%instance7 = alloc_stack [lexical] [var_decl] $Builtin.NativeObject
dealloc_stack %instance7 : $*Builtin.NativeObject
%instance8 = alloc_stack [lexical] [var_decl] [dynamic_lifetime] $Builtin.NativeObject
dealloc_stack %instance8 : $*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
%sb = store_borrow %1 to %3 : $*Builtin.NativeObject
end_borrow %sb : $*Builtin.NativeObject
dealloc_stack %3 : $*Builtin.NativeObject
destroy_addr %0 : $*Builtin.NativeObject
%4 = tuple()
return %4 : $()
}
class C {}