@@ -726,8 +726,8 @@ SILValue SILGenFunction::emitUncheckedGuaranteedConversion(SILValue value) {
726726bool SILGenFunction::emitGuaranteedReturn (
727727 SILLocation loc, Expr *ret, SmallVectorImpl<SILValue> &directResults) {
728728 auto *afd = cast<AbstractFunctionDecl>(FunctionDC->getAsDecl ());
729- assert (cast<AccessorDecl>(afd)->isBorrowAccessor ());
730-
729+ assert (cast<AccessorDecl>(afd)->isBorrowAccessor () ||
730+ cast<AccessorDecl>(afd)-> isMutateAccessor ());
731731
732732 auto emitLoadBorrowFromGuaranteedAddress =
733733 [&](ManagedValue guaranteedAddress) -> SILValue {
@@ -762,13 +762,25 @@ bool SILGenFunction::emitGuaranteedReturn(
762762 // Emit return value at +0.
763763 FormalEvaluationScope scope (*this );
764764 LValueOptions options;
765+
766+ if (cast<AccessorDecl>(afd)->isMutateAccessor ()) {
767+ options = options.forGuaranteedAddressReturn (true );
768+ } else {
769+ assert (cast<AccessorDecl>(afd)->isBorrowAccessor ());
770+ if (F.getSelfArgument ()->getType ().isObject ()) {
771+ options = options.forGuaranteedReturn (true );
772+ } else {
773+ options = options.forGuaranteedAddressReturn (true );
774+ }
775+ }
776+
765777 auto lvalue = emitLValue (ret,
766778 F.getSelfArgument ()->getType ().isObject ()
767779 ? SGFAccessKind::BorrowedObjectRead
768- : SGFAccessKind::BorrowedAddressRead,
769- F. getSelfArgument ()-> getType (). isObject ()
770- ? options. forGuaranteedReturn ( true )
771- : options. forGuaranteedAddressReturn ( true ) );
780+ : cast<AccessorDecl>(afd)-> isBorrowAccessor ()
781+ ? SGFAccessKind::BorrowedAddressRead
782+ : SGFAccessKind::Write,
783+ options);
772784
773785 // If the accessor is annotated with @_unsafeSelfDependentResultAttr,
774786 // disable diagnosing the return expression.
0 commit comments