@@ -1637,7 +1637,7 @@ void LoweredValue::getExplosion(IRGenFunction &IGF, SILType type,
16371637 case Kind::DynamicallyEnforcedAddress:
16381638 case Kind::CoroutineState:
16391639 llvm_unreachable (" not a value" );
1640-
1640+
16411641 case Kind::ExplosionVector:
16421642 ex.add (Storage.get <ExplosionVector>(kind));
16431643 return ;
@@ -4713,7 +4713,11 @@ static bool InCoroContext(SILFunction &f, SILInstruction &i) {
47134713}
47144714
47154715void IRGenSILFunction::visitDebugValueInst (DebugValueInst *i) {
4716+ auto SILVal = i->getOperand ();
4717+ bool IsAddrVal = SILVal->getType ().isAddress ();
47164718 if (i->poisonRefs ()) {
4719+ assert (!IsAddrVal &&
4720+ " SIL values with address type should not have poison" );
47174721 emitPoisonDebugValueInst (i);
47184722 return ;
47194723 }
@@ -4722,16 +4726,17 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
47224726
47234727 auto VarInfo = i->getVarInfo ();
47244728 assert (VarInfo && " debug_value without debug info" );
4725- auto SILVal = i->getOperand ();
47264729 if (isa<SILUndef>(SILVal)) {
47274730 // We cannot track the location of inlined error arguments because it has no
47284731 // representation in SIL.
4729- if (!i->getDebugScope ()->InlinedCallSite && VarInfo->Name == " $error" ) {
4732+ if (!IsAddrVal &&
4733+ !i->getDebugScope ()->InlinedCallSite && VarInfo->Name == " $error" ) {
47304734 auto funcTy = CurSILFn->getLoweredFunctionType ();
47314735 emitErrorResultVar (funcTy, funcTy->getErrorResult (), i);
47324736 }
47334737 return ;
47344738 }
4739+ bool IsInCoro = InCoroContext (*CurSILFn, *i);
47354740
47364741 bool IsAnonymous = false ;
47374742 VarInfo->Name = getVarName (i, IsAnonymous);
@@ -4742,27 +4747,50 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
47424747 SILTy = *MaybeSILTy;
47434748 else
47444749 SILTy = SILVal->getType ();
4750+
47454751 auto RealTy = SILTy.getASTType ();
4752+ if (IsAddrVal && IsInCoro)
4753+ if (auto *PBI = dyn_cast<ProjectBoxInst>(i->getOperand ())) {
4754+ // Usually debug info only ever describes the *result* of a projectBox
4755+ // call. To allow the debugger to display a boxed parameter of an async
4756+ // continuation object, however, the debug info can only describe the box
4757+ // itself and thus also needs to emit a box type for it so the debugger
4758+ // knows to call into Remote Mirrors to unbox the value.
4759+ RealTy = PBI->getOperand ()->getType ().getASTType ();
4760+ assert (isa<SILBoxType>(RealTy));
4761+ }
4762+
4763+ // Figure out the debug variable type
47464764 if (VarDecl *Decl = i->getDecl ()) {
47474765 DbgTy = DebugTypeInfo::getLocalVariable (
47484766 Decl, RealTy, getTypeInfo (SILVal->getType ()));
47494767 } else if (!SILTy.hasArchetype () && !VarInfo->Name .empty ()) {
4750- // Preliminary support for .sil debug information.
4768+ // Handle the cases that read from a SIL file
47514769 DbgTy = DebugTypeInfo::getFromTypeInfo (RealTy, getTypeInfo (SILTy));
47524770 } else
47534771 return ;
47544772
4773+ // Calculate the indirection
4774+ IndirectionKind Indirection = DirectValue;
4775+ if (IsInCoro)
4776+ Indirection = IsAddrVal ? CoroIndirectValue : CoroDirectValue;
4777+ else if (IsAddrVal && !isa<AllocStackInst>(SILVal))
4778+ Indirection = IndirectValue;
4779+
47554780 // Put the value into a stack slot at -Onone.
47564781 llvm::SmallVector<llvm::Value *, 8 > Copy;
4757- emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), *VarInfo, IsAnonymous,
4758- Copy);
4782+ if (IsAddrVal)
4783+ Copy.emplace_back (
4784+ emitShadowCopyIfNeeded (getLoweredAddress (SILVal).getAddress (),
4785+ i->getDebugScope (), *VarInfo, IsAnonymous));
4786+ else
4787+ emitShadowCopyIfNeeded (SILVal, i->getDebugScope (), *VarInfo, IsAnonymous,
4788+ Copy);
4789+
47594790 bindArchetypes (DbgTy.getType ());
47604791 if (!IGM.DebugInfo )
47614792 return ;
47624793
4763- IndirectionKind Indirection =
4764- InCoroContext (*CurSILFn, *i) ? CoroDirectValue : DirectValue;
4765-
47664794 emitDebugVariableDeclaration (Copy, DbgTy, SILTy, i->getDebugScope (),
47674795 i->getLoc (), *VarInfo, Indirection);
47684796}
0 commit comments