@@ -4670,10 +4670,8 @@ namespace {
4670
4670
};
4671
4671
} // end anonymous namespace
4672
4672
4673
- EnumImplStrategy *EnumImplStrategy::get (TypeConverter &TC,
4674
- SILType type,
4675
- EnumDecl *theEnum)
4676
- {
4673
+ std::unique_ptr<EnumImplStrategy>
4674
+ EnumImplStrategy::get (TypeConverter &TC, SILType type, EnumDecl *theEnum) {
4677
4675
unsigned numElements = 0 ;
4678
4676
TypeInfoKind tik = Loadable;
4679
4677
IsFixedSize_t alwaysFixedSize = IsFixedSize;
@@ -4779,43 +4777,49 @@ EnumImplStrategy *EnumImplStrategy::get(TypeConverter &TC,
4779
4777
&& " not all elements accounted for" );
4780
4778
4781
4779
if (isResilient) {
4782
- return new ResilientEnumImplStrategy (TC.IGM ,
4780
+ return std::unique_ptr<EnumImplStrategy>(
4781
+ new ResilientEnumImplStrategy (TC.IGM ,
4783
4782
numElements,
4784
4783
std::move (elementsWithPayload),
4785
- std::move (elementsWithNoPayload));
4784
+ std::move (elementsWithNoPayload))) ;
4786
4785
}
4787
4786
4788
4787
// Enums imported from Clang or marked with @objc use C-compatible layout.
4789
4788
if (theEnum->hasClangNode () || theEnum->isObjC ()) {
4790
4789
assert (elementsWithPayload.size () == 0 && " C enum with payload?!" );
4791
4790
assert (alwaysFixedSize == IsFixedSize && " C enum with resilient payload?!" );
4792
- return new CCompatibleEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4791
+ return std::unique_ptr<EnumImplStrategy>(
4792
+ new CCompatibleEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4793
4793
numElements,
4794
4794
std::move (elementsWithPayload),
4795
- std::move (elementsWithNoPayload));
4795
+ std::move (elementsWithNoPayload))) ;
4796
4796
}
4797
4797
4798
4798
if (numElements <= 1 )
4799
- return new SingletonEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4799
+ return std::unique_ptr<EnumImplStrategy>(
4800
+ new SingletonEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4800
4801
numElements,
4801
4802
std::move (elementsWithPayload),
4802
- std::move (elementsWithNoPayload));
4803
+ std::move (elementsWithNoPayload))) ;
4803
4804
if (elementsWithPayload.size () > 1 )
4804
- return new MultiPayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4805
+ return std::unique_ptr<EnumImplStrategy>(
4806
+ new MultiPayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4805
4807
allowFixedLayoutOptimizations,
4806
4808
numElements,
4807
4809
std::move (elementsWithPayload),
4808
- std::move (elementsWithNoPayload));
4810
+ std::move (elementsWithNoPayload))) ;
4809
4811
if (elementsWithPayload.size () == 1 )
4810
- return new SinglePayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4812
+ return std::unique_ptr<EnumImplStrategy>(
4813
+ new SinglePayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4811
4814
numElements,
4812
4815
std::move (elementsWithPayload),
4813
- std::move (elementsWithNoPayload));
4816
+ std::move (elementsWithNoPayload))) ;
4814
4817
4815
- return new NoPayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4818
+ return std::unique_ptr<EnumImplStrategy>(
4819
+ new NoPayloadEnumImplStrategy (TC.IGM , tik, alwaysFixedSize,
4816
4820
numElements,
4817
4821
std::move (elementsWithPayload),
4818
- std::move (elementsWithNoPayload));
4822
+ std::move (elementsWithNoPayload))) ;
4819
4823
}
4820
4824
4821
4825
namespace {
@@ -4829,6 +4833,10 @@ namespace {
4829
4833
EnumTypeInfoBase (EnumImplStrategy &strategy, AA &&...args)
4830
4834
: BaseTypeInfo(std::forward<AA>(args)...), Strategy(strategy) {}
4831
4835
4836
+ ~EnumTypeInfoBase () {
4837
+ delete &Strategy;
4838
+ }
4839
+
4832
4840
llvm::StructType *getStorageType () const {
4833
4841
return cast<llvm::StructType>(TypeInfo::getStorageType ());
4834
4842
}
@@ -5502,11 +5510,12 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type,
5502
5510
SILType loweredTy = SILType::getPrimitiveAddressType (type);
5503
5511
5504
5512
// Determine the implementation strategy.
5505
- EnumImplStrategy *strategy = EnumImplStrategy::get (*this , loweredTy, theEnum);
5513
+ auto strategy = EnumImplStrategy::get (*this , loweredTy, theEnum).release ();
5514
+
5515
+ // Create the TI. The TI will delete the strategy in its destructor.
5516
+ auto *ti =
5517
+ strategy->completeEnumTypeLayout (*this , loweredTy, theEnum, storageType);
5506
5518
5507
- // Create the TI.
5508
- auto *ti = strategy->completeEnumTypeLayout (*this , loweredTy,
5509
- theEnum, storageType);
5510
5519
// Assert that the layout query functions for fixed-layout enums work, for
5511
5520
// LLDB's sake.
5512
5521
#ifndef NDEBUG
0 commit comments