Skip to content

Commit e14e692

Browse files
committed
[ownership] Fix ownership in SILOptimizer/exclusivity_static_diagnostics.sil.
1 parent 5ace517 commit e14e692

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

test/SILOptimizer/exclusivity_static_diagnostics.sil

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,28 @@ class ClassWithStoredProperty {
234234
init()
235235
}
236236
// CHECK-LABEL: sil hidden [ossa] @classStoredProperty
237-
sil hidden [ossa] @classStoredProperty : $@convention(thin) (ClassWithStoredProperty) -> () {
238-
bb0(%0 : @unowned $ClassWithStoredProperty):
239-
%1 = ref_element_addr %0 : $ClassWithStoredProperty, #ClassWithStoredProperty.f
237+
sil hidden [ossa] @classStoredProperty : $@convention(thin) (@owned ClassWithStoredProperty) -> () {
238+
bb0(%0 : @owned $ClassWithStoredProperty):
239+
%0a = begin_borrow %0 : $ClassWithStoredProperty
240+
%1 = ref_element_addr %0a : $ClassWithStoredProperty, #ClassWithStoredProperty.f
240241

241242
// expected-error@+1{{overlapping accesses to 'f', but modification requires exclusive access; consider copying to a local variable}}
242243
%2 = begin_access [modify] [dynamic] %1 : $*Int
243-
%3 = ref_element_addr %0 : $ClassWithStoredProperty, #ClassWithStoredProperty.f
244+
%3 = ref_element_addr %0a : $ClassWithStoredProperty, #ClassWithStoredProperty.f
244245

245246
// expected-note@+1{{conflicting access is here}}
246247
%4 = begin_access [modify] [dynamic] %3 : $*Int
247248
end_access %4 : $*Int
248249
end_access %2 : $*Int
250+
end_borrow %0a : $ClassWithStoredProperty
249251
destroy_value %0 : $ClassWithStoredProperty
250252
%5 = tuple ()
251253
return %5 : $()
252254
}
253255

254256
// CHECK-LABEL: sil hidden [ossa] @lookThroughBeginBorrow
255-
sil hidden [ossa] @lookThroughBeginBorrow : $@convention(thin) (ClassWithStoredProperty) -> () {
256-
bb0(%0 : @unowned $ClassWithStoredProperty):
257+
sil hidden [ossa] @lookThroughBeginBorrow : $@convention(thin) (@owned ClassWithStoredProperty) -> () {
258+
bb0(%0 : @owned $ClassWithStoredProperty):
257259
%1 = begin_borrow %0 : $ClassWithStoredProperty
258260
%2 = begin_borrow %0 : $ClassWithStoredProperty
259261
%3 = ref_element_addr %1 : $ClassWithStoredProperty, #ClassWithStoredProperty.f
@@ -605,6 +607,7 @@ bb0(%0 : $Int):
605607
%7 = begin_access [modify] [unknown] %3 : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
606608
%8 = apply %4(%7, %conv) : $@convention(thin) (@inout Int, @noescape @owned @callee_owned (Int) -> ()) -> ()
607609
end_access %7: $*Int
610+
destroy_value %6 : $@callee_owned (Int) -> ()
608611
destroy_value %2 : ${ var Int }
609612
%9 = tuple ()
610613
return %9 : $()
@@ -625,6 +628,7 @@ bb0(%0 : $Int):
625628
%8 = apply %4(%7, %bconv) : $@convention(thin) (@inout Int, @noescape @guaranteed @callee_guaranteed (Int) -> ()) -> ()
626629
end_access %7: $*Int
627630
end_borrow %bconv : $@callee_guaranteed @noescape (Int) -> ()
631+
destroy_value %6 : $@callee_guaranteed (Int) -> ()
628632
destroy_value %2 : ${ var Int }
629633
%9 = tuple ()
630634
return %9 : $()
@@ -651,6 +655,7 @@ bb0(%0 : $Int):
651655
%7 = begin_access [read] [unknown] %3 : $*Int // expected-note {{conflicting access is here}}
652656
%8 = apply %4(%3, %conv) : $@convention(thin) (@inout Int, @noescape @owned @callee_owned () -> ()) -> ()
653657
end_access %7: $*Int
658+
destroy_value %6 : $@callee_owned () -> ()
654659
destroy_value %2 : ${ var Int }
655660
%9 = tuple ()
656661
return %9 : $()
@@ -681,6 +686,8 @@ bb0(%0 : $Int):
681686
%11 = begin_access [modify] [unknown] %3 : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
682687
%12 = apply %4<Int>(%11, %10) : $@convention(thin) <T_0> (@inout Int, @noescape @callee_owned (Int) -> @out T_0) -> ()
683688
end_access %11: $*Int
689+
destroy_value %9 : $@callee_owned (Int) -> @out Int
690+
destroy_value %6 : $@callee_owned (Int) -> Int
684691
destroy_value %2 : ${ var Int }
685692
%13 = tuple ()
686693
return %13 : $()
@@ -722,6 +729,8 @@ bb0(%0 : $Int):
722729
end_access %13 : $*Int
723730
destroy_addr %8 : $*@callee_guaranteed() -> ()
724731
dealloc_stack %7 : $*@block_storage @callee_guaranteed () -> ()
732+
destroy_value %sentinel2 : $@callee_guaranteed () -> ()
733+
destroy_value %6 : $@callee_guaranteed () -> ()
725734
destroy_value %2 : ${ var Int }
726735
%ret = tuple ()
727736
return %ret : $()
@@ -753,6 +762,8 @@ bb0(%0 : $Int):
753762
end_access %14 : $*Int
754763
destroy_addr %8 : $*@callee_guaranteed () -> ()
755764
dealloc_stack %7 : $*@block_storage @callee_guaranteed () -> ()
765+
destroy_value %sentinel2 : $@callee_guaranteed () -> ()
766+
destroy_value %6 : $@callee_guaranteed () -> ()
756767
destroy_value %2 : ${ var Int }
757768
%ret = tuple ()
758769
return %ret : $()
@@ -909,6 +920,7 @@ bb0(%0 : $Int):
909920
%4 = enum $Optional<@convention(block) @noescape () -> ()>, #Optional.none!enumelt
910921
%5 = function_ref @takesInoutAndNoEscapeOptionalBlockClosure : $@convention(thin) (@inout Int, @owned Optional<@convention(block) @noescape () -> ()>) -> ()
911922
%6 = apply %5(%3, %4) : $@convention(thin) (@inout Int, @owned Optional<@convention(block) @noescape () -> ()>) -> ()
923+
destroy_value %2 : ${ var Int }
912924
%7 = tuple ()
913925
return %7 : $()
914926
}
@@ -933,6 +945,7 @@ bb0(%0 : $Int):
933945
%access = begin_access [modify] [unknown] %boxadr : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
934946
%call = apply %nepa(%access) : $@noescape @callee_guaranteed (@inout Int) -> ()
935947
end_access %access : $*Int
948+
destroy_value %pa : $@callee_guaranteed (@inout Int) -> ()
936949
destroy_value %box : ${ var Int }
937950
%v = tuple ()
938951
return %v : $()
@@ -959,6 +972,7 @@ bb0(%0 : $Int):
959972
%access = begin_access [modify] [unknown] %boxadr : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
960973
%call = apply %nepa(%access) : $@noescape @callee_guaranteed (@inout Int) -> ()
961974
end_access %access : $*Int
975+
destroy_value %pa2 : $@callee_guaranteed (@inout Int) -> ()
962976
destroy_value %box : ${ var Int }
963977
%v = tuple ()
964978
return %v : $()
@@ -986,6 +1000,7 @@ bb0(%0 : $Int):
9861000
%8 = begin_access [modify] [unknown] %3 : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
9871001
%9 = apply %4(%8, %conv) : $@convention(thin) (@inout Int, @noescape @owned @callee_owned () -> ()) -> ()
9881002
end_access %8: $*Int
1003+
destroy_value %7 : $@callee_owned () -> ()
9891004
destroy_value %2 : ${ var Int }
9901005
%v = tuple ()
9911006
return %v : $()
@@ -1086,6 +1101,7 @@ bb0(%0 : $UnsafePointer<Int32>, %1 : $*Int32):
10861101
%closure = convert_escape_to_noescape [not_guaranteed] %pa2 : $@callee_guaranteed (UnsafePointer<Int32>) -> () to $@noescape @callee_guaranteed (UnsafePointer<Int32>) -> ()
10871102
%f2 = function_ref @takeMutatingNoescapeClosure : $@convention(thin) <τ_0_0> (UnsafePointer<τ_0_0>, @noescape @callee_guaranteed (UnsafePointer<Int32>) -> ()) -> ()
10881103
%call = apply %f2<Int32>(%0, %closure) : $@convention(thin) <τ_0_0> (UnsafePointer<τ_0_0>, @noescape @callee_guaranteed (UnsafePointer<Int32>) -> ()) -> ()
1104+
destroy_value %pa2 : $@callee_guaranteed (UnsafePointer<Int32>) -> ()
10891105
%v = tuple ()
10901106
return %v : $()
10911107
}
@@ -1102,6 +1118,7 @@ bb0(%0 : $UnsafePointer<Int32>, %1 : $*Int32):
11021118
%f2 = function_ref @takeInoutAndMutatingNoescapeClosure : $@convention(thin) <τ_0_0> (@inout Int32, UnsafePointer<τ_0_0>, @noescape @callee_guaranteed (UnsafePointer<Int32>) -> ()) -> ()
11031119
%access = begin_access [modify] [unknown] %1 : $*Int32 // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
11041120
%call = apply %f2<Int32>(%access, %0, %closure) : $@convention(thin) <τ_0_0> (@inout Int32, UnsafePointer<τ_0_0>, @noescape @callee_guaranteed (UnsafePointer<Int32>) -> ()) -> ()
1121+
destroy_value %pa2 : $@callee_guaranteed (UnsafePointer<Int32>) -> ()
11051122
end_access %access : $*Int32
11061123
%v = tuple ()
11071124
return %v : $()
@@ -1159,6 +1176,7 @@ bb1:
11591176
%copyblock1 = copy_block %initblock1 : $@convention(block) @noescape () -> ()
11601177
destroy_addr %pbs1 : $*@callee_guaranteed() -> ()
11611178
dealloc_stack %bs1 : $*@block_storage @callee_guaranteed () -> ()
1179+
destroy_value %sentinel2 : $@callee_guaranteed () -> ()
11621180
br bb3(%copyblock1 : $@convention(block) @noescape () -> ())
11631181

11641182
bb2:
@@ -1169,13 +1187,15 @@ bb2:
11691187
%copyblock2 = copy_block %initblock2 : $@convention(block) @noescape () -> ()
11701188
destroy_addr %pbs2 : $*@callee_guaranteed() -> ()
11711189
dealloc_stack %bs2 : $*@block_storage @callee_guaranteed () -> ()
1190+
destroy_value %sentinel2 : $@callee_guaranteed () -> ()
11721191
br bb3(%copyblock2 : $@convention(block) @noescape () -> ())
11731192

11741193
bb3(%block : @owned $@convention(block) @noescape () -> ()):
11751194
%access = begin_access [modify] [unknown] %boxadr : $*Int // expected-error {{overlapping accesses, but modification requires exclusive access; consider copying to a local variable}}
11761195
%f = function_ref @takesInoutAndNoEscapeBlockClosure : $@convention(thin) (@inout Int, @owned @convention(block) @noescape () -> ()) -> ()
11771196
%call = apply %f(%access, %block) : $@convention(thin) (@inout Int, @owned @convention(block) @noescape () -> ()) -> ()
11781197
end_access %access : $*Int
1198+
destroy_value %pa : $@callee_guaranteed () -> ()
11791199
destroy_value %box : ${ var Int }
11801200
%ret = tuple ()
11811201
return %ret : $()
@@ -1308,13 +1328,15 @@ bb0(%0 : $*Int):
13081328
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) (@inout_aliasable Int) -> ()
13091329

