@@ -663,6 +663,13 @@ namespace {
663
663
return ;
664
664
}
665
665
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
+
666
673
if (getLoadableSingleton ())
667
674
getLoadableSingleton ()->consume (IGF, src, atomicity,
668
675
getSingletonType (IGF.IGM , T));
@@ -677,7 +684,7 @@ namespace {
677
684
if (tryEmitDestroyUsingDeinit (IGF, addr, T)) {
678
685
return ;
679
686
}
680
-
687
+
681
688
if (getSingleton () &&
682
689
!getSingleton ()->isTriviallyDestroyable (ResilienceExpansion::Maximal)) {
683
690
if (!ElementsAreABIAccessible) {
@@ -1986,6 +1993,7 @@ namespace {
1986
1993
1987
1994
// If the payload is TriviallyDestroyable, then we can use TriviallyDestroyable value semantics.
1988
1995
auto &payloadTI = *ElementsWithPayload[0 ].ti ;
1996
+
1989
1997
if (!payloadTI.isABIAccessible ()) {
1990
1998
CopyDestroyKind = ABIInaccessible;
1991
1999
} else if (payloadTI.isTriviallyDestroyable (ResilienceExpansion::Maximal)) {
@@ -2851,6 +2859,14 @@ namespace {
2851
2859
if (tryEmitConsumeUsingDeinit (IGF, src, T)) {
2852
2860
return ;
2853
2861
}
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
+
2854
2870
assert (TIK >= Loadable);
2855
2871
2856
2872
switch (CopyDestroyKind) {
@@ -4882,6 +4898,14 @@ namespace {
4882
4898
if (tryEmitConsumeUsingDeinit (IGF, src, T)) {
4883
4899
return ;
4884
4900
}
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
+
4885
4909
assert (TIK >= Loadable);
4886
4910
switch (CopyDestroyKind) {
4887
4911
case TriviallyDestroyable:
@@ -6407,7 +6431,6 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
6407
6431
// fixed-size from this resilience scope.
6408
6432
ResilienceExpansion layoutScope =
6409
6433
TC.IGM .getResilienceExpansionForLayout (theEnum);
6410
-
6411
6434
for (auto elt : theEnum->getAllElements ()) {
6412
6435
++numElements;
6413
6436
@@ -6693,10 +6716,11 @@ namespace {
6693
6716
IsTriviallyDestroyable_t isTriviallyDestroyable,
6694
6717
IsBitwiseTakable_t isBT,
6695
6718
IsCopyable_t copyable,
6696
- IsFixedSize_t alwaysFixedSize)
6719
+ IsFixedSize_t alwaysFixedSize,
6720
+ IsABIAccessible_t isABIAccessible)
6697
6721
: FixedEnumTypeInfoBase(strategy, T, S, std::move(SB), A,
6698
6722
isTriviallyDestroyable, isBT, copyable,
6699
- alwaysFixedSize) {}
6723
+ alwaysFixedSize, isABIAccessible ) {}
6700
6724
};
6701
6725
6702
6726
// / TypeInfo for loadable enum types.
@@ -6708,10 +6732,11 @@ namespace {
6708
6732
Alignment A,
6709
6733
IsTriviallyDestroyable_t isTriviallyDestroyable,
6710
6734
IsCopyable_t copyable,
6711
- IsFixedSize_t alwaysFixedSize)
6735
+ IsFixedSize_t alwaysFixedSize,
6736
+ IsABIAccessible_t isABIAccessible)
6712
6737
: FixedEnumTypeInfoBase(strategy, T, S, std::move(SB), A,
6713
6738
isTriviallyDestroyable, copyable,
6714
- alwaysFixedSize) {}
6739
+ alwaysFixedSize, isABIAccessible ) {}
6715
6740
6716
6741
void addToAggLowering (IRGenModule &IGM, SwiftAggLowering &lowering,
6717
6742
Size offset) const override {
@@ -6821,7 +6846,8 @@ EnumImplStrategy::getFixedEnumTypeInfo(llvm::StructType *T, Size S,
6821
6846
Alignment A,
6822
6847
IsTriviallyDestroyable_t isTriviallyDestroyable,
6823
6848
IsBitwiseTakable_t isBT,
6824
- IsCopyable_t isCopyable) {
6849
+ IsCopyable_t isCopyable,
6850
+ IsABIAccessible_t abiAccessible) {
6825
6851
TypeInfo *mutableTI;
6826
6852
switch (TIK) {
6827
6853
case Opaque:
@@ -6831,14 +6857,16 @@ EnumImplStrategy::getFixedEnumTypeInfo(llvm::StructType *T, Size S,
6831
6857
isTriviallyDestroyable,
6832
6858
isBT,
6833
6859
isCopyable,
6834
- AlwaysFixedSize);
6860
+ AlwaysFixedSize,
6861
+ abiAccessible);
6835
6862
break ;
6836
6863
case Loadable:
6837
6864
assert (isBT && " loadable enum not bitwise takable?!" );
6838
6865
mutableTI = new LoadableEnumTypeInfo (*this , T, S, std::move (SB), A,
6839
6866
isTriviallyDestroyable,
6840
6867
isCopyable,
6841
- AlwaysFixedSize);
6868
+ AlwaysFixedSize,
6869
+ abiAccessible);
6842
6870
break ;
6843
6871
}
6844
6872
TI = mutableTI;
@@ -6859,7 +6887,8 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
6859
6887
alignment,
6860
6888
TriviallyDestroyable,
6861
6889
Copyable,
6862
- AlwaysFixedSize));
6890
+ AlwaysFixedSize,
6891
+ IsABIAccessible));
6863
6892
} else {
6864
6893
const TypeInfo &eltTI = *getSingleton ();
6865
6894
@@ -6886,13 +6915,16 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
6886
6915
auto alignment = fixedEltTI.getFixedAlignment ();
6887
6916
applyLayoutAttributes (TC.IGM , theEnum, /* fixed*/ true , alignment);
6888
6917
6918
+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
6919
+ Type.getASTType ());
6889
6920
return getFixedEnumTypeInfo (enumTy,
6890
6921
fixedEltTI.getFixedSize (),
6891
6922
fixedEltTI.getSpareBits (),
6892
6923
alignment,
6893
6924
TriviallyDestroyable,
6894
6925
BitwiseTakable,
6895
- Copyable);
6926
+ Copyable,
6927
+ isABIAccessible);
6896
6928
}
6897
6929
}
6898
6930
}
@@ -6927,7 +6959,8 @@ NoPayloadEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
6927
6959
alignment,
6928
6960
TriviallyDestroyable,
6929
6961
Copyable,
6930
- AlwaysFixedSize));
6962
+ AlwaysFixedSize,
6963
+ IsABIAccessible));
6931
6964
}
6932
6965
6933
6966
TypeInfo *
@@ -6976,7 +7009,8 @@ CCompatibleEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
6976
7009
alignment,
6977
7010
IsTriviallyDestroyable,
6978
7011
IsCopyable,
6979
- IsFixedSize));
7012
+ IsFixedSize,
7013
+ IsABIAccessible));
6980
7014
}
6981
7015
6982
7016
TypeInfo *SinglePayloadEnumImplStrategy::completeFixedLayout (
@@ -7044,11 +7078,15 @@ TypeInfo *SinglePayloadEnumImplStrategy::completeFixedLayout(
7044
7078
? IsNotTriviallyDestroyable : IsTriviallyDestroyable;
7045
7079
auto copyable = !theEnum->canBeCopyable ()
7046
7080
? IsNotCopyable : IsCopyable;
7081
+
7082
+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
7083
+ Type.getASTType ());
7047
7084
getFixedEnumTypeInfo (
7048
7085
enumTy, Size (sizeWithTag), spareBits.build (), alignment,
7049
7086
deinit & payloadTI.isTriviallyDestroyable (ResilienceExpansion::Maximal),
7050
7087
payloadTI.isBitwiseTakable (ResilienceExpansion::Maximal),
7051
- copyable);
7088
+ copyable, isABIAccessible);
7089
+
7052
7090
if (TIK >= Loadable && CopyDestroyKind == Normal) {
7053
7091
computePayloadTypesAndTagType (TC.IGM , *TI, PayloadTypesAndTagType);
7054
7092
loweredType = Type;
@@ -7255,9 +7293,12 @@ MultiPayloadEnumImplStrategy::completeFixedLayout(TypeConverter &TC,
7255
7293
7256
7294
applyLayoutAttributes (TC.IGM , theEnum, /* fixed*/ true , worstAlignment);
7257
7295
7296
+ auto isABIAccessible = isTypeABIAccessibleIfFixedSize (TC.IGM ,
7297
+ Type.getASTType ());
7258
7298
getFixedEnumTypeInfo (enumTy, Size (sizeWithTag), std::move (spareBits),
7259
7299
worstAlignment, isTriviallyDestroyable, isBT,
7260
- isCopyable);
7300
+ isCopyable, isABIAccessible);
7301
+
7261
7302
if (TIK >= Loadable &&
7262
7303
(CopyDestroyKind == Normal || CopyDestroyKind == BitwiseTakable)) {
7263
7304
computePayloadTypesAndTagType (TC.IGM , *TI, PayloadTypesAndTagType);
0 commit comments