File: guaranteed_phis_errors.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (226 lines) | stat: -rw-r--r-- 7,733 bytes parent folder | download
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
// RUN: %target-sil-opt -module-name Swift -sil-ownership-verifier-enable-testing -ownership-verifier-textual-error-dumper -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s

class SuperKlass {}

class Klass : SuperKlass {}

struct WrapperStruct {
  var val: Klass
}

struct Wrapper1 {
  var val1: Wrapper2
}

struct Wrapper2 {
  var val2: Klass
}

sil @use_superklass : $@convention(thin) (@guaranteed SuperKlass) -> ()
sil @use_klass : $@convention(thin) (@guaranteed Klass) -> ()

// CHECK-LABEL: Error#: 0. Begin Error in Function: 'test1'
// CHECK: Found outside of lifetime use?!
// CHECK: Value:   %1 = begin_borrow %0 : $WrapperStruct
// CHECK: Consuming User:   end_borrow %1 : $WrapperStruct
// CHECK: Non Consuming User:   %5 = apply %4(%2) : $@convention(thin) (@guaranteed Klass) -> ()
// CHECK: Block: bb0
// CHECK-LABEL: Error#: 0. End Error in Function: 'test1'
sil [ossa] @test1 : $@convention(thin) (@owned WrapperStruct) -> () {
bb0(%0 : @owned $WrapperStruct):
  %b = begin_borrow %0 : $WrapperStruct
  %ex1 = struct_extract %b : $WrapperStruct, #WrapperStruct.val
  end_borrow %b : $WrapperStruct
  %func = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
  apply %func(%ex1) : $@convention(thin) (@guaranteed Klass) -> ()
  destroy_value %0  : $WrapperStruct
  %9999 = tuple()
  return %9999 : $()
}

// CHECK: Error#: 0. Begin Error in Function: 'test2'
// CHECK: Found outside of lifetime use?!
// CHECK: Value:   %1 = begin_borrow %0 : $Klass
// CHECK: Consuming User:   end_borrow %1 : $Klass
// CHECK: Non Consuming User:   %8 = apply %7(%5) : $@convention(thin) (@guaranteed SuperKlass) -> ()
// CHECK: Block: bb2
// CHECK: Error#: 0. End Error in Function: 'test2'
sil [ossa] @test2 : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
  %outer = begin_borrow %0 : $Klass
  br bb1

bb1:
  %cast1 = unchecked_ref_cast %outer : $Klass to $SuperKlass
  br bb2(%cast1 : $SuperKlass)

bb2(%phi : @guaranteed $SuperKlass):
  end_borrow %outer : $Klass
  %func = function_ref @use_superklass : $@convention(thin) (@guaranteed SuperKlass) -> ()
  apply %func(%phi) : $@convention(thin) (@guaranteed SuperKlass) -> ()
  destroy_value %0 : $Klass
  %9999 = tuple()
  return %9999 : $()
}

// CHECK: Error#: 0. Begin Error in Function: 'test3'
// CHECK: Found outside of lifetime use?!
// CHECK: Value: %9 = argument of bb3 : $Klass
// CHECK: Consuming User:   destroy_value %9 : $Klass
// CHECK: Non Consuming User:   end_borrow %10 : $Klass
// CHECK: Block: bb3
// CHECK: Error#: 0. End Error in Function: 'test3'
sil [ossa] @test3 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
  cond_br undef, bb1, bb2

bb1:
  %copy0 = copy_value %0 : $Klass
  %borrow0 = begin_borrow %copy0 : $Klass
  br bb3(%copy0 : $Klass, %borrow0 : $Klass)

bb2:
  %copy1 = copy_value %1 : $Klass
  %borrow1 = begin_borrow %copy1 : $Klass
  br bb3(%copy1 : $Klass, %borrow1 : $Klass)

bb3(%phi : @owned $Klass, %gphi : @guaranteed $Klass):
  %func = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
  apply %func(%phi) : $@convention(thin) (@guaranteed Klass) -> ()
  destroy_value %phi : $Klass
  end_borrow %gphi : $Klass
  %9999 = tuple()
  return %9999 : $()
}

