Skip to content

Commit c6892c5

Browse files
committed
[SILCloner] Remap debug variable type and scope at the same time (NFC)
(cherry picked from commit 5512df5)
1 parent df5749b commit c6892c5

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -1412,14 +1412,12 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
14121412
return;
14131413

14141414
// Since we want the debug info to survive, we do not remap the location here.
1415-
SILDebugVariable VarInfo = *Inst->getVarInfo();
1415+
std::optional<SILDebugVariable> VarInfo = Inst->getVarInfo();
14161416
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1417-
if (VarInfo.Type)
1418-
VarInfo.Type = getOpType(*VarInfo.Type);
1417+
remapDebugVariable(VarInfo);
14191418
auto *NewInst = getBuilder().createDebugValue(
1420-
Inst->getLoc(), getOpValue(Inst->getOperand()), VarInfo,
1419+
Inst->getLoc(), getOpValue(Inst->getOperand()), *VarInfo,
14211420
Inst->poisonRefs(), Inst->usesMoveableValueDebugInfo(), Inst->hasTrace());
1422-
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
14231421
recordClonedInstruction(Inst, NewInst);
14241422
}
14251423
template<typename ImplClass>

0 commit comments

Comments
 (0)