@@ -6116,27 +6116,47 @@ RValue RValueEmitter::visitErrorExpr(ErrorExpr *E, SGFContext C) {
61166116}
61176117
61186118RValue RValueEmitter::visitConsumeExpr (ConsumeExpr *E, SGFContext C) {
6119- auto *subExpr = cast<DeclRefExpr>( E->getSubExpr () );
6119+ auto *subExpr = E->getSubExpr ();
61206120 auto subASTType = subExpr->getType ()->getCanonicalType ();
6121-
61226121 auto subType = SGF.getLoweredType (subASTType);
61236122
6123+ if (auto *li = dyn_cast<LoadExpr>(subExpr)) {
6124+ FormalEvaluationScope writeback (SGF);
6125+ LValue lv =
6126+ SGF.emitLValue (li->getSubExpr (), SGFAccessKind::ReadWrite);
6127+ auto address = SGF.emitAddressOfLValue (subExpr, std::move (lv));
6128+ auto optTemp = SGF.emitTemporary (E, SGF.getTypeLowering (subType));
6129+ SILValue toAddr = optTemp->getAddressForInPlaceInitialization (SGF, E);
6130+ if (address.getType ().isMoveOnly ()) {
6131+ SGF.B .createCopyAddr (subExpr, address.getLValueAddress (), toAddr, IsNotTake,
6132+ IsInitialization);
6133+ } else {
6134+ SGF.B .createMarkUnresolvedMoveAddr (subExpr, address.getLValueAddress (), toAddr);
6135+ }
6136+ optTemp->finishInitialization (SGF);
6137+
6138+ if (subType.isLoadable (SGF.F )) {
6139+ ManagedValue value = SGF.B .createLoadTake (E, optTemp->getManagedAddress ());
6140+ if (value.getType ().isTrivial (SGF.F ))
6141+ return RValue (SGF, {value}, subType.getASTType ());
6142+ return RValue (SGF, {value}, subType.getASTType ());
6143+ }
6144+
6145+ return RValue (SGF, {optTemp->getManagedAddress ()}, subType.getASTType ());
6146+ }
6147+
61246148 if (subType.isLoadable (SGF.F )) {
6125- auto mv = SGF.emitRValue (subExpr).getAsSingleValue (SGF, subExpr);
6149+ ManagedValue mv = SGF.emitRValue (subExpr).getAsSingleValue (SGF, subExpr);
61266150 if (mv.getType ().isTrivial (SGF.F ))
61276151 return RValue (SGF, {mv}, subType.getASTType ());
61286152 mv = SGF.B .createMoveValue (E, mv);
6129- auto *movedValue = cast<MoveValueInst>(mv. getValue ());
6130- movedValue ->setAllowsDiagnostics (true /* set allows diagnostics */ );
6153+ // Set the flag so we check this.
6154+ cast<MoveValueInst>(mv. getValue ()) ->setAllowsDiagnostics (true );
61316155 return RValue (SGF, {mv}, subType.getASTType ());
61326156 }
61336157
61346158 // If we aren't loadable, then create a temporary initialization and
6135- // mark_unresolved_move into that if we have a copyable type if we have a move
6136- // only, just add a copy_addr init.
6137- //
6138- // The reason why we do this is that we only use mark_unresolved_move_addr and
6139- // the move operator checker for copyable values.
6159+ // explicit_copy_addr into that.
61406160 std::unique_ptr<TemporaryInitialization> optTemp;
61416161 optTemp = SGF.emitTemporary (E, SGF.getTypeLowering (subType));
61426162 SILValue toAddr = optTemp->getAddressForInPlaceInitialization (SGF, E);
@@ -6163,7 +6183,6 @@ RValue RValueEmitter::visitCopyExpr(CopyExpr *E, SGFContext C) {
61636183 auto subType = SGF.getLoweredType (subASTType);
61646184
61656185 if (auto *li = dyn_cast<LoadExpr>(subExpr)) {
6166-
61676186 FormalEvaluationScope writeback (SGF);
61686187 LValue lv =
61696188 SGF.emitLValue (li->getSubExpr (), SGFAccessKind::BorrowedAddressRead);
0 commit comments