@@ -313,6 +313,7 @@ class IRGenSILFunction :
313313
314314 // / All alloc_ref instructions which allocate the object on the stack.
315315 llvm::SmallPtrSet<SILInstruction *, 8 > StackAllocs;
316+
316317 // / With closure captures it is actually possible to have two function
317318 // / arguments that both have the same name. Until this is fixed, we need to
318319 // / also hash the ArgNo here.
@@ -759,8 +760,7 @@ class IRGenSILFunction :
759760
760761 void visitSILBasicBlock (SILBasicBlock *BB);
761762
762- void emitFunctionArgDebugInfo (SILBasicBlock *BB);
763-
763+ void emitErrorResultVar (SILResultInfo ErrorInfo, DebugValueInst *DbgValue);
764764 void emitDebugInfoForAllocStack (AllocStackInst *i, const TypeInfo &type,
765765 llvm::Value *addr);
766766 void visitAllocStackInst (AllocStackInst *i);
@@ -1470,52 +1470,12 @@ void IRGenSILFunction::estimateStackSize() {
14701470 }
14711471}
14721472
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-
15121473void IRGenSILFunction::visitSILBasicBlock (SILBasicBlock *BB) {
15131474 // Insert into the lowered basic block.
15141475 llvm::BasicBlock *llBB = getLoweredBB (BB).bb ;
15151476 Builder.SetInsertPoint (llBB);
15161477
15171478 bool InEntryBlock = BB->pred_empty ();
1518- bool ArgsEmitted = false ;
15191479
15201480 // Set this block as the dominance point. This implicitly communicates
15211481 // with the dominance resolver configured in emitSILFunction.
@@ -1585,22 +1545,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
15851545 // Use an artificial (line 0) location.
15861546 IGM.DebugInfo ->setCurrentLoc (Builder, DS);
15871547
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- }
16041548 if (isa<TermInst>(&I))
16051549 emitDebugVariableRangeExtension (BB);
16061550 }
@@ -3188,13 +3132,35 @@ void IRGenSILFunction::visitStoreInst(swift::StoreInst *i) {
31883132 }
31893133}
31903134
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+
31913149void IRGenSILFunction::visitDebugValueInst (DebugValueInst *i) {
31923150 if (!IGM.DebugInfo )
31933151 return ;
31943152
31953153 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+ }
31973162 return ;
3163+ }
31983164
31993165 StringRef Name = getVarName (i);
32003166 DebugTypeInfo DbgTy;
0 commit comments