Skip to content

Commit 7c9676e

Browse files
committed
[DebugInfo] Fix var info after DeadObjectElimination
The scope of a store has to be the variable's scope. The type should be set to the element's type, and only if not already set. The variable's location should be set.
1 parent 95d2479 commit 7c9676e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,10 @@ void DeadObjectElimination::salvageDebugInfo(SILInstruction *toBeRemoved) {
854854
if (!varInfo)
855855
return;
856856

857-
SILBuilderWithScope Builder(SI);
857+
// Note: The instruction should logically be in SI's scope.
858+
// However, LLVM does not support variables and stores in different scopes,
859+
// so we use the variable's scope.
860+
SILBuilder Builder(SI, varInfo->Scope);
858861
Builder.createDebugValue(SI->getLoc(), SI->getSrc(), *varInfo);
859862
}
860863

@@ -866,7 +869,11 @@ DeadObjectElimination::buildDIExpression(SILInstruction *current) {
866869
auto var = dvci->getVarInfo();
867870
if (!var)
868871
return {};
869-
var->Type = dvci->getType();
872+
if (!var->Type)
873+
var->Type = dvci->getElementType();
874+
var->Loc = dvci->getVarLoc();
875+
if (!var->Scope)
876+
var->Scope = dvci->getDebugScope();
870877
return var;
871878
}
872879
if (auto *tupleAddr = dyn_cast<TupleElementAddrInst>(current)) {

0 commit comments

Comments
 (0)