// CHECK: Error#: 0. Begin Error in Function: 'test4'
// CHECK: Found outside of lifetime use?!
// CHECK: Value: %15 = argument of bb4 : $Wrapper1
// CHECK: Consuming User:   end_borrow %15 : $Wrapper1
// CHECK: Non Consuming User:   %18 = apply %17(%14) : $@convention(thin) (@guaranteed Klass) -> ()
// CHECK: Block: bb4
// CHECK: Error#: 0. End Error in Function: 'test4'
sil [ossa] @test4 : $@convention(thin) (@owned Wrapper1, @owned Wrapper1) -> () {
bb0(%0 : @owned $Wrapper1, %1 : @owned $Wrapper1):
  %b1 = begin_borrow %0 : $Wrapper1
  cond_br undef, bb1, bb2

bb1:
  %ex1 = struct_extract %b1 : $Wrapper1, #Wrapper1.val1
  br bb3(%ex1 : $Wrapper2, %b1 : $Wrapper1)

bb2:
  end_borrow %b1 : $Wrapper1
  %b2 = begin_borrow %1 : $Wrapper1
  %ex2 = struct_extract %b2 : $Wrapper1, #Wrapper1.val1
  br bb3(%ex2 : $Wrapper2, %b2 : $Wrapper1)

bb3(%phi1 : @guaranteed $Wrapper2, %phi2 : @guaranteed $Wrapper1):
  %ex3 = struct_extract %phi1 : $Wrapper2, #Wrapper2.val2
  br bb4(%ex3 : $Klass, %phi2 : $Wrapper1)

bb4(%phi3 : @guaranteed $Klass, %phi4 : @guaranteed $Wrapper1):
  end_borrow %phi4 : $Wrapper1
  %f = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
  apply %f(%phi3) : $@convention(thin) (@guaranteed Klass) -> ()
  destroy_value %0 : $Wrapper1
  destroy_value %1 : $Wrapper1
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: Error#: 0. Begin Error in Function: 'test5'
// CHECK: Have operand with incompatible ownership?!
// CHECK: Value: %5 = argument of bb2 : $SuperKlass
// CHECK: User:   destroy_value %5 : $SuperKlass
// CHECK: Operand Number: 0
// CHECK: Conv: guaranteed
// CHECK: Constraint:
// CHECK: <Constraint Kind:owned LifetimeConstraint:LifetimeEnding>
// CHECK-LABEL: Error#: 0. End Error in Function: 'test5'
sil [ossa] @test5 : $@convention(thin) (@owned Klass) -> () {
bb0(%0 : @owned $Klass):
  %outer = begin_borrow %0 : $Klass
  br bb1

bb1:
  %cast1 = unchecked_ref_cast %outer : $Klass to $SuperKlass
  br bb2(%cast1 : $SuperKlass)

bb2(%phi : @guaranteed $SuperKlass):
  destroy_value %phi : $SuperKlass
  end_borrow %outer : $Klass
  destroy_value %0 : $Klass
  %9999 = tuple()
  return %9999 : $()
}

// CHECK-LABEL: Error#: 0. Begin Error in Function: 'test6'
// CHECK: Found outside of lifetime use?!
// CHECK: Value:   %1 = load_borrow %0 : $*Klass
// CHECK: Consuming User:   end_borrow %1 : $Klass
// CHECK: Non Consuming User:   %8 = apply %7(%5) : $@convention(thin) (@guaranteed SuperKlass) -> ()
// CHECK: Block: bb2
// CHECK-LABEL: Error#: 0. End Error in Function: 'test6'
sil [ossa] @test6 : $@convention(thin) (@in Klass) -> () {
bb0(%0 : $*Klass):
  %outer = load_borrow %0 : $*Klass
  br bb1

bb1:
  %cast1 = unchecked_ref_cast %outer : $Klass to $SuperKlass
  br bb2(%cast1 : $SuperKlass)

bb2(%phi : @guaranteed $SuperKlass):
  end_borrow %outer : $Klass
  %func = function_ref @use_superklass : $@convention(thin) (@guaranteed SuperKlass) -> ()
  apply %func(%phi) : $@convention(thin) (@guaranteed SuperKlass) -> ()
  destroy_addr %0 : $*Klass
  %9999 = tuple()
  return %9999 : $()
}

// Error#: 0. Begin Error in Function: 'test7'
// Invalid End Borrow!
// Original Value: %0 = argument of bb0 : $Klass
// End Borrow:   br bb3(%3 : $SuperKlass)
//
// Error#: 0. End Error in Function: 'test7'
// CHECK: Error#: 1. Begin Error in Function: 'test7'
// CHECK: Malformed @guaranteed phi!
// CHECK: Phi: %7 = argument of bb3 : $SuperKlass
// CHECK: Guaranteed forwarding operands not found on all paths!
// CHECK: Error#: 1. End Error in Function: 'test7'
sil [ossa] @test7 : $@convention(thin) (@guaranteed Klass, @owned SuperKlass) -> () {
bb0(%0 : @guaranteed $Klass, %1 : @owned $SuperKlass):
  cond_br undef, bb1, bb2

bb1:
  %3 = unchecked_ref_cast %0 : $Klass to $SuperKlass
  br bb3(%3 : $SuperKlass)

bb2:
  %5 = begin_borrow %1 : $SuperKlass
  br bb3(%5 : $SuperKlass)

bb3(%7 : @guaranteed $SuperKlass):
  %8 = function_ref @use_superklass : $@convention(thin) (@guaranteed SuperKlass) -> ()
  %9 = apply %8(%7) : $@convention(thin) (@guaranteed SuperKlass) -> ()
  end_borrow %7 : $SuperKlass
  destroy_value %1 : $SuperKlass
  %12 = tuple ()
  return %12 : $()
}

enum FakeOptional<T> {
  case none
  case some(T)
}

sil [ossa] @end_borrow_test1 : $@convention(thin) () -> () {
bb0:
  %0 = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
  end_borrow %0 : $FakeOptional<Klass>
  %r = tuple ()
  return %r : $()
}