@@ -313,6 +313,7 @@ class IRGenSILFunction :
313
313
314
314
// / All alloc_ref instructions which allocate the object on the stack.
315
315
llvm::SmallPtrSet<SILInstruction *, 8 > StackAllocs;
316
+
316
317
// / With closure captures it is actually possible to have two function
317
318
// / arguments that both have the same name. Until this is fixed, we need to
318
319
// / also hash the ArgNo here.
@@ -759,8 +760,7 @@ class IRGenSILFunction :
759
760
760
761
void visitSILBasicBlock (SILBasicBlock *BB);
761
762
762
- void emitFunctionArgDebugInfo (SILBasicBlock *BB);
763
-
763
+ void emitErrorResultVar (SILResultInfo ErrorInfo, DebugValueInst *DbgValue);
764
764
void emitDebugInfoForAllocStack (AllocStackInst *i, const TypeInfo &type,
765
765
llvm::Value *addr);
766
766
void visitAllocStackInst (AllocStackInst *i);
@@ -1470,52 +1470,12 @@ void IRGenSILFunction::estimateStackSize() {
1470
1470
}
1471
1471
}
1472
1472
1473
- // / Determine the number of source-level Swift of a function or closure.
1474
- static unsigned countArgs (DeclContext *DC) {
1475
- unsigned N = 0 ;
1476
- if (auto *Fn = dyn_cast<AbstractFunctionDecl>(DC)) {
1477
- for (auto *PL : Fn->getParameterLists ())
1478
- N += PL->size ();
1479
-
1480
- } else if (auto *Closure = dyn_cast<AbstractClosureExpr>(DC))
1481
- N += Closure->getParameters ()->size ();
1482
- else
1483
- llvm_unreachable (" unhandled declcontext type" );
1484
- return N;
1485
- }
1486
-
1487
- void IRGenSILFunction::emitFunctionArgDebugInfo (SILBasicBlock *BB) {
1488
- // Emit the artificial error result argument.
1489
- auto FnTy = CurSILFn->getLoweredFunctionType ();
1490
- if (FnTy->hasErrorResult () && CurSILFn->getDeclContext ()) {
1491
- auto ErrorInfo = FnTy->getErrorResult ();
1492
- auto ErrorResultSlot = getErrorResultSlot (ErrorInfo.getSILType ());
1493
- DebugTypeInfo DTI (ErrorInfo.getType (),
1494
- ErrorResultSlot->getType (),
1495
- IGM.getPointerSize (),
1496
- IGM.getPointerAlignment (),
1497
- nullptr );
1498
- StringRef Name (" $error" );
1499
- // We just need any number that is guaranteed to be larger than every
1500
- // other argument. It is only used for sorting.
1501
- unsigned ArgNo =
1502
- countArgs (CurSILFn->getDeclContext ()) + 1 + BB->getBBArgs ().size ();
1503
- auto Storage = emitShadowCopy (ErrorResultSlot.getAddress (), getDebugScope (),
1504
- Name, ArgNo);
1505
- IGM.DebugInfo ->emitVariableDeclaration (
1506
- Builder, Storage, DTI, getDebugScope (), nullptr , Name, ArgNo,
1507
- IndirectValue, ArtificialValue);
1508
- }
1509
- }
1510
-
1511
-
1512
1473
void IRGenSILFunction::visitSILBasicBlock (SILBasicBlock *BB) {
1513
1474
// Insert into the lowered basic block.
1514
1475
llvm::BasicBlock *llBB = getLoweredBB (BB).bb ;
1515
1476
Builder.SetInsertPoint (llBB);
1516
1477
1517
1478
bool InEntryBlock = BB->pred_empty ();
1518
- bool ArgsEmitted = false ;
1519
1479
1520
1480
// Set this block as the dominance point. This implicitly communicates
1521
1481
// with the dominance resolver configured in emitSILFunction.
@@ -1585,22 +1545,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
1585
1545
// Use an artificial (line 0) location.
1586
1546
IGM.DebugInfo ->setCurrentLoc (Builder, DS);
1587
1547
1588
- // Function argument handling.
1589
- if (InEntryBlock && !ArgsEmitted) {
1590
- if (!I.getLoc ().isInPrologue () && I.getLoc ().getSourceLoc ().isValid ()) {
1591
- // This is the first non-prologue instruction in the entry
1592
- // block. The function prologue is where the stack frame is
1593
- // set up and storage for local variables and function
1594
- // arguments is initialized. We need to emit the debug info
1595
- // for the function arguments after the function prologue,
1596
- // after the initialization.
1597
- if (!DS)
1598
- DS = CurSILFn->getDebugScope ();
1599
- PrologueLocation AutoRestore (IGM.DebugInfo , Builder);
1600
- emitFunctionArgDebugInfo (BB);
1601
- ArgsEmitted = true ;
1602
- }
1603
- }
1604
1548
if (isa<TermInst>(&I))
1605
1549
emitDebugVariableRangeExtension (BB);
1606
1550
}
@@ -3188,13 +3132,35 @@ void IRGenSILFunction::visitStoreInst(swift::StoreInst *i) {
3188
3132
}
3189
3133
}
3190
3134
3135
+ // / Emit the artificial error result argument.
3136
+ void IRGenSILFunction::emitErrorResultVar (SILResultInfo ErrorInfo,
3137
+ DebugValueInst *DbgValue) {
3138
+ auto ErrorResultSlot = getErrorResultSlot (ErrorInfo.getSILType ());
3139
+ SILDebugVariable Var = DbgValue->getVarInfo ();
3140
+ auto Storage = emitShadowCopy (ErrorResultSlot.getAddress (), getDebugScope (),
3141
+ Var.Name , Var.ArgNo );
3142
+ DebugTypeInfo DTI (ErrorInfo.getType (), ErrorResultSlot->getType (),
3143
+ IGM.getPointerSize (), IGM.getPointerAlignment (), nullptr );
3144
+ IGM.DebugInfo ->emitVariableDeclaration (Builder, Storage, DTI, getDebugScope (),
3145
+ nullptr , Var.Name , Var.ArgNo ,
3146
+ IndirectValue, ArtificialValue);
3147
+ }
3148
+
3191
3149
void IRGenSILFunction::visitDebugValueInst (DebugValueInst *i) {
3192
3150
if (!IGM.DebugInfo )
3193
3151
return ;
3194
3152
3195
3153
auto SILVal = i->getOperand ();
3196
- if (isa<SILUndef>(SILVal))
3154
+ if (isa<SILUndef>(SILVal)) {
3155
+ // We cannot track the location of inlined error arguments because it has no
3156
+ // representation in SIL.
3157
+ if (!i->getDebugScope ()->InlinedCallSite &&
3158
+ i->getVarInfo ().Name == " $error" ) {
3159
+ auto funcTy = CurSILFn->getLoweredFunctionType ();
3160
+ emitErrorResultVar (funcTy->getErrorResult (), i);
3161
+ }
3197
3162
return ;
3163
+ }
3198
3164
3199
3165
StringRef Name = getVarName (i);
3200
3166
DebugTypeInfo DbgTy;
0 commit comments