Skip to content

Commit bef2075

Browse files
committed
Use unchecked_ownership during SILGen of borrow accessors
1 parent 33ebf80 commit bef2075

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,6 +5479,13 @@ ManagedValue SILGenFunction::applyBorrowMutateAccessor(
54795479
assert(rawResults.size() == 1);
54805480
auto rawResult = rawResults[0];
54815481

5482+
if (fn.getFunction()->getConventions().hasGuaranteedResult()) {
5483+
auto selfArg = args.back().getValue();
5484+
if (isa<LoadBorrowInst>(selfArg)) {
5485+
rawResult = B.createUncheckedOwnership(loc, rawResult);
5486+
}
5487+
}
5488+
54825489
if (rawResult->getType().isMoveOnly()) {
54835490
if (rawResult->getType().isAddress()) {
54845491
auto result = B.createMarkUnresolvedNonCopyableValueInst(

lib/SILGen/SILGenStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,8 @@ bool SILGenFunction::emitBorrowOrMutateAccessorResult(
719719
assert(guaranteedAddress.getValue()->getType().isAddress());
720720
assert(F.getConventions().hasGuaranteedResult());
721721
auto regularLoc = RegularLocation::getAutoGeneratedLocation();
722-
return B.createLoadBorrow(regularLoc, guaranteedAddress).getValue();
722+
auto load = B.createLoadBorrow(regularLoc, guaranteedAddress).getValue();
723+
return B.createUncheckedOwnership(regularLoc, load);
723724
};
724725

725726
// If the return expression is a literal, emit as a regular return

0 commit comments

Comments
 (0)