Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,15 @@ void SILGenFunction::emitCaptures(SILLocation loc,
// If we have a mutable binding for a 'let', such as 'self' in an
// 'init' method, load it.
if (val->getType().isMoveOnly()) {
val = B.createMarkUnresolvedNonCopyableValueInst(
loc, val,
MarkUnresolvedNonCopyableValueInst::CheckKind::
NoConsumeOrAssign);
auto *moveOnlyIntroducer = dyn_cast_or_null<MarkUnresolvedNonCopyableValueInst>(val);
if (!moveOnlyIntroducer || moveOnlyIntroducer->getCheckKind() !=
MarkUnresolvedNonCopyableValueInst::
CheckKind::NoConsumeOrAssign) {
val = B.createMarkUnresolvedNonCopyableValueInst(
loc, val,
MarkUnresolvedNonCopyableValueInst::CheckKind::
NoConsumeOrAssign);
}
}
val = emitLoad(loc, val, tl, SGFContext(), IsNotTake).forward(*this);
}
Expand Down
21 changes: 21 additions & 0 deletions test/SILGen/addressable_read.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -emit-sil -verify -enable-experimental-feature AddressableParameters %s

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 {}