Skip to content

Commit 9b9de44

Browse files
authored
Merge pull request swiftlang#23493 from gottesmm/pr-5ede7ff49f2951b8bd547d822874421c2ceee876
2 parents e0c9a6e + e4ba615 commit 9b9de44

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

test/SILGen/without_actually_escaping.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// RUN: %target-swift-emit-silgen -module-name without_actually_escaping %s | %FileCheck %s
32

43
var escapeHatch: Any = 0
@@ -75,3 +74,29 @@ struct DontCrash {
7574
}
7675
}
7776
}
77+
78+
func modifyAndPerform<T>(_ _: UnsafeMutablePointer<T>, closure: () ->()) {
79+
closure()
80+
}
81+
82+
// Make sure that we properly handle cases where the input closure is not
83+
// trivial. This means we need to copy first.
84+
// CHECK-LABEL: sil hidden [ossa] @$s25without_actually_escaping0A24ActuallyEscapingConflictyyF : $@convention(thin) () -> () {
85+
// CHECK: [[CLOSURE_1_FUN:%.*]] = function_ref @$s25without_actually_escaping0A24ActuallyEscapingConflictyyFyycfU_ :
86+
// CHECK: [[CLOSURE_1:%.*]] = partial_apply [callee_guaranteed] [[CLOSURE_1_FUN]](
87+
// CHECK: [[BORROWED_CLOSURE_1:%.*]] = begin_borrow [[CLOSURE_1]]
88+
// CHECK: [[COPY_BORROWED_CLOSURE_1:%.*]] = copy_value [[BORROWED_CLOSURE_1]]
89+
// CHECK: [[THUNK_FUNC:%.*]] = function_ref @$sIeg_Ieg_TR :
90+
// CHECK: [[COPY_2_BORROWED_CLOSURE_1:%.*]] = copy_value [[COPY_BORROWED_CLOSURE_1]]
91+
// CHECK: [[THUNK_PA:%.*]] = partial_apply [callee_guaranteed] [[THUNK_FUNC]]([[COPY_2_BORROWED_CLOSURE_1]])
92+
// CHECK: [[THUNK_PA_MDI:%.*]] = mark_dependence [[THUNK_PA]] : $@callee_guaranteed () -> () on [[COPY_BORROWED_CLOSURE_1]] : $@callee_guaranteed () -> ()
93+
// CHECK: destroy_value [[THUNK_PA_MDI]]
94+
// CHECK: destroy_value [[COPY_BORROWED_CLOSURE_1]]
95+
// CHECK: } // end sil function '$s25without_actually_escaping0A24ActuallyEscapingConflictyyF'
96+
func withoutActuallyEscapingConflict() {
97+
var localVar = 0
98+
let nestedModify = { localVar = 3 }
99+
withoutActuallyEscaping(nestedModify) {
100+
modifyAndPerform(&localVar, closure: $0)
101+
}
102+
}

0 commit comments

Comments
 (0)