@@ -663,6 +663,13 @@ namespace {
663663 return ;
664664 }
665665
666+ if (!ElementsAreABIAccessible) {
667+ auto temporary = TI->allocateStack (IGF, T, " deinit.arg" ).getAddress ();
668+ cast<LoadableTypeInfo>(TI)->initialize (IGF, src, temporary, /* outlined*/ false );
669+ emitDestroyCall (IGF, T, temporary);
670+ return ;
671+ }
672+
666673 if (getLoadableSingleton ())
667674 getLoadableSingleton ()->consume (IGF, src, atomicity,
668675 getSingletonType (IGF.IGM , T));
@@ -677,7 +684,7 @@ namespace {
677684 if (tryEmitDestroyUsingDeinit (IGF, addr, T)) {
678685 return ;
679686 }
680-
687+
681688 if (getSingleton () &&
682689 !getSingleton ()->isTriviallyDestroyable (ResilienceExpansion::Maximal)) {
683690 if (!ElementsAreABIAccessible) {
@@ -1986,6 +1993,7 @@ namespace {
19861993
19871994 // If the payload is TriviallyDestroyable, then we can use TriviallyDestroyable value semantics.
19881995 auto &payloadTI = *ElementsWithPayload[0 ].ti ;
1996+
19891997 if (!payloadTI.isABIAccessible ()) {
19901998 CopyDestroyKind = ABIInaccessible;
19911999 } else if (payloadTI.isTriviallyDestroyable (ResilienceExpansion::Maximal)) {
@@ -2851,6 +2859,14 @@ namespace {
28512859 if (tryEmitConsumeUsingDeinit (IGF, src, T)) {
28522860 return ;
28532861 }
2862+
2863+ if (!ElementsAreABIAccessible) {
2864+ auto temporary = TI->allocateStack (IGF, T, " deinit.arg" ).getAddress ();
2865+ cast<LoadableTypeInfo>(TI)->initialize (IGF, src, temporary, /* outlined*/ false );
2866+ emitDestroyCall (IGF, T, temporary);
2867+ return ;
2868+ }
2869+
28542870 assert (TIK >= Loadable);
28552871
28562872 switch (CopyDestroyKind) {
@@ -4882,6 +4898,14 @@ namespace {
48824898 if (tryEmitConsumeUsingDeinit (IGF, src, T)) {
48834899 return ;
48844900 }
4901+
4902+ if (!ElementsAreABIAccessible) {
4903+ auto temporary = TI->allocateStack (IGF, T, " deinit.arg" ).getAddress ();
4904+ cast<LoadableTypeInfo>(TI)->initialize (IGF, src, temporary, /* outlined*/ false );
4905+ emitDestroyCall (IGF, T, temporary);
4906+ return ;
4907+ }
4908+
48854909 assert (TIK >= Loadable);
48864910 switch (CopyDestroyKind) {
48874911 case TriviallyDestroyable:
@@ -6407,7 +6431,6 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
64076431 // fixed-size from this resilience scope.
64086432 ResilienceExpansion layoutScope =
64096433 TC.IGM .getResilienceExpansionForLayout (theEnum);
6410-
64116434 for (auto elt : theEnum->getAllElements ()) {
64126435 ++numElements;
64136436
@@ -6693,10 +6716,11 @@ namespace {
66936716 IsTriviallyDestroyable_t isTriviallyDestroyable,
66946717 IsBitwiseTakable_t isBT,
66956718 IsCopyable_t copyable,
6696- IsFixedSize_t alwaysFixedSize)
6719+ IsFixedSize_t alwaysFixedSize,
6720+ IsABIAccessible_t isABIAccessible)
66976721 : FixedEnumTypeInfoBase(strategy, T, S, std::move(SB), A,
66986722 isTriviallyDestroyable, isBT, copyable,
6699- alwaysFixedSize) {}
6723+ alwaysFixedSize, isABIAccessible ) {}
67006724 };
67016725
67026726 // / TypeInfo for loadable enum types.
@@ -6708,10 +6732,11 @@ namespace {
67086732 Alignment A,
67096733 IsTriviallyDestroyable_t isTriviallyDestroyable,
67106734 IsCopyable_t copyable,
6711- IsFixedSize_t alwaysFixedSize)
6735+ IsFixedSize_t alwaysFixedSize,
6736+ IsABIAccessible_t isABIAccessible)
67126737 : FixedEnumTypeInfoBase(strategy, T, S, std::move(SB), A,
67136738 isTriviallyDestroyable, copyable,
6714- alwaysFixedSize) {}
6739+ alwaysFixedSize, isABIAccessible ) {}
67156740
67166741 void addToAggLowering (IRGenModule &IGM, SwiftAggLowering &lowering,
67176742 Size offset) const override {
@@ -6821,7 +6846,8 @@ EnumImplStrategy::getFixedEnumTypeInfo(llvm::StructType *T, Size S,
68216846 Alignment A,
68226847 IsTriviallyDestroyable_t isTriviallyDestroyable,
68236848 IsBitwiseTakable_t isBT,
6824- IsCopyable_t isCopyable) {
6849+ IsCopyable_t isCopyable,
6850+ IsABIAccessible_t abiAccessible) {
68256851 TypeInfo *mutableTI;
68266852 switch (TIK) {
68276853 case Opaque:
@@ -6831,14 +6857,16 @@ EnumImplStrategy::getFixedEnumTypeInfo(llvm::StructType *T, Size S,
68316857 isTriviallyDestroyable,
68326858 isBT,
68336859 isCopyable,
6834- AlwaysFixedSize);
6860+ AlwaysFixedSize,
6861+ abiAccessible);
68356862 break ;
68366863 case Loadable:
68376864 assert (isBT && " loadable enum not bitwise takable?!" );
68386865 mutableTI = new LoadableEnumTypeInfo (*this , T, S, std::move (SB), A,
68396866 isTriviallyDestroyable,
68406867 isCopyable,
6841- AlwaysFixedSize);
6868+ AlwaysFixedSize,
6869+ abiAccessible);
68426870 break ;
68436871 }
68446872 TI = mutableTI;
@@ -6859,7 +6887,8 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
68596887 alignment,
68606888 TriviallyDestroyable,
68616889 Copyable,
6862- AlwaysFixedSize));
6890+ AlwaysFixedSize,
6891+ IsABIAccessible));
68636892 } else {
68646893 const TypeInfo &eltTI = *getSingleton ();
68656894
@@ -6886,13 +6915,16 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
68866915 auto alignment = fixedEltTI.getFixedAlignment ();
68876916 applyLayoutAttributes (TC.IGM , theEnum, /* fixed*/ true , alignment);
68886917
6918+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
6919+ Type.getASTType ());
68896920 return getFixedEnumTypeInfo (enumTy,
68906921 fixedEltTI.getFixedSize (),
68916922 fixedEltTI.getSpareBits (),
68926923 alignment,
68936924 TriviallyDestroyable,
68946925 BitwiseTakable,
6895- Copyable);
6926+ Copyable,
6927+ isABIAccessible);
68966928 }
68976929 }
68986930}
@@ -6927,7 +6959,8 @@ NoPayloadEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
69276959 alignment,
69286960 TriviallyDestroyable,
69296961 Copyable,
6930- AlwaysFixedSize));
6962+ AlwaysFixedSize,
6963+ IsABIAccessible));
69316964}
69326965
69336966TypeInfo *
@@ -6976,7 +7009,8 @@ CCompatibleEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
69767009 alignment,
69777010 IsTriviallyDestroyable,
69787011 IsCopyable,
6979- IsFixedSize));
7012+ IsFixedSize,
7013+ IsABIAccessible));
69807014}
69817015
69827016TypeInfo *SinglePayloadEnumImplStrategy::completeFixedLayout (
@@ -7044,11 +7078,15 @@ TypeInfo *SinglePayloadEnumImplStrategy::completeFixedLayout(
70447078 ? IsNotTriviallyDestroyable : IsTriviallyDestroyable;
70457079 auto copyable = !theEnum->canBeCopyable ()
70467080 ? IsNotCopyable : IsCopyable;
7081+
7082+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
7083+ Type.getASTType ());
70477084 getFixedEnumTypeInfo (
70487085 enumTy, Size (sizeWithTag), spareBits.build (), alignment,
70497086 deinit & payloadTI.isTriviallyDestroyable (ResilienceExpansion::Maximal),
70507087 payloadTI.isBitwiseTakable (ResilienceExpansion::Maximal),
7051- copyable);
7088+ copyable, isABIAccessible);
7089+
70527090 if (TIK >= Loadable && CopyDestroyKind == Normal) {
70537091 computePayloadTypesAndTagType (TC.IGM , *TI, PayloadTypesAndTagType);
70547092 loweredType = Type;
@@ -7255,9 +7293,12 @@ MultiPayloadEnumImplStrategy::completeFixedLayout(TypeConverter &TC,
72557293
72567294 applyLayoutAttributes (TC.IGM , theEnum, /* fixed*/ true , worstAlignment);
72577295
7296+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
7297+ Type.getASTType ());
72587298 getFixedEnumTypeInfo (enumTy, Size (sizeWithTag), std::move (spareBits),
72597299 worstAlignment, isTriviallyDestroyable, isBT,
7260- isCopyable);
7300+ isCopyable, isABIAccessible);
7301+
72617302 if (TIK >= Loadable &&
72627303 (CopyDestroyKind == Normal || CopyDestroyKind == BitwiseTakable)) {
72637304 computePayloadTypesAndTagType (TC.IGM , *TI, PayloadTypesAndTagType);
0 commit comments