mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Bail if the closure captures an ObjectiveC block which might _not_ be copied onto the heap, i.e optimized by SimplifyCopyBlock. We can't do this because the optimization inserts retains+releases for captured arguments. That's not possible for stack-allocated blocks. Fixes a mis-compile rdar://154241245
21 lines
541 B
Swift
21 lines
541 B
Swift
// RUN: %target-swift-frontend -parse-as-library -O %s -emit-sil | %FileCheck %s
|
|
|
|
func callClosure<R>(_ body: () -> R) -> R {
|
|
return body()
|
|
}
|
|
|
|
// Check that after removing a copy_block, no retains+releases are inserted for the block.
|
|
// CHECK-LABEL: sil {{.*}}@testit :
|
|
// CHECK-NOT: retain
|
|
// CHECK-NOT: release
|
|
// CHECK: } // end sil function 'testit'
|
|
@_cdecl("testit")
|
|
public func testit(_ block: (_ index: Int) -> Int) -> Bool {
|
|
@inline(never)
|
|
func c() -> Bool {
|
|
return block(0) != 0
|
|
}
|
|
|
|
return callClosure(c)
|
|
}
|