Skip to content

Commit c4e764e

Browse files
authored
[RemoveDIs] Update ConvertDebugDeclareToDebugValue after #72276 (#73508)
That patch was missing a recent change to the non-DPValue StoreInst overload. Add it to the DPValue version. This is tested by `llvm/tests/Transforms/Mem2Reg/dbg_declare_to_value_conversions.ll`, which already has `--try-experimental-debuginfo-iterators`. It doesn't fail currently because until #74090 lands the declares are not converted to DPValues. The tests will become "live" once #74090 lands (see for more info).
1 parent f22a65c commit c4e764e

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,23 +1775,37 @@ void llvm::ConvertDebugDeclareToDebugValue(DPValue *DPV, StoreInst *SI,
17751775

17761776
DebugLoc NewLoc = getDebugValueLoc(DPV);
17771777

1778-
if (!valueCoversEntireFragment(DV->getType(), DPV)) {
1779-
// FIXME: If storing to a part of the variable described by the dbg.declare,
1780-
// then we want to insert a DPValue.value for the corresponding fragment.
1781-
LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to DPValue: " << *DPV
1782-
<< '\n');
1783-
// For now, when there is a store to parts of the variable (but we do not
1784-
// know which part) we insert an DPValue record to indicate that we know
1785-
// nothing about the variable's content.
1786-
DV = UndefValue::get(DV->getType());
1787-
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
1788-
DPValue *NewDPV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get());
1789-
SI->getParent()->insertDPValueBefore(NewDPV, SI->getIterator());
1778+
// If the alloca describes the variable itself, i.e. the expression in the
1779+
// dbg.declare doesn't start with a dereference, we can perform the
1780+
// conversion if the value covers the entire fragment of DII.
1781+
// If the alloca describes the *address* of DIVar, i.e. DIExpr is
1782+
// *just* a DW_OP_deref, we use DV as is for the dbg.value.
1783+
// We conservatively ignore other dereferences, because the following two are
1784+
// not equivalent:
1785+
// dbg.declare(alloca, ..., !Expr(deref, plus_uconstant, 2))
1786+
// dbg.value(DV, ..., !Expr(deref, plus_uconstant, 2))
1787+
// The former is adding 2 to the address of the variable, whereas the latter
1788+
// is adding 2 to the value of the variable. As such, we insist on just a
1789+
// deref expression.
1790+
bool CanConvert =
1791+
DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
1792+
valueCoversEntireFragment(DV->getType(), DPV));
1793+
if (CanConvert) {
1794+
insertDbgValueOrDPValue(Builder, DV, DIVar, DIExpr, NewLoc,
1795+
SI->getIterator());
17901796
return;
17911797
}
17921798

1799+
// FIXME: If storing to a part of the variable described by the dbg.declare,
1800+
// then we want to insert a dbg.value for the corresponding fragment.
1801+
LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DPV
1802+
<< '\n');
17931803
assert(UseNewDbgInfoFormat);
1794-
// Create a DPValue directly and insert.
1804+
1805+
// For now, when there is a store to parts of the variable (but we do not
1806+
// know which part) we insert an dbg.value intrinsic to indicate that we
1807+
// know nothing about the variable's content.
1808+
DV = UndefValue::get(DV->getType());
17951809
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
17961810
DPValue *NewDPV = new DPValue(DVAM, DIVar, DIExpr, NewLoc.get());
17971811
SI->getParent()->insertDPValueBefore(NewDPV, SI->getIterator());

0 commit comments

Comments
 (0)