@@ -4414,9 +4414,18 @@ ManagedValue SILGenFunction::emitConversionToSemanticRValue(
4414
4414
switch (swiftStorageType->getOwnership ()) {
4415
4415
case ReferenceOwnership::Strong:
4416
4416
llvm_unreachable (" strong reference storage type should be impossible" );
4417
- #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4418
- case ReferenceOwnership::Name: \
4419
- /* Address-only storage types are handled with their underlying type. */ \
4417
+ #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4418
+ case ReferenceOwnership::Name: \
4419
+ if (!useLoweredAddresses ()) { \
4420
+ auto refTy = src.getType (); \
4421
+ auto ty = refTy.getReferenceStorageReferentType (); \
4422
+ assert (ty); \
4423
+ assert (ty.getOptionalObjectType ()); \
4424
+ (void )ty; \
4425
+ /* Copy the weak value, opening the @sil_weak box. */ \
4426
+ return B.createStrongCopy ##Name##Value (loc, src); \
4427
+ } \
4428
+ /* Address-only storage types are handled with their underlying type. */ \
4420
4429
llvm_unreachable (" address-only pointers are handled elsewhere" );
4421
4430
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4422
4431
case ReferenceOwnership::Name: \
@@ -4697,11 +4706,26 @@ SILValue SILGenFunction::emitConversionFromSemanticValue(SILLocation loc,
4697
4706
}
4698
4707
4699
4708
auto swiftStorageType = storageType.castTo <ReferenceStorageType>();
4709
+ if (!useLoweredAddresses () && storageType.isAddressOnly (F)) {
4710
+ switch (swiftStorageType->getOwnership ()) {
4711
+ case ReferenceOwnership::Strong:
4712
+ llvm_unreachable (" strong reference storage type should be impossible" );
4713
+ case ReferenceOwnership::Unmanaged:
4714
+ llvm_unreachable (" unimplemented" );
4715
+ case ReferenceOwnership::Weak: {
4716
+ auto value = B.createWeakCopyValue (loc, semanticValue);
4717
+ B.emitDestroyValueOperation (loc, semanticValue);
4718
+ return value;
4719
+ }
4720
+ case ReferenceOwnership::Unowned:
4721
+ llvm_unreachable (" unimplemented" );
4722
+ }
4723
+ }
4700
4724
switch (swiftStorageType->getOwnership ()) {
4701
4725
case ReferenceOwnership::Strong:
4702
4726
llvm_unreachable (" strong reference storage type should be impossible" );
4703
- #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4704
- case ReferenceOwnership::Name: \
4727
+ #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4728
+ case ReferenceOwnership::Name: \
4705
4729
llvm_unreachable (" address-only types are never loadable" );
4706
4730
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4707
4731
case ReferenceOwnership::Name: { \
0 commit comments