Skip to content

Commit 901bce2

Browse files
authored
Merge pull request #34613 from atrick/critedge-test
Fix recently added SIL tests with critical edges.
2 parents 36fa93a + adca58f commit 901bce2

14 files changed

+210
-133
lines changed

test/SIL/memory_lifetime_failures.sil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ bb0(%0 : $*T):
4848
end_access %2 : $*T
4949
br bb1
5050
bb1:
51-
cond_br undef, bb1, bb2
51+
cond_br undef, bb2, bb3
5252
bb2:
53+
br bb1
54+
bb3:
5355
return %3 : $T
5456
}
5557

test/SIL/ownership-verifier/arguments.sil

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ bb1(%1 : @guaranteed $Builtin.NativeObject):
7979

8080
bb2:
8181
end_borrow %1 : $Builtin.NativeObject
82-
br bb3
82+
br bb4
8383

8484
bb3:
85+
br bb4
86+
87+
bb4:
8588
%9999 = tuple()
8689
return %9999 : $()
8790
}
@@ -104,9 +107,12 @@ bb1(%2 : @guaranteed $Builtin.NativeObject):
104107

105108
bb2:
106109
end_borrow %2 : $Builtin.NativeObject
107-
br bb3
110+
br bb4
108111

109112
bb3:
113+
br bb4
114+
115+
bb4:
110116
%9999 = tuple()
111117
return %9999 : $()
112118
}
@@ -123,17 +129,17 @@ bb3:
123129
// CHECK-LABEL: Error#: 1. Begin Error in Function: 'leak_along_subarg_path'
124130
// CHECK: Found over consume?!
125131
// CHECK: Value: %2 = argument of bb1 : $Builtin.NativeObject
126-
// CHECK: Block: bb2
132+
// CHECK: Block: bb3
127133
// CHECK: Consuming Users:
128-
// CHECK: br bb3(%2 : $Builtin.NativeObject)
134+
// CHECK: br bb4(%2 : $Builtin.NativeObject)
129135
// CHECK: end_borrow %2 : $Builtin.NativeObject
130136
// CHECK: Error#: 1. End Error in Function: 'leak_along_subarg_path'
131137
//
132138
// CHECK-LABEL: Error#: 2. Begin Error in Function: 'leak_along_subarg_path'
133139
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
134-
// CHECK: Value: %5 = argument of bb3 : $Builtin.NativeObject
140+
// CHECK: Value: %6 = argument of bb4 : $Builtin.NativeObject
135141
// CHECK: Post Dominating Failure Blocks:
136-
// CHECK: bb5
142+
// CHECK: bb6
137143
// CHECK: Error#: 2. End Error in Function: 'leak_along_subarg_path'
138144
//
139145
// CHECK-NOT: Error#: {{[0-9][0-9]*}}. End Error in Function: 'leak_along_subarg_path'
@@ -142,19 +148,25 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
142148
br bb1(%0 : $Builtin.NativeObject)
143149

144150
bb1(%1 : @guaranteed $Builtin.NativeObject):
145-
cond_br undef, bb2, bb5
151+
cond_br undef, bb2, bb3
146152

147153
bb2:
148-
br bb3(%1 : $Builtin.NativeObject)
154+
br bb7
149155

150-
bb3(%2 : @guaranteed $Builtin.NativeObject):
151-
cond_br undef, bb4, bb5
156+
bb3:
157+
br bb4(%1 : $Builtin.NativeObject)
152158

153-
bb4:
154-
end_borrow %2 : $Builtin.NativeObject
155-
br bb5
159+
bb4(%2 : @guaranteed $Builtin.NativeObject):
160+
cond_br undef, bb5, bb6
156161

157162
bb5:
163+
end_borrow %2 : $Builtin.NativeObject
164+
br bb7
165+
166+
bb6:
167+
br bb7
168+
169+
bb7:
158170
end_borrow %1 : $Builtin.NativeObject
159171
%9999 = tuple()
160172
return %9999 : $()
@@ -164,7 +176,7 @@ bb5:
164176
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
165177
// CHECK: Value: %7 = argument of bb3 : $Builtin.NativeObject
166178
// CHECK: Post Dominating Failure Blocks:
167-
// CHECK: bb5
179+
// CHECK: bb6
168180
// CHECK: Error#: 0. End Error in Function: 'leak_along_subarg_path_2'
169181
//
170182
// CHECK-NOT: Error#: {{[0-9][0-9]*}}. End Error in Function: 'leak_along_subarg_path_2'
@@ -181,13 +193,19 @@ bb2:
181193
br bb3(%2a : $Builtin.NativeObject)
182194

183195
bb3(%3 : @guaranteed $Builtin.NativeObject):
184-
cond_br undef, bb4, bb5
196+
cond_br undef, bb4, bb6
185197

186198
bb4:
187199
end_borrow %3 : $Builtin.NativeObject
188-
br bb5
200+
br bb7
189201

