@@ -206,13 +206,21 @@ ManagedValue ManagedValue::materialize(SILGenFunction &SGF,
206206 StoreOwnershipQualifier::Init);
207207
208208 // SEMANTIC SIL TODO: This should really be called a temporary LValue.
209- return ManagedValue::forOwnedAddressRValue (temporary,
210- SGF.enterDestroyCleanup (temporary));
211- } else {
212- auto object = SGF.emitManagedBeginBorrow (loc, getValue ());
213- SGF.emitManagedStoreBorrow (loc, object.getValue (), temporary);
214- return ManagedValue::forBorrowedAddressRValue (temporary);
209+ return ManagedValue::forOwnedAddressRValue (
210+ temporary, SGF.enterDestroyCleanup (temporary));
211+ }
212+ auto &lowering = SGF.getTypeLowering (getType ());
213+ if (lowering.isAddressOnly ()) {
214+ assert (!SGF.silConv .useLoweredAddresses ());
215+ auto copy = SGF.B .createCopyValue (loc, getValue ());
216+ SGF.B .emitStoreValueOperation (loc, copy, temporary,
217+ StoreOwnershipQualifier::Init);
218+ return ManagedValue::forOwnedAddressRValue (
219+ temporary, SGF.enterDestroyCleanup (temporary));
215220 }
221+ auto object = SGF.emitManagedBeginBorrow (loc, getValue ());
222+ SGF.emitManagedStoreBorrow (loc, object.getValue (), temporary);
223+ return ManagedValue::forBorrowedAddressRValue (temporary);
216224}
217225
218226void ManagedValue::print (raw_ostream &os) const {
0 commit comments