@@ -2743,9 +2743,11 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
27432743 // There no real argument to pass to the underlying accessors.
27442744 if (!storage->getDeclContext ()->isTypeContext ())
27452745 return ManagedValue ();
2746-
2747- auto paramOrigValue =
2748- ManagedValue::forBorrowedRValue (paramArg).copy (subSGF, loc);
2746+
2747+ auto paramOrigValue = paramArg->getType ().isTrivial (subSGF.F )
2748+ ? ManagedValue::forTrivialRValue (paramArg)
2749+ : ManagedValue::forBorrowedRValue (paramArg);
2750+ paramOrigValue = paramOrigValue.copy (subSGF, loc);
27492751 auto paramSubstValue = subSGF.emitOrigToSubstValue (loc, paramOrigValue,
27502752 AbstractionPattern::getOpaque (),
27512753 baseType);
@@ -2942,15 +2944,20 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
29422944 subSGF.F .getTypeExpansionContext ());
29432945
29442946 auto entry = thunk->begin ();
2945- auto resultArgTy = signature->getSingleResult ().getSILStorageType (
2946- SGM.M , signature, subSGF.F .getTypeExpansionContext ());
2947- auto baseArgTy = signature->getParameters ()[0 ].getSILStorageType (
2948- SGM.M , signature, subSGF.F .getTypeExpansionContext ());
2947+ auto resultArgTy =
2948+ subSGF.silConv .getSILType (signature->getSingleResult (), signature,
2949+ subSGF.F .getTypeExpansionContext ());
2950+ auto baseArgTy =
2951+ subSGF.silConv .getSILType (signature->getParameters ()[0 ], signature,
2952+ subSGF.F .getTypeExpansionContext ());
29492953 if (genericEnv) {
29502954 resultArgTy = genericEnv->mapTypeIntoContext (SGM.M , resultArgTy);
29512955 baseArgTy = genericEnv->mapTypeIntoContext (SGM.M , baseArgTy);
29522956 }
2953- auto resultArg = entry->createFunctionArgument (resultArgTy);
2957+ SILFunctionArgument *resultArg = nullptr ;
2958+ if (SGM.M .useLoweredAddresses ()) {
2959+ resultArg = entry->createFunctionArgument (resultArgTy);
2960+ }
29542961 auto baseArg = entry->createFunctionArgument (baseArgTy);
29552962 SILValue indexPtrArg;
29562963 if (!indexes.empty ()) {
@@ -2997,15 +3004,21 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
29973004 resultSubst = std::move (resultRValue).getAsSingleValue (subSGF, loc);
29983005 }
29993006
3000- if (resultSubst.getType ().getAddressType () != resultArg-> getType () )
3007+ if (resultSubst.getType ().getAddressType () != resultArgTy )
30013008 resultSubst = subSGF.emitSubstToOrigValue (loc, resultSubst,
30023009 AbstractionPattern::getOpaque (),
30033010 propertyType);
3004-
3005- resultSubst.forwardInto (subSGF, loc, resultArg);
3006- scope.pop ();
3007-
3008- subSGF.B .createReturn (loc, subSGF.emitEmptyTuple (loc));
3011+
3012+ if (SGM.M .useLoweredAddresses ()) {
3013+ resultSubst.forwardInto (subSGF, loc, resultArg);
3014+ scope.pop ();
3015+
3016+ subSGF.B .createReturn (loc, subSGF.emitEmptyTuple (loc));
3017+ } else {
3018+ auto result = resultSubst.forward (subSGF);
3019+ scope.pop ();
3020+ subSGF.B .createReturn (loc, result);
3021+ }
30093022
30103023 SGM.emitLazyConformancesForFunction (thunk);
30113024 return thunk;
0 commit comments