190202
bb5:
203+
br bb7
204+
205+
bb6:
206+
br bb7
207+
208+
bb7:
191209
end_borrow %2 : $Builtin.NativeObject
192210
%9999 = tuple()
193211
return %9999 : $()
@@ -204,7 +222,7 @@ bb1:
204222

205223
bb2(%2 : @guaranteed $Builtin.NativeObject):
206224
end_borrow %2 : $Builtin.NativeObject
207-
cond_br undef, bb3, bb4
225+
cond_br undef, bb3, bb6
208226

209227
bb3:
210228
br bb4
@@ -217,6 +235,9 @@ bb4:
217235
bb5:
218236
end_borrow %1 : $Builtin.NativeObject
219237
br bb4
238+
239+
bb6:
240+
br bb4
220241
}
221242

222243
// CHECK-NOT: Function: 'good_order_2'
@@ -232,7 +253,7 @@ bb1:
232253
bb2(%2 : @guaranteed $Builtin.NativeObject):
233254
end_borrow %2 : $Builtin.NativeObject
234255
end_borrow %1 : $Builtin.NativeObject
235-
cond_br undef, bb3, bb4
256+
cond_br undef, bb3, bb6
236257

237258
bb3:
238259
br bb4
@@ -245,6 +266,9 @@ bb4:
245266
bb5:
246267
end_borrow %1 : $Builtin.NativeObject
247268
br bb4
269+
270+
bb6:
271+
br bb4
248272
}
249273

250274

@@ -271,7 +295,7 @@ bb1:
271295
bb2(%2 : @guaranteed $Builtin.NativeObject):
272296
end_borrow %1 : $Builtin.NativeObject
273297
end_borrow %2 : $Builtin.NativeObject
274-
cond_br undef, bb3, bb4
298+
cond_br undef, bb3, bb6
275299

276300
bb3:
277301
br bb4
@@ -284,6 +308,9 @@ bb4:
284308
bb5:
285309
end_borrow %1 : $Builtin.NativeObject
286310
br bb4
311+
312+
bb6:
313+
br bb4
287314
}
288315

289316
// CHECK-LABEL: Error#: 0. Begin Error in Function: 'bad_order_add_a_level'

test/SIL/ownership-verifier/definite_init.sil

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,12 @@ bb1:
265265
%f = function_ref @getSomeClass : $@convention(thin) () -> @owned SomeClass
266266
%6 = apply %f() : $@convention(thin) () -> @owned SomeClass
267267
assign %6 to %3 : $*SomeClass
268-
br bb2
268+
br bb3
269269

270270
bb2:
271+
br bb3
272+
273+
bb3:
271274
destroy_addr %3 : $*SomeClass
272275
dealloc_stack %2 : $*SomeClass
273276
%14 = tuple ()
@@ -284,9 +287,12 @@ bb1:
284287
%2 = function_ref @getSomeClass : $@convention(thin) () -> @owned SomeClass
285288
%12 = apply %2() : $@convention(thin) () -> @owned SomeClass
286289
assign %12 to %6 : $*SomeClass // id: %13
287-
br bb2 // id: %14
290+
br bb3 // id: %14
288291

289292
bb2:
293+
br bb3
294+
295+
bb3:
290296
%3 = function_ref @getSomeClass : $@convention(thin) () -> @owned SomeClass
291297
%17 = apply %3() : $@convention(thin) () -> @owned SomeClass
292298
assign %17 to %6 : $*SomeClass // id: %18
@@ -540,9 +546,12 @@ bb1:
540546
%9 = function_ref @selfinit_mystruct3 : $@convention(thin) () -> @owned MyStruct3
541547
%10 = apply %9() : $@convention(thin) () -> @owned MyStruct3
542548
assign %10 to %3 : $*MyStruct3
543-
br bb2
549+
br bb3
544550

545551
bb2:
552+
br bb3
553+
554+
bb3:
546555
destroy_addr %3 : $*MyStruct3
547556
dealloc_stack %2 : $*MyStruct3
548557
%15 = tuple ()
@@ -564,9 +573,12 @@ bb1:
564573
%5 = function_ref @selfinit_myclass3 : $@convention(thin) (@owned MyClass3) -> @owned MyClass3
565574
%6 = apply %5(%4) : $@convention(thin) (@owned MyClass3) -> @owned MyClass3
566575
store %6 to [init] %3 : $*MyClass3
567-
br bb2
576+
br bb3
568577

569578
bb2:
579+
br bb3
580+
581+
bb3:
570582
destroy_addr %3 : $*MyClass3
571583
dealloc_stack %2 : $*MyClass3
572584
%7 = tuple ()

