Files
swift-mirror/test/SILGen/indirect_accessor_access.swift
Joe Groff 19329e3e03 SILGen: Treat read-formal-accessed lvalues as borrows.
A read access asserts that the memory location is immutable for the duration
of the access, so it can be treated as a borrow rather than a mutable lvalue.
Doing this allows the borrow formal access scope fixes from #79084 to apply
to situations where a loadable type undergoes an accessor-based access with
indirect arguments (such as for public accessors when library evolution is
enabled for the type). Fixes rdar://143334632.
2025-02-04 08:23:34 -08:00

23 lines
592 B
Swift

// rdar://143334632
// RUN: %target-swift-emit-silgen -enable-library-evolution %s | %FileCheck %s
public struct Foo {
// CHECK-LABEL: sil {{.*}} @$s{{.*}}3FooV3foo
mutating func foo() -> Int {
// CHECK: [[BEGIN_READ:%.*]] = begin_access [read] [unknown] %0
// CHECK: ([[RESULT:%.*]], [[TOKEN:%.*]]) = begin_apply %{{.*}}([[BEGIN_READ]])
// CHECK: end_apply [[TOKEN]]
// CHECK: end_access [[BEGIN_READ]]
// CHECK: return [[RESULT]]
return self[]
}
var object : AnyObject
subscript() -> Int {
_read {fatalError()}
_modify {fatalError()}
}
}