mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Previously, we would emit this as %1 = load [copy] %address %2 = moveonly_wrapper_to_copyable [owned] %1 which is difficult for move-only checking to handle, since %2 looks like a consume of %1, making it difficult to determine %1's true lifetime. Change this to %1 = moveonly_wrapper_to_copyable_addr %address %2 = load [copy] %address which is handled better by move-only checking, improving the accuracy of existing move-checking as well as fixing a spurious diagnostic when indirect parameters get passed as by-value arguments to other functions.
31 lines
951 B
Swift
31 lines
951 B
Swift
// RUN: %target-swift-frontend -emit-sil -enable-experimental-feature BuiltinModule -enable-experimental-feature LifetimeDependence -enable-experimental-feature AddressableTypes -enable-experimental-feature AddressableParameters -verify %s
|
|
|
|
// REQUIRES: swift_feature_BuiltinModule
|
|
// REQUIRES: swift_feature_AddressableParameters
|
|
// REQUIRES: swift_feature_AddressableTypes
|
|
// REQUIRES: swift_feature_LifetimeDependence
|
|
|
|
@_addressableForDependencies
|
|
struct Node {
|
|
var id: AnyObject
|
|
|
|
func grungle() {}
|
|
}
|
|
|
|
struct NodeRef: ~Escapable {
|
|
private var parent: UnsafePointer<Node>
|
|
|
|
@lifetime(borrow node)
|
|
init(node: borrowing Node) { fatalError() }
|
|
}
|
|
|
|
// Ensure there aren't spurious errors about consumption when an addressable
|
|
// parameter is passed as a normal loadable parameter to another function
|
|
// or method.
|
|
@lifetime(borrow node)
|
|
func test(node: borrowing Node) -> NodeRef {
|
|
node.grungle()
|
|
return NodeRef(node: node)
|
|
}
|
|
|