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