-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathload_borrow_verify_errors.sil
102 lines (85 loc) · 3.01 KB
/
load_borrow_verify_errors.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// RUN: %target-sil-opt %s -verify-continue-on-failure=true -o /dev/null 2>&1 | %FileCheck %s
import Builtin
class Klass {}
sil @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
// Write: store {{.*}} [assign] {{.*}}
// CHECK: Begin Error in function test_write_reborrow
// CHECK: SIL verification failed: Load borrow invalidated by a local write
// CHECK: End Error in function test_write_reborrow
sil [ossa] @test_write_reborrow : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack [lexical] $Klass
store %0 to [init] %stk : $*Klass
%ld1 = load_borrow %stk : $*Klass
br bb2(%ld1 : $Klass)
bb2(%ldarg : @guaranteed $Klass):
%ld = borrowed %ldarg : $Klass from ()
store %1 to [assign] %stk : $*Klass
%3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
%4 = apply %3(%ld) : $@convention(thin) (@guaranteed Klass) -> ()
end_borrow %ld : $Klass
destroy_addr %stk : $*Klass
dealloc_stack %stk : $*Klass
%6 = tuple ()
return %6 : $()
}
// CHECK: Begin Error in function test_multiple_loadborrows
// CHECK: SIL verification failed: Load borrow invalidated by a local write
// CHECK: Verifying instruction:
// CHECK: -> destroy_addr
// CHECK: End Error in function test_multiple_loadborrows
sil [ossa] @test_multiple_loadborrows : $@convention(thin) (@owned Klass, @owned Klass) -> () {
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
%stk = alloc_stack [lexical] $Klass
cond_br undef, bb1, bb2
bb1:
destroy_value %1 : $Klass
store %0 to [init] %stk : $*Klass
br bb3
bb2:
destroy_value %0 : $Klass
store %1 to [init] %stk : $*Klass
br bb3
bb3:
cond_br undef, bb4, bb5
bb4:
%ld1 = load_borrow %stk : $*Klass
destroy_addr %stk : $*Klass
br bb6(%ld1 : $Klass)
bb5:
%ld2 = load_borrow %stk : $*Klass
destroy_addr %stk : $*Klass
br bb6(%ld2 : $Klass)
bb6(%ldarg : @guaranteed $Klass):
%ld = borrowed %ldarg : $Klass from ()
%3 = function_ref @use_guaranteed : $@convention(thin) (@guaranteed Klass) -> ()
%4 = apply %3(%ld) : $@convention(thin) (@guaranteed Klass) -> ()
end_borrow %ld : $Klass
dealloc_stack %stk : $*Klass
%6 = tuple ()
return %6 : $()
}
struct ArrayIntBuffer {
var storage : Builtin.NativeObject
}
struct MyArray<T> {
var buffer : ArrayIntBuffer
}
struct MyStruct {
}
// CHECK: Begin Error in function test_is_unique
// CHECK: SIL verification failed: Load borrow invalidated by a local write
// CHECK: -> %4 = is_unique %1 : $*ArrayIntBuffer
// CHECK: End Error in function test_is_unique
sil [ossa] @test_is_unique : $@convention(thin) (@in MyArray<MyStruct>) -> () {
bb0(%0 : $*MyArray<MyStruct>):
%1 = struct_element_addr %0 : $*MyArray<MyStruct>, #MyArray.buffer
%2 = load_borrow %1 : $*ArrayIntBuffer
%3 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
%6 = is_unique %1 : $*ArrayIntBuffer
%7 = struct $MyArray<MyStruct>(%2 : $ArrayIntBuffer)
end_borrow %2 : $ArrayIntBuffer
destroy_addr %0 : $*MyArray<MyStruct>
%t = tuple ()
return %t : $()
}