@@ -3213,9 +3213,9 @@ static void emitInitializeFieldOffsetVectorWithLayoutString(
32133213 IGM.getPointerSize () * numFields);
32143214}
32153215
3216- static void emitInitializeRawLayoutOld (IRGenFunction &IGF, SILType likeType,
3217- llvm::Value *count, SILType T,
3218- llvm::Value *metadata,
3216+ static void emitInitializeRawLayoutOldOld (IRGenFunction &IGF, SILType likeType,
3217+ llvm::Value *count, SILType T,
3218+ llvm::Value *metadata,
32193219 MetadataDependencyCollector *collector) {
32203220 auto &IGM = IGF.IGM ;
32213221
@@ -3296,11 +3296,11 @@ static void emitInitializeRawLayoutOld(IRGenFunction &IGF, SILType likeType,
32963296 IGF.Builder .CreateLifetimeEnd (fieldLayouts, IGM.getPointerSize ());
32973297}
32983298
3299- static void emitInitializeRawLayout (IRGenFunction &IGF, SILType likeType,
3300- llvm::Value *count, SILType T,
3301- llvm::Value *metadata,
3302- MetadataDependencyCollector *collector) {
3303- // If our deployment target doesn't contain the new swift_initRawStructMetadata,
3299+ static void emitInitializeRawLayoutOld (IRGenFunction &IGF, SILType likeType,
3300+ llvm::Value *count, SILType T,
3301+ llvm::Value *metadata,
3302+ MetadataDependencyCollector *collector) {
3303+ // If our deployment target doesn't contain the swift_initRawStructMetadata,
33043304 // emit a call to the swift_initStructMetadata tricking it into thinking
33053305 // we have a single field.
33063306 auto deploymentAvailability =
@@ -3310,6 +3310,39 @@ static void emitInitializeRawLayout(IRGenFunction &IGF, SILType likeType,
33103310 if (!IGF.IGM .Context .LangOpts .DisableAvailabilityChecking &&
33113311 !deploymentAvailability.isContainedIn (initRawAvail) &&
33123312 !IGF.IGM .getSwiftModule ()->isStdlibModule ()) {
3313+ emitInitializeRawLayoutOldOld (IGF, likeType, count, T, metadata, collector);
3314+ return ;
3315+ }
3316+
3317+ auto &IGM = IGF.IGM ;
3318+ auto likeTypeLayout = emitTypeLayoutRef (IGF, likeType, collector);
3319+ StructLayoutFlags flags = StructLayoutFlags::Swift5Algorithm;
3320+
3321+ // If we don't have a count, then we're the 'like:' variant and we need to
3322+ // pass '-1' to the runtime call.
3323+ if (!count) {
3324+ count = llvm::ConstantInt::get (IGF.IGM .Int32Ty , -1 );
3325+ }
3326+
3327+ // Call swift_initRawStructMetadata().
3328+ IGF.Builder .CreateCall (IGM.getInitRawStructMetadataFunctionPointer (),
3329+ {metadata, IGM.getSize (Size (uintptr_t (flags))),
3330+ likeTypeLayout, count});
3331+ }
3332+
3333+ static void emitInitializeRawLayout (IRGenFunction &IGF, SILType likeType,
3334+ llvm::Value *count, SILType T,
3335+ llvm::Value *metadata,
3336+ MetadataDependencyCollector *collector) {
3337+ // If our deployment target doesn't contain the swift_initRawStructMetadata2,
3338+ // emit a call to the older swift_initRawStructMetadata.
3339+ auto deploymentAvailability =
3340+ AvailabilityContext::forDeploymentTarget (IGF.IGM .Context );
3341+ auto initRaw2Avail = IGF.IGM .Context .getInitRawStructMetadata2Availability ();
3342+
3343+ if (!IGF.IGM .Context .LangOpts .DisableAvailabilityChecking &&
3344+ !deploymentAvailability.isContainedIn (initRaw2Avail) &&
3345+ !IGF.IGM .getSwiftModule ()->isStdlibModule ()) {
33133346 emitInitializeRawLayoutOld (IGF, likeType, count, T, metadata, collector);
33143347 return ;
33153348 }
@@ -3331,8 +3364,8 @@ static void emitInitializeRawLayout(IRGenFunction &IGF, SILType likeType,
33313364 rawLayoutFlags |= RawLayoutFlags::IsArray;
33323365 }
33333366
3334- // Call swift_initRawStructMetadata ().
3335- IGF.Builder .CreateCall (IGM.getInitRawStructMetadataFunctionPointer (),
3367+ // Call swift_initRawStructMetadata2 ().
3368+ IGF.Builder .CreateCall (IGM.getInitRawStructMetadata2FunctionPointer (),
33363369 {metadata,
33373370 IGM.getSize (Size (uintptr_t (structLayoutflags))),
33383371 likeTypeLayout,
0 commit comments