@@ -4544,9 +4544,18 @@ ManagedValue SILGenFunction::emitConversionToSemanticRValue(
4544
4544
switch (swiftStorageType->getOwnership ()) {
4545
4545
case ReferenceOwnership::Strong:
4546
4546
llvm_unreachable (" strong reference storage type should be impossible" );
4547
- #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4548
- case ReferenceOwnership::Name: \
4549
- /* Address-only storage types are handled with their underlying type. */ \
4547
+ #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4548
+ case ReferenceOwnership::Name: \
4549
+ if (!useLoweredAddresses ()) { \
4550
+ auto refTy = src.getType (); \
4551
+ auto ty = refTy.getReferenceStorageReferentType (); \
4552
+ assert (ty); \
4553
+ assert (ty.getOptionalObjectType ()); \
4554
+ (void )ty; \
4555
+ /* Copy the weak value, opening the @sil_weak box. */ \
4556
+ return B.createStrongCopy ##Name##Value (loc, src); \
4557
+ } \
4558
+ /* Address-only storage types are handled with their underlying type. */ \
4550
4559
llvm_unreachable (" address-only pointers are handled elsewhere" );
4551
4560
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4552
4561
case ReferenceOwnership::Name: \
@@ -4827,11 +4836,26 @@ SILValue SILGenFunction::emitConversionFromSemanticValue(SILLocation loc,
4827
4836
}
4828
4837
4829
4838
auto swiftStorageType = storageType.castTo <ReferenceStorageType>();
4839
+ if (!useLoweredAddresses () && storageType.isAddressOnly (F)) {
4840
+ switch (swiftStorageType->getOwnership ()) {
4841
+ case ReferenceOwnership::Strong:
4842
+ llvm_unreachable (" strong reference storage type should be impossible" );
4843
+ case ReferenceOwnership::Unmanaged:
4844
+ llvm_unreachable (" unimplemented" );
4845
+ case ReferenceOwnership::Weak: {
4846
+ auto value = B.createWeakCopyValue (loc, semanticValue);
4847
+ B.emitDestroyValueOperation (loc, semanticValue);
4848
+ return value;
4849
+ }
4850
+ case ReferenceOwnership::Unowned:
4851
+ llvm_unreachable (" unimplemented" );
4852
+ }
4853
+ }
4830
4854
switch (swiftStorageType->getOwnership ()) {
4831
4855
case ReferenceOwnership::Strong:
4832
4856
llvm_unreachable (" strong reference storage type should be impossible" );
4833
- #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4834
- case ReferenceOwnership::Name: \
4857
+ #define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4858
+ case ReferenceOwnership::Name: \
4835
4859
llvm_unreachable (" address-only types are never loadable" );
4836
4860
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
4837
4861
case ReferenceOwnership::Name: { \
0 commit comments