Skip to content

Commit a6ec750

Browse files
authored
Merge pull request #23218 from gottesmm/pr-d24d308b6dec12e39ca8fb7df3726a8340b263fc
2 parents 6711faf + 15c03b7 commit a6ec750

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ ManagedValue SILGenFunction::emitFuncToBlock(SILLocation loc,
514514
// the block is ultimately destroyed checking that the closure is uniquely
515515
// referenced.
516516
bool useWithoutEscapingVerification = false;
517-
ManagedValue escaping;
517+
ManagedValue escaping;
518518
if (loweredFuncTy->isNoEscape()) {
519519
auto escapingTy = loweredFuncTy->getWithExtInfo(
520520
loweredFuncTy->getExtInfo().withNoEscape(false));
@@ -525,8 +525,11 @@ ManagedValue SILGenFunction::emitFuncToBlock(SILLocation loc,
525525
auto escapingAnyTy =
526526
funcType.withExtInfo(funcType->getExtInfo().withNoEscape(false));
527527
funcType = escapingAnyTy;
528-
fn = B.createCopyValue(loc, escaping);
528+
fn = escaping.copy(*this, loc);
529529
useWithoutEscapingVerification = true;
530+
} else {
531+
// Since we are going to be storing this into memory, we need fn at +1.
532+
fn = fn.ensurePlusOne(*this, loc);
530533
}
531534

532535
// Build the invoke function signature. The block will capture the original

test/PrintAsObjC/blocks.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Please keep this file in alphabetical order!
22

33
// RUN: %empty-directory(%t)
4-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t %s -disable-objc-attr-requires-foundation-module
5-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/blocks.swiftmodule -typecheck -emit-objc-header-path %t/blocks.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-sil-ownership -emit-module -o %t %s -disable-objc-attr-requires-foundation-module
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-sil-ownership -parse-as-library %t/blocks.swiftmodule -typecheck -emit-objc-header-path %t/blocks.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module
66
// RUN: %FileCheck %s < %t/blocks.h
77
// RUN: %check-in-clang %t/blocks.h
88

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -import-objc-header %S/Inputs/objc_block_to_func_to_block.h -emit-silgen -verify %s
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-sil-ownership -import-objc-header %S/Inputs/objc_block_to_func_to_block.h -emit-silgen -verify %s
22
// REQUIRES: objc_interop
33

44
import Foundation
55

66
func bar<A>(x: Foo<A>) {
77
x.blockInception { f in f { _ = $0 } }
88
}
9+
10+
typealias MyBlockWithEscapingParam = (@escaping () -> ()) -> Int
11+
12+
// Make sure that we properly create thunks for objc_block_to_func_to_block
13+
@objc class ObjCClass : NSObject {
14+
@objc func blockWithBlockTypealias(_ block: MyBlockWithEscapingParam) {}
15+
}

0 commit comments

Comments
 (0)