13101330
%4 = function_ref @thunkForWithoutActuallyEscapingVerify : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
1311-
%5 = partial_apply [callee_guaranteed] %4(%3) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
1331+
%3a = copy_value %3 : $@callee_guaranteed () -> ()
1332+
%5 = partial_apply [callee_guaranteed] %4(%3a) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
13121333
%6 = mark_dependence %5 : $@callee_guaranteed () -> () on %3 : $@callee_guaranteed () -> ()
13131334

13141335
%8 = function_ref @closureForWithoutActuallyEscapingVerify : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
13151336
%9 = apply %8(%6) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
13161337
%10 = is_escaping_closure %6 : $@callee_guaranteed () -> ()
13171338
cond_fail %10 : $Builtin.Int1
1339+
destroy_value %3 : $@callee_guaranteed () -> ()
13181340
destroy_value %6 : $@callee_guaranteed () -> ()
13191341
%14 = tuple ()
13201342
return %14 : $()
@@ -1354,7 +1376,8 @@ bb0(%0 : $Int):
13541376
store %closure to [init] %blockproj : $*@callee_guaranteed () -> ()
13551377
// function_ref thunk for @escaping @callee_guaranteed () -> ()
13561378
%thunkF = function_ref @$sIeg_IeyB_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> ()
1357-
%initblock = init_block_storage_header %block : $*@block_storage @callee_guaranteed () -> (), invoke %thunkF : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> (), type $@convention(block) () -> ()
1379+
%initblock_unowned = init_block_storage_header %block : $*@block_storage @callee_guaranteed () -> (), invoke %thunkF : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> ()) -> (), type $@convention(block) () -> ()
1380+
%initblock = copy_block %initblock_unowned : $@convention(block) () -> ()
13581381
destroy_addr %blockproj : $*@callee_guaranteed () -> ()
13591382
dealloc_stack %block : $*@block_storage @callee_guaranteed () -> ()
13601383
%borrow = begin_borrow %initblock : $@convention(block) () -> ()

0 commit comments

Comments
 (0)