@@ -663,13 +663,42 @@ namespace {
663663 metadata);
664664 }
665665
666- void initializeMetadataWithLayoutString (IRGenFunction &IGF,
667- llvm::Value *metadata,
668- bool isVWTMutable,
669- SILType T,
670- MetadataDependencyCollector *collector) const override {
671- // Not yet supported on this type, so forward to regular method
672- initializeMetadata (IGF, metadata, isVWTMutable, T, collector);
666+ void initializeMetadataWithLayoutString (
667+ IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
668+ MetadataDependencyCollector *collector) const override {
669+ if (TIK >= Fixed)
670+ return ;
671+
672+ assert (ElementsWithPayload.size () == 1 &&
673+ " empty singleton enum should not be dynamic!" );
674+
675+ auto payloadTy =
676+ T.getEnumElementType (ElementsWithPayload[0 ].decl , IGM.getSILModule (),
677+ IGM.getMaximalTypeExpansionContext ());
678+
679+ auto request = DynamicMetadataRequest::getNonBlocking (
680+ MetadataState::LayoutComplete, collector);
681+ auto payloadMetadata =
682+ IGF.emitTypeMetadataRefForLayout (payloadTy, request);
683+
684+ auto flags = emitEnumLayoutFlags (IGF.IGM , isVWTMutable);
685+ IGF.Builder .CreateCall (
686+ IGF.IGM
687+ .getInitEnumMetadataSingleCaseWithLayoutStringFunctionPointer (),
688+ {metadata, flags, payloadMetadata});
689+
690+ // Pre swift-5.1 runtimes were missing the initialization of the
691+ // the extraInhabitantCount field. Do it here instead.
692+ auto payloadLayout = emitTypeLayoutRef (IGF, payloadTy, collector);
693+ auto payloadRef = IGF.Builder .CreateBitOrPointerCast (
694+ payloadLayout, IGF.IGM .TypeLayoutTy ->getPointerTo ());
695+ auto payloadExtraInhabitantCount =
696+ IGF.Builder .CreateLoad (IGF.Builder .CreateStructGEP (
697+ Address (payloadRef, IGF.IGM .TypeLayoutTy , Alignment (1 )), 3 ,
698+ Size (IGF.IGM .DataLayout .getTypeAllocSize (IGF.IGM .SizeTy ) * 2 +
699+ IGF.IGM .DataLayout .getTypeAllocSize (IGF.IGM .Int32Ty ))));
700+ emitStoreOfExtraInhabitantCount (IGF, payloadExtraInhabitantCount,
701+ metadata);
673702 }
674703
675704 bool mayHaveExtraInhabitants (IRGenModule &IGM) const override {
@@ -973,11 +1002,9 @@ namespace {
9731002 // witness table initialization.
9741003 }
9751004
976- void initializeMetadataWithLayoutString (IRGenFunction &IGF,
977- llvm::Value *metadata,
978- bool isVWTMutable,
979- SILType T,
980- MetadataDependencyCollector *collector) const override {
1005+ void initializeMetadataWithLayoutString (
1006+ IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
1007+ MetadataDependencyCollector *collector) const override {
9811008 // No-payload enums are always fixed-size so never need dynamic value
9821009 // witness table initialization.
9831010 }
@@ -3207,11 +3234,9 @@ namespace {
32073234 {metadata, flags, payloadLayout, emptyCasesVal});
32083235 }
32093236
3210- void initializeMetadataWithLayoutString (IRGenFunction &IGF,
3211- llvm::Value *metadata,
3212- bool isVWTMutable,
3213- SILType T,
3214- MetadataDependencyCollector *collector) const override {
3237+ void initializeMetadataWithLayoutString (
3238+ IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
3239+ MetadataDependencyCollector *collector) const override {
32153240 // Not yet supported on this type, so forward to regular method
32163241 initializeMetadata (IGF, metadata, isVWTMutable, T, collector);
32173242 }
@@ -5335,11 +5360,9 @@ namespace {
53355360 {metadata, flags, numPayloadsVal, payloadLayoutArray});
53365361 }
53375362
5338- void initializeMetadataWithLayoutString (IRGenFunction &IGF,
5339- llvm::Value *metadata,
5340- bool isVWTMutable,
5341- SILType T,
5342- MetadataDependencyCollector *collector) const override {
5363+ void initializeMetadataWithLayoutString (
5364+ IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
5365+ MetadataDependencyCollector *collector) const override {
53435366 // Fixed-size enums don't need dynamic metadata initialization.
53445367 if (TIK >= Fixed) return ;
53455368
@@ -6035,11 +6058,9 @@ namespace {
60356058 llvm_unreachable (" resilient enums cannot be defined" );
60366059 }
60376060
6038- void initializeMetadataWithLayoutString (IRGenFunction &IGF,
6039- llvm::Value *metadata,
6040- bool isVWTMutable,
6041- SILType T,
6042- MetadataDependencyCollector *collector) const override {
6061+ void initializeMetadataWithLayoutString (
6062+ IRGenFunction &IGF, llvm::Value *metadata, bool isVWTMutable, SILType T,
6063+ MetadataDependencyCollector *collector) const override {
60436064 llvm_unreachable (" resilient enums cannot be defined" );
60446065 }
60456066
0 commit comments