Skip to content

Commit a4117e1

Browse files
committed
[DebugInfo] Salvage integer literals
1 parent 46909fc commit a4117e1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,25 @@ void swift::salvageDebugInfo(SILInstruction *I) {
19641964
}
19651965
}
19661966
}
1967+
1968+
if (auto *IL = dyn_cast<IntegerLiteralInst>(I)) {
1969+
APInt value = IL->getValue();
1970+
const SILDIExprElement ExprElements[2] = {
1971+
SILDIExprElement::createOperator(value.isNegative() ?
1972+
SILDIExprOperator::ConstSInt : SILDIExprOperator::ConstUInt),
1973+
SILDIExprElement::createConstInt(value.getLimitedValue()),
1974+
};
1975+
for (Operand *U : getDebugUses(IL)) {
1976+
auto *DbgInst = cast<DebugValueInst>(U->getUser());
1977+
auto VarInfo = DbgInst->getVarInfo();
1978+
if (!VarInfo)
1979+
continue;
1980+
VarInfo->DIExpr.prependElements(ExprElements);
1981+
// Create a new debug_value, with undef, and the correct const int
1982+
SILBuilder(DbgInst, DbgInst->getDebugScope())
1983+
.createDebugValue(DbgInst->getLoc(), SILUndef::get(IL), *VarInfo);
1984+
}
1985+
}
19671986
}
19681987

19691988
void swift::salvageLoadDebugInfo(LoadOperation load) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -O -g -emit-sil %s | %FileCheck %s
2+
3+
// In optimized code, a + b will be folded to 5, but we should still keep their
4+
// debug values.
5+
6+
// CHECK-LABEL: sil
7+
public func f() -> Int {
8+
let a = 2
9+
let b = 3
10+
// CHECK: debug_value undef : $Builtin.Int64, let, name "a", type $Int, expr op_constu:2:op_fragment:#Int._value
11+
// CHECK: debug_value undef : $Builtin.Int64, let, name "b", type $Int, expr op_constu:3:op_fragment:#Int._value
12+
return a + b
13+
}

0 commit comments

Comments
 (0)