@@ -271,6 +271,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
271271 break ;
272272 case CaptureKind::Immutable:
273273 case CaptureKind::StorageAddress:
274+ // FIXME_addrlower: only call getAddressType for M.useLoweredAddresses()
274275 capturedArgs.push_back (emitUndef (getLoweredType (type).getAddressType ()));
275276 break ;
276277 case CaptureKind::Box: {
@@ -290,11 +291,13 @@ void SILGenFunction::emitCaptures(SILLocation loc,
290291 // Get an address value for a SILValue if it is address only in an type
291292 // expansion context without opaque archetype substitution.
292293 auto getAddressValue = [&](SILValue entryValue) -> SILValue {
293- if (SGM.Types .getTypeLowering (
294- valueType,
295- TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (
296- expansion.getResilienceExpansion ()))
297- .isAddressOnly ()
294+ if (SGM.M .useLoweredAddresses ()
295+ && SGM.Types
296+ .getTypeLowering (
297+ valueType,
298+ TypeExpansionContext::noOpaqueTypeArchetypesSubstitution (
299+ expansion.getResilienceExpansion ()))
300+ .isAddressOnly ()
298301 && !entryValue->getType ().isAddress ()) {
299302
300303 auto addr = emitTemporaryAllocation (vd, entryValue->getType ());
@@ -342,13 +345,15 @@ void SILGenFunction::emitCaptures(SILLocation loc,
342345 }
343346 case CaptureKind::Immutable: {
344347 if (canGuarantee) {
345- auto entryValue = getAddressValue (Entry.value );
346348 // No-escaping stored declarations are captured as the
347349 // address of the value.
348- assert ( entryValue-> getType (). isAddress () && " no address for captured var! " );
349- capturedArgs.push_back (ManagedValue::forLValue (entryValue));
350+ auto entryValue = getAddressValue (Entry. value );
351+ capturedArgs.push_back (ManagedValue::forBorrowedRValue (entryValue));
350352 }
351- else {
353+ else if (!silConv.useLoweredAddresses ()) {
354+ capturedArgs.push_back (
355+ B.createCopyValue (loc, ManagedValue::forUnmanaged (Entry.value )));
356+ } else {
352357 auto entryValue = getAddressValue (Entry.value );
353358 // We cannot pass a valid SILDebugVariable while creating the temp here
354359 // See rdar://60425582
0 commit comments