@@ -334,14 +334,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
334334 registerLocalArchetypeRemapping (archetypeTy, replacementTy);
335335 }
336336
337- // SILCloner will take care of debug scope on the instruction
338- // and this helper will remap the auxiliary debug scope too, if there is any.
339- void remapDebugVarInfo (DebugVarCarryingInst DbgVarInst ) {
340- if (!DbgVarInst )
337+ // / SILCloner will take care of debug scope on the instruction
338+ // / and this helper will remap the auxiliary debug scope too, if there is any.
339+ void remapDebugVariable (std::optional<SILDebugVariable> &VarInfo ) {
340+ if (!VarInfo )
341341 return ;
342- auto VarInfo = DbgVarInst.getVarInfo ();
343- if (VarInfo && VarInfo->Scope )
344- DbgVarInst.setDebugVarScope (getOpScope (VarInfo->Scope ));
342+ if (VarInfo->Type )
343+ VarInfo->Type = getOpType (*VarInfo->Type );
344+ // Don't remap locations for debug values.
345+ if (VarInfo->Scope )
346+ VarInfo->Scope = getOpScope (VarInfo->Scope );
345347 }
346348
347349 ProtocolConformanceRef getOpConformance (Type ty,
@@ -875,8 +877,7 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
875877 Loc = MandatoryInlinedLocation::getAutoGeneratedLocation ();
876878 VarInfo = std::nullopt ;
877879 }
878- if (VarInfo && VarInfo->Type )
879- VarInfo->Type = getOpType (*VarInfo->Type );
880+ remapDebugVariable (VarInfo);
880881 auto *NewInst = getBuilder ().createAllocStack (
881882 Loc, getOpType (Inst->getElementType ()), VarInfo,
882883 Inst->hasDynamicLifetime (), Inst->isLexical (), Inst->isFromVarDecl (),
@@ -886,7 +887,6 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
886887 true
887888#endif
888889 );
889- remapDebugVarInfo (DebugVarCarryingInst (NewInst));
890890 recordClonedInstruction (Inst, NewInst);
891891}
892892
@@ -1409,14 +1409,12 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
14091409 return ;
14101410
14111411 // Since we want the debug info to survive, we do not remap the location here.
1412- SILDebugVariable VarInfo = * Inst->getVarInfo ();
1412+ std::optional< SILDebugVariable> VarInfo = Inst->getVarInfo ();
14131413 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1414- if (VarInfo.Type )
1415- VarInfo.Type = getOpType (*VarInfo.Type );
1414+ remapDebugVariable (VarInfo);
14161415 auto *NewInst = getBuilder ().createDebugValue (
1417- Inst->getLoc (), getOpValue (Inst->getOperand ()), VarInfo,
1416+ Inst->getLoc (), getOpValue (Inst->getOperand ()), * VarInfo,
14181417 Inst->poisonRefs (), Inst->usesMoveableValueDebugInfo (), Inst->hasTrace ());
1419- remapDebugVarInfo (DebugVarCarryingInst (NewInst));
14201418 recordClonedInstruction (Inst, NewInst);
14211419}
14221420template <typename ImplClass>
0 commit comments