@@ -1158,12 +1158,10 @@ class IRGenSILFunction :
1158
1158
}
1159
1159
1160
1160
emitTypeMetadataRef (archetype);
1161
- } else if (auto packArchetype = dyn_cast<PackArchetypeType>(t)) {
1162
- emitTypeMetadataRef (packArchetype);
1163
- } else if (auto packtype = dyn_cast<SILPackType>(t)) {
1161
+ } else if (auto packType = dyn_cast<SILPackType>(t)) {
1164
1162
llvm::Value *Shape = emitPackShapeExpression (t);
1165
1163
emitPackCountDebugVariable (Shape);
1166
- } else if (auto packtype = dyn_cast<PackType>(t)) {
1164
+ } else if (auto packType = dyn_cast<PackType>(t)) {
1167
1165
llvm::Value *Shape = emitPackShapeExpression (t);
1168
1166
emitPackCountDebugVariable (Shape);
1169
1167
}
@@ -1212,8 +1210,13 @@ class IRGenSILFunction :
1212
1210
SILResultInfo ErrorInfo,
1213
1211
DebugValueInst *DbgValue);
1214
1212
void emitPoisonDebugValueInst (DebugValueInst *i);
1215
- void emitDebugInfoForAllocStack (AllocStackInst *i, const TypeInfo &type,
1216
- llvm::Value *addr);
1213
+ void emitDebugInfoBeforeAllocStack (AllocStackInst *i,
1214
+ const TypeInfo &type,
1215
+ DebugTypeInfo &DbgTy);
1216
+ void emitDebugInfoAfterAllocStack (AllocStackInst *i,
1217
+ const TypeInfo &type,
1218
+ const DebugTypeInfo &DbgTy,
1219
+ llvm::Value *addr);
1217
1220
void visitAllocStackInst (AllocStackInst *i);
1218
1221
void visitAllocPackInst (AllocPackInst *i);
1219
1222
void visitAllocPackMetadataInst (AllocPackMetadataInst *i);
@@ -6401,14 +6404,52 @@ void IRGenSILFunction::visitDestroyNotEscapedClosureInst(
6401
6404
setLoweredExplosion (i, out);
6402
6405
}
6403
6406
6404
- void IRGenSILFunction::emitDebugInfoForAllocStack (AllocStackInst *i,
6405
- const TypeInfo &type,
6406
- llvm::Value *addr ) {
6407
+ void IRGenSILFunction::emitDebugInfoBeforeAllocStack (AllocStackInst *i,
6408
+ const TypeInfo &type,
6409
+ DebugTypeInfo &DbgTy ) {
6407
6410
auto VarInfo = i->getVarInfo ();
6408
- if (!VarInfo)
6411
+ if (!VarInfo ||
6412
+ !i->getDebugScope () ||
6413
+ i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
6414
+ return ;
6415
+
6416
+ VarDecl *Decl = i->getDecl ();
6417
+
6418
+ SILType SILTy;
6419
+ if (auto MaybeSILTy = VarInfo->Type ) {
6420
+ // If there is auxiliary type info, use it
6421
+ SILTy = *MaybeSILTy;
6422
+ } else {
6423
+ SILTy = i->getType ();
6424
+ }
6425
+ auto RealType = SILTy.getASTType ();
6426
+ if (Decl) {
6427
+ DbgTy = DebugTypeInfo::getLocalVariable (Decl, RealType, type, IGM);
6428
+ } else if (i->getFunction ()->isBare () && !SILTy.hasArchetype () &&
6429
+ !VarInfo->Name .empty ()) {
6430
+ DbgTy = DebugTypeInfo::getFromTypeInfo (RealType, getTypeInfo (SILTy), IGM);
6431
+ } else
6432
+ return ;
6433
+
6434
+ bindArchetypes (DbgTy.getType ());
6435
+ }
6436
+
6437
+ // / Do not instantiate type metadata in here, since this may allocate on-stack
6438
+ // / packs which will then be cleaned up in the wrong order with respect to the
6439
+ // / value stack allocation.
6440
+ void IRGenSILFunction::emitDebugInfoAfterAllocStack (AllocStackInst *i,
6441
+ const TypeInfo &type,
6442
+ const DebugTypeInfo &DbgTy,
6443
+ llvm::Value *addr) {
6444
+ auto VarInfo = i->getVarInfo ();
6445
+ if (!VarInfo ||
6446
+ !i->getDebugScope () ||
6447
+ i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
6409
6448
return ;
6410
6449
6411
6450
VarDecl *Decl = i->getDecl ();
6451
+ auto *DS = i->getDebugScope ();
6452
+
6412
6453
// Describe the underlying alloca. This way an llvm.dbg.declare intrinsic
6413
6454
// is used, which is valid for the entire lifetime of the alloca.
6414
6455
if (auto *BitCast = dyn_cast<llvm::BitCastInst>(addr)) {
@@ -6425,13 +6466,6 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
6425
6466
(void )isTaskAlloc;
6426
6467
}
6427
6468
}
6428
-
6429
- auto DS = i->getDebugScope ();
6430
- if (!DS)
6431
- return ;
6432
-
6433
- if (i->getDebugScope ()->getInlinedFunction ()->isTransparent ())
6434
- return ;
6435
6469
6436
6470
bool IsAnonymous = false ;
6437
6471
VarInfo->Name = getVarName (i, IsAnonymous);
@@ -6466,25 +6500,15 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
6466
6500
}
6467
6501
}
6468
6502
6469
- SILType SILTy;
6470
- if (auto MaybeSILTy = VarInfo->Type ) {
6471
- // If there is auxiliary type info, use it
6472
- SILTy = *MaybeSILTy;
6473
- } else {
6474
- SILTy = i->getType ();
6475
- }
6476
- auto RealType = SILTy.getASTType ();
6477
- DebugTypeInfo DbgTy;
6478
- if (Decl) {
6479
- DbgTy = DebugTypeInfo::getLocalVariable (Decl, RealType, type, IGM);
6480
- } else if (i->getFunction ()->isBare () && !SILTy.hasArchetype () &&
6481
- !VarInfo->Name .empty ()) {
6482
- DbgTy = DebugTypeInfo::getFromTypeInfo (RealType, getTypeInfo (SILTy), IGM);
6483
- } else
6484
- return ;
6503
+ if (DbgTy.getType () && IGM.DebugInfo ) {
6504
+ SILType SILTy;
6505
+ if (auto MaybeSILTy = VarInfo->Type ) {
6506
+ // If there is auxiliary type info, use it
6507
+ SILTy = *MaybeSILTy;
6508
+ } else {
6509
+ SILTy = i->getType ();
6510
+ }
6485
6511
6486
- bindArchetypes (DbgTy.getType ());
6487
- if (IGM.DebugInfo ) {
6488
6512
emitDebugVariableDeclaration (
6489
6513
addr, DbgTy, SILTy, DS, i->getLoc (), *VarInfo, Indirection,
6490
6514
AddrDbgInstrKind (i->usesMoveableValueDebugInfo ()));
@@ -6502,6 +6526,9 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
6502
6526
dbgname = getVarName (i, IsAnonymous);
6503
6527
# endif
6504
6528
6529
+ DebugTypeInfo DbgTy;
6530
+ emitDebugInfoBeforeAllocStack (i, type, DbgTy);
6531
+
6505
6532
auto stackAddr = type.allocateStack (*this , i->getElementType (), dbgname);
6506
6533
setLoweredStackAddress (i, stackAddr);
6507
6534
Address addr = stackAddr.getAddress ();
@@ -6516,7 +6543,7 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
6516
6543
Ty->getStructOrBoundGenericStruct ())
6517
6544
zeroInit (dyn_cast<llvm::AllocaInst>(addr.getAddress ()));
6518
6545
}
6519
- emitDebugInfoForAllocStack (i, type, addr.getAddress ());
6546
+ emitDebugInfoAfterAllocStack (i, type, DbgTy , addr.getAddress ());
6520
6547
}
6521
6548
6522
6549
void IRGenSILFunction::visitAllocPackInst (swift::AllocPackInst *i) {
0 commit comments