@@ -195,7 +195,8 @@ irgen::emitPackArchetypeMetadataRef(IRGenFunction &IGF,
195
195
196
196
static Address emitFixedSizeMetadataPackRef (IRGenFunction &IGF,
197
197
CanPackType packType,
198
- DynamicMetadataRequest request) {
198
+ DynamicMetadataRequest request,
199
+ llvm::ConstantInt *constantInt) {
199
200
assert (!packType->containsPackExpansionType ());
200
201
201
202
unsigned elementCount = packType->getNumElements ();
@@ -206,6 +207,10 @@ static Address emitFixedSizeMetadataPackRef(IRGenFunction &IGF,
206
207
IGF.Builder .CreateLifetimeStart (pack,
207
208
IGF.IGM .getPointerSize () * elementCount);
208
209
210
+ // Record this before making recursive calls to emitTypeMetadataRef(),
211
+ // to ensure we maintain correct stack discipline.
212
+ IGF.recordStackPackMetadataAlloc (pack, constantInt);
213
+
209
214
for (unsigned i : indices (packType->getElementTypes ())) {
210
215
Address slot = IGF.Builder .CreateStructGEP (
211
216
pack, i, IGF.IGM .getPointerSize ());
@@ -461,8 +466,8 @@ irgen::emitTypeMetadataPack(IRGenFunction &IGF, CanPackType packType,
461
466
if (auto *constantInt = dyn_cast<llvm::ConstantInt>(shape)) {
462
467
assert (packType->getNumElements () == constantInt->getValue ());
463
468
auto pack =
464
- StackAddress (emitFixedSizeMetadataPackRef (IGF, packType, request));
465
- IGF. recordStackPackMetadataAlloc (pack, constantInt);
469
+ StackAddress (emitFixedSizeMetadataPackRef (IGF, packType, request,
470
+ constantInt) );
466
471
return {pack, constantInt};
467
472
}
468
473
@@ -471,6 +476,10 @@ irgen::emitTypeMetadataPack(IRGenFunction &IGF, CanPackType packType,
471
476
IGF.IGM .getPointerAlignment (),
472
477
/* allowTaskAlloc=*/ true );
473
478
479
+ // Record this before making recursive calls to emitTypeMetadataRef(),
480
+ // to ensure we maintain correct stack discipline.
481
+ IGF.recordStackPackMetadataAlloc (pack, shape);
482
+
474
483
auto visitFn =
475
484
[&](CanType eltTy, unsigned staticIndex,
476
485
llvm::Value *dynamicIndex,
@@ -497,7 +506,6 @@ irgen::emitTypeMetadataPack(IRGenFunction &IGF, CanPackType packType,
497
506
};
498
507
499
508
visitPackExplosion (IGF, packType, visitFn);
500
- IGF.recordStackPackMetadataAlloc (pack, shape);
501
509
502
510
return {pack, shape};
503
511
}
@@ -537,7 +545,8 @@ irgen::emitTypeMetadataPackRef(IRGenFunction &IGF, CanPackType packType,
537
545
538
546
static Address emitFixedSizeWitnessTablePack (IRGenFunction &IGF,
539
547
CanPackType packType,
540
- PackConformance *packConformance) {
548
+ PackConformance *packConformance,
549
+ llvm::ConstantInt *constantInt) {
541
550
assert (!packType->containsPackExpansionType ());
542
551
543
552
unsigned elementCount = packType->getNumElements ();
@@ -548,6 +557,10 @@ static Address emitFixedSizeWitnessTablePack(IRGenFunction &IGF,
548
557
IGF.Builder .CreateLifetimeStart (pack,
549
558
IGF.IGM .getPointerSize () * elementCount);
550
559
560
+ // Record this before making recursive calls to emitTypeMetadataRef(),
561
+ // to ensure we maintain correct stack discipline.
562
+ IGF.recordStackPackWitnessTableAlloc (pack, constantInt);
563
+
551
564
for (unsigned i : indices (packType->getElementTypes ())) {
552
565
Address slot =
553
566
IGF.Builder .CreateStructGEP (pack, i, IGF.IGM .getPointerSize ());
@@ -607,8 +620,7 @@ irgen::emitWitnessTablePack(IRGenFunction &IGF, CanPackType packType,
607
620
if (auto *constantInt = dyn_cast<llvm::ConstantInt>(shape)) {
608
621
assert (packType->getNumElements () == constantInt->getValue ());
609
622
auto pack = StackAddress (
610
- emitFixedSizeWitnessTablePack (IGF, packType, packConformance));
611
- IGF.recordStackPackWitnessTableAlloc (pack, constantInt);
623
+ emitFixedSizeWitnessTablePack (IGF, packType, packConformance, constantInt));
612
624
return {pack, constantInt};
613
625
}
614
626
@@ -617,6 +629,10 @@ irgen::emitWitnessTablePack(IRGenFunction &IGF, CanPackType packType,
617
629
IGF.IGM .getPointerAlignment (),
618
630
/* allowTaskAlloc=*/ true );
619
631
632
+ // Record this before making recursive calls to emitTypeMetadataRef(),
633
+ // to ensure we maintain correct stack discipline.
634
+ IGF.recordStackPackWitnessTableAlloc (pack, shape);
635
+
620
636
auto index = 0 ;
621
637
auto visitFn = [&](CanType eltTy, unsigned staticIndex,
622
638
llvm::Value *dynamicIndex, llvm::Value *dynamicLength) {
@@ -645,7 +661,6 @@ irgen::emitWitnessTablePack(IRGenFunction &IGF, CanPackType packType,
645
661
};
646
662
647
663
visitPackExplosion (IGF, packType, visitFn);
648
- IGF.recordStackPackWitnessTableAlloc (pack, shape);
649
664
650
665
return {pack, shape};
651
666
}
@@ -1437,6 +1452,11 @@ irgen::emitInducedTupleTypeMetadataPack(
1437
1452
auto pack = IGF.emitDynamicAlloca (IGF.IGM .TypeMetadataPtrTy , shape,
1438
1453
IGF.IGM .getPointerAlignment (),
1439
1454
/* allowTaskAlloc=*/ true );
1455
+
1456
+ // Record this before making recursive calls to emitTypeMetadataRef(),
1457
+ // to ensure we maintain correct stack discipline.
1458
+ IGF.recordStackPackMetadataAlloc (pack, shape);
1459
+
1440
1460
auto elementForIndex =
1441
1461
[&](llvm::Value *index) -> llvm::Value * {
1442
1462
return irgen::emitTupleTypeMetadataElementType (IGF, tupleMetadata, index);
@@ -1446,8 +1466,6 @@ irgen::emitInducedTupleTypeMetadataPack(
1446
1466
emitPackExpansionPack (IGF, pack.getAddress (), index, shape,
1447
1467
elementForIndex);
1448
1468
1449
- IGF.recordStackPackMetadataAlloc (pack, shape);
1450
-
1451
1469
return {pack, shape};
1452
1470
}
1453
1471
0 commit comments