test/SIL/ownership-verifier/false_positive_leaks.sil

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bb3:
116116
// ending users as successors that we must visit. The target block is bb4.
117117
sil [ossa] @multiple_block_consume_with_diamond : $@convention(thin) () -> () {
118118
bb0:
119-
cond_br undef, bb1, bb4
119+
cond_br undef, bb1, bb5
120120

121121
bb1:
122122
%0 = function_ref @allocate_object : $@convention(thin) () -> (@owned Builtin.NativeObject)
@@ -125,16 +125,19 @@ bb1:
125125

126126
bb2:
127127
destroy_value %1 : $Builtin.NativeObject
128-
br bb5
128+
br bb6
129129

130130
bb3:
131131
destroy_value %1 : $Builtin.NativeObject
132132
br bb4
133133

134134
bb4:
135-
br bb5
135+
br bb6
136136

137137
bb5:
138+
br bb6
139+
140+
bb6:
138141
%9999 = tuple()
139142
return %9999 : $()
140143
}

test/SIL/ownership-verifier/unreachable_code.sil

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@ bb1:
9696
cond_br undef, bb3, bb4
9797

9898
bb2:
99-
br bb4
99+
br bb5
100100

101101
bb3:
102102
unreachable
103103

104104
bb4:
105+
br bb5
106+
107+
bb5:
105108
destroy_value %0 : $Builtin.NativeObject
106109
%9999 = tuple()
107110
return %9999 : $()
@@ -117,13 +120,16 @@ bb1:
117120
cond_br undef, bb3, bb4
118121

119122
bb2:
120-
br bb4
123+
br bb5
121124

122125
bb3:
123126
destroy_value %0 : $Builtin.NativeObject
124127
unreachable
125128

126129
bb4:
130+
br bb5
131+
132+
bb5:
127133
destroy_value %0 : $Builtin.NativeObject
128134
%9999 = tuple()
129135
return %9999 : $()

test/SILOptimizer/allocbox_to_stack_ownership.sil

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -972,51 +972,6 @@ bb2:
972972
return %r : $()
973973
}
974974

975-
// CHECK-LABEL: sil [ossa] @nesting_and_unreachable_critical_edge
976-
// CHECK: bb0(%0 : $Int):
977-
// CHECK-NEXT: [[BOX:%[0-9]+]] = alloc_stack $Int
978-
// CHECK-NEXT: [[STACK1:%[0-9]+]] = alloc_stack $Bool
979-
// CHECK-NEXT: cond_br
980-
// CHECK: bb1:
981-
// CHECK-NEXT: [[STACK2:%[0-9]+]] = alloc_stack $Bool
982-
// CHECK-NEXT: cond_br
983-
// CHECK: bb2:
984-
// CHECK-NEXT: dealloc_stack [[STACK2]]
985-
// CHECK-NEXT: br bb4
986-
// CHECK: bb3:
987-
// CHECK: store
988-
// CHECK: dealloc_stack [[STACK2]]
989-
// CHECK-NEXT: dealloc_stack [[STACK1]]
990-
// CHECK-NEXT: dealloc_stack [[BOX]]
991-
// CHECK-NEXT: tuple
992-
// CHECK-NEXT: return
993-
// CHECK: bb4:
994-
// CHECK-NEXT: unreachable
995-
sil [ossa] @nesting_and_unreachable_critical_edge : $@convention(thin) (Int) -> () {
996-
bb0(%0 : $Int):
997-
%1 = alloc_box ${ var Int }
998-
%as1 = alloc_stack $Bool
999-
%1a = project_box %1 : ${ var Int }, 0
1000-
cond_br undef, bb1, bb3
1001-
1002-
bb1:
1003-
%as2 = alloc_stack $Bool
1004-
cond_br undef, bb2, bb3
1005-
1006-
bb2:
1007-
store %0 to [trivial] %1a : $*Int
1008-
%3 = load [trivial] %1a : $*Int
1009-
dealloc_stack %as2 : $*Bool
1010-
dealloc_stack %as1 : $*Bool
1011-
destroy_value %1 : ${ var Int }
1012-
%r = tuple ()
1013-
return %r : $()
1014-
1015-
bb3:
1016-
destroy_value %1 : ${ var Int }
1017-
unreachable
1018-
}
1019-
1020975
// Test that
1021976
// begin_access [read], copy_addr, end_access, destroy_addr
1022977
// is folded into

test/SILOptimizer/constant_propagation_ownership.sil

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,7 @@ bb0(%2 : $*Value, %0 : $Builtin.Int1, %1 : @guaranteed $AnObject):
885885
cond_br %0, bb1, bb2
886886

887887
bb1:
888-
%3 = tuple()
889-
return %3 : $()
888+
br bb3
890889

891890
bb2:
892891
%31 = alloc_stack $AnObject
@@ -896,7 +895,11 @@ bb2:
896895
%32 = alloc_stack $AnObject
897896
dealloc_stack %32: $*AnObject
898897
dealloc_stack %31 : $*AnObject
899-
br bb1
898+
br bb3
899+
900+
bb3:
901+
%3 = tuple()
902+
return %3 : $()
900903
}
901904

902905
public protocol P {

0 commit comments

Comments
 (0)