@@ -338,14 +338,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
338338 registerLocalArchetypeRemapping (archetypeTy, replacementTy);
339339 }
340340
341- // SILCloner will take care of debug scope on the instruction
342- // and this helper will remap the auxiliary debug scope too, if there is any.
343- void remapDebugVarInfo (DebugVarCarryingInst DbgVarInst ) {
344- if (!DbgVarInst )
341+ // / SILCloner will take care of debug scope on the instruction
342+ // / and this helper will remap the auxiliary debug scope too, if there is any.
343+ void remapDebugVariable (std::optional<SILDebugVariable> &VarInfo ) {
344+ if (!VarInfo )
345345 return ;
346- auto VarInfo = DbgVarInst.getVarInfo ();
347- if (VarInfo && VarInfo->Scope )
348- DbgVarInst.setDebugVarScope (getOpScope (VarInfo->Scope ));
346+ if (VarInfo->Type )
347+ VarInfo->Type = getOpType (*VarInfo->Type );
348+ // Don't remap locations for debug values.
349+ if (VarInfo->Scope )
350+ VarInfo->Scope = getOpScope (VarInfo->Scope );
349351 }
350352
351353 ProtocolConformanceRef getOpConformance (Type ty,
@@ -879,8 +881,7 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
879881 Loc = MandatoryInlinedLocation::getAutoGeneratedLocation ();
880882 VarInfo = std::nullopt ;
881883 }
882- if (VarInfo && VarInfo->Type )
883- VarInfo->Type = getOpType (*VarInfo->Type );
884+ remapDebugVariable (VarInfo);
884885 auto *NewInst = getBuilder ().createAllocStack (
885886 Loc, getOpType (Inst->getElementType ()), VarInfo,
886887 Inst->hasDynamicLifetime (), Inst->isLexical (), Inst->isFromVarDecl (),
@@ -890,7 +891,6 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
890891 true
891892#endif
892893 );
893- remapDebugVarInfo (DebugVarCarryingInst (NewInst));
894894 recordClonedInstruction (Inst, NewInst);
895895}
896896
@@ -1428,14 +1428,12 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
14281428 return ;
14291429
14301430 // Since we want the debug info to survive, we do not remap the location here.
1431- SILDebugVariable VarInfo = * Inst->getVarInfo ();
1431+ std::optional< SILDebugVariable> VarInfo = Inst->getVarInfo ();
14321432 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1433- if (VarInfo.Type )
1434- VarInfo.Type = getOpType (*VarInfo.Type );
1433+ remapDebugVariable (VarInfo);
14351434 auto *NewInst = getBuilder ().createDebugValue (
1436- Inst->getLoc (), getOpValue (Inst->getOperand ()), VarInfo,
1435+ Inst->getLoc (), getOpValue (Inst->getOperand ()), * VarInfo,
14371436 Inst->poisonRefs (), Inst->usesMoveableValueDebugInfo (), Inst->hasTrace ());
1438- remapDebugVarInfo (DebugVarCarryingInst (NewInst));
14391437 recordClonedInstruction (Inst, NewInst);
14401438}
14411439template <typename ImplClass>
0 commit comments