Skip to content

When emitting no-escape closures, make sure that we copy the closure … #23478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/SILGen/SILGenPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3327,17 +3327,20 @@ SILGenFunction::createWithoutActuallyEscapingClosure(

// Create it in our current function.
auto thunkValue = B.createFunctionRefFor(loc, thunk);

// Create a copy for the noescape value, so we can mark_dependence upon the
// original value.
SILValue noEscapeValue =
noEscapingFunctionValue.ensurePlusOne(*this, loc).forward(*this);
noEscapingFunctionValue.copy(*this, loc).forward(*this);
SingleValueInstruction *thunkedFn = B.createPartialApply(
loc, thunkValue,
SILType::getPrimitiveObjectType(substFnTy),
interfaceSubs,
noEscapeValue,
SILType::getPrimitiveObjectType(escapingFnTy));
// We need to ensure the 'lifetime' of the trivial values context captures. As
// long as we rerpresent these captures by the same value the following works.
thunkedFn = B.createMarkDependence(loc, thunkedFn, noEscapeValue);
// long as we represent these captures by the same value the following works.
thunkedFn = B.createMarkDependence(loc, thunkedFn, noEscapingFunctionValue.getValue());

return emitManagedRValueWithCleanup(thunkedFn);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Interpreter/enforce_exclusive_access.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -swift-version 4 %s -o %t/a.out -enforce-exclusivity=checked -Onone
// RUN: %target-build-swift -Xfrontend -verify-sil-ownership -swift-version 4 %s -o %t/a.out -enforce-exclusivity=checked -Onone
//
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
Expand Down