Files
swift-mirror/test/SILGen/addressable_capture_2.swift
Joe Groff 42d1ca3338 SILGen: Fix positioning of store_borrow for addressable references to closure captures.
These get passed to the closure body in SIL as function arguments to the entry
point, so the alloc_stack necessarily has to appear inside of the value's lifetime,
and the store_borrow needs to be placed after that alloc_stack.
2025-07-28 17:04:49 -07:00

22 lines
551 B
Swift

// RUN: %target-swift-emit-silgen -enable-experimental-feature AddressableParameters %s | %FileCheck %s
// REQUIRES: swift_feature_AddressableParameters
struct Foo {
var x, y, z: Int
init() { fatalError() }
@_addressableSelf
func foo() {}
}
func block(_: (Int) -> ()) {}
func test() {
let x = Foo()
block { (_) in x.foo() }
}
// ensure the closure properly nests the store_borrow after the alloc_stack:
// CHECK-LABEL: sil{{.*}} @${{.*}}4test{{.*}}U_ : $
// CHECK: [[STACK:%.*]] = alloc_stack
// CHECK-NEXT: store_borrow {{.*}} to [[STACK]]