@@ -468,6 +468,7 @@ namespace {
468468
469469 RValue visitStringLiteralExpr (StringLiteralExpr *E, SGFContext C);
470470 RValue visitLoadExpr (LoadExpr *E, SGFContext C);
471+ RValue visitBorrowExpr (BorrowExpr *E, SGFContext C);
471472 RValue visitDerivedToBaseExpr (DerivedToBaseExpr *E, SGFContext C);
472473 RValue visitMetatypeConversionExpr (MetatypeConversionExpr *E,
473474 SGFContext C);
@@ -1103,6 +1104,24 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
11031104 C.withFollowingSideEffects ());
11041105}
11051106
1107+ RValue RValueEmitter::visitBorrowExpr (BorrowExpr *E, SGFContext C_Ignored) {
1108+ // NOTE: You should NOT add an evaluation scope here!
1109+ //
1110+ // The callers of this visitor should have established a scope already that
1111+ // encompasses the use of the borrowed RValue that we return.
1112+ ASSERT (SGF.isInFormalEvaluationScope () && " emit borrow_expr without scope?" );
1113+
1114+ auto accessKind =
1115+ SGF.getTypeLowering (E->getType ()).isAddress ()
1116+ ? SGFAccessKind::BorrowedAddressRead
1117+ : SGFAccessKind::BorrowedObjectRead;
1118+
1119+ LValue lv = SGF.emitLValue (E->getSubExpr (), accessKind);
1120+ auto substFormalType = lv.getSubstFormalType ();
1121+ ManagedValue mv = SGF.emitBorrowedLValue (E, std::move (lv));
1122+ return RValue (SGF, E, substFormalType, mv);
1123+ }
1124+
11061125SILValue SILGenFunction::emitTemporaryAllocation (SILLocation loc, SILType ty,
11071126 HasDynamicLifetime_t dynamic,
11081127 IsLexical_t isLexical,
0 commit comments