Files
swift-mirror/test/SILGen/addressable_read.swift
Meghana Gupta 7c25466b21 Avoid unnecessary insertion of mark_unresolved_noncopyable_value
SILGen inserts mark_unresolved_noncopyable_value at the introducer in some cases and at uses in other cases. This inconsistency can causes insertion of a redundant mark* instruction which crashes the move-only checker.

This change avoids inserting a redundant mark* instruction.
2025-10-23 05:19:16 -07:00

24 lines
756 B
Swift

// RUN: %target-swift-frontend -emit-sil -verify -enable-experimental-feature AddressableParameters %s
// REQUIRES: swift_feature_AddressableParameters
public struct Container<Element: ~Copyable >: ~Copyable {
var _storage: UnsafeMutableBufferPointer<Element>
var _count: Int
public subscript(index: Int) -> Element {
@_addressableSelf
_read {
precondition(index >= 0 && index < _count, "Index out of bounds")
yield _storage.baseAddress.unsafelyUnwrapped.advanced(by: index).pointee
}
_modify {
precondition(index >= 0 && index < _count, "Index out of bounds")
yield &_storage.baseAddress.unsafelyUnwrapped.advanced(by: index).pointee
}
}
}
extension Container: Copyable where Element: Copyable {}