1
1
// RUN: %target-sil-opt -module-name Swift -enable-sil-verify-all -semantic-arc-opts -sil-semantic-arc-peepholes-lifetime-joining %s | %FileCheck %s
2
- // REQUIRES: swift_stdlib_asserts
3
2
4
3
// NOTE: Some of our tests here depend on borrow elimination /not/ running!
5
4
// Please do not add it to clean up the IR like we did in
@@ -15,6 +14,13 @@ import Builtin
15
14
16
15
typealias AnyObject = Builtin.AnyObject
17
16
17
+ struct Bool {
18
+ var value : Builtin.Int1
19
+ }
20
+
21
+ sil @closureCapturesBool : $@convention(thin) (@guaranteed { var Bool }) -> ()
22
+ sil @closureArgumentEscapes : $@convention(thin) (@owned @callee_guaranteed () -> ()) -> ()
23
+
18
24
enum MyNever {}
19
25
enum FakeOptional<T> {
20
26
case none
@@ -883,3 +889,34 @@ bb3(%result : @owned $FakeOptional<Builtin.NativeObject>):
883
889
dealloc_stack %allocStack : $*Builtin.NativeObject
884
890
return %result : $FakeOptional<Builtin.NativeObject>
885
891
}
892
+
893
+ // Don't do this optimization:
894
+ // Eliminate borrowed copy with useless lifetime:
895
+ // %5 = copy_value %0 : ${ var Bool }
896
+ //
897
+ // CHECK: sil hidden [ossa] @testCapturedSingleDestroyCopy : $@convention(thin) () -> Bool {
898
+ // CHECK: load [trivial] %{{.*}} : $*Bool
899
+ // CHECK: destroy_value %0 : ${ var Bool }
900
+ sil hidden [ossa] @testCapturedSingleDestroyCopy : $@convention(thin) () -> Bool {
901
+ bb0:
902
+ // var test = false
903
+ %0 = alloc_box ${ var Bool }, var, name "test"
904
+ %1 = project_box %0 : ${ var Bool }, 0
905
+ %2 = integer_literal $Builtin.Int1, 0
906
+ %3 = struct $Bool (%2 : $Builtin.Int1)
907
+ store %3 to [trivial] %1 : $*Bool
908
+
909
+ // capture test in an escaping closure
910
+ %5 = copy_value %0 : ${ var Bool }
911
+ %6 = function_ref @closureCapturesBool : $@convention(thin) (@guaranteed { var Bool }) -> ()
912
+ %7 = partial_apply [callee_guaranteed] %6(%5) : $@convention(thin) (@guaranteed { var Bool }) -> ()
913
+ %8 = function_ref @closureArgumentEscapes : $@convention(thin) (@owned @callee_guaranteed () -> ()) -> ()
914
+ %9 = apply %8(%7) : $@convention(thin) (@owned @callee_guaranteed () -> ()) -> ()
915
+
916
+ // return test
917
+ %10 = begin_access [read] [dynamic] %1 : $*Bool
918
+ %11 = load [trivial] %10 : $*Bool
919
+ end_access %10 : $*Bool
920
+ destroy_value %0 : ${ var Bool }
921
+ return %11 : $Bool
922
+ }
0 commit comments