Skip to content

[RemoveDIs] Simplify spliceDebugInfo, fixing splice-to-end edge case #105670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,13 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
// Detach the marker at Dest -- this lets us move the "====" DbgRecords
// around.
DbgMarker *DestMarker = nullptr;
if (Dest != end()) {
if ((DestMarker = getMarker(Dest)))
if ((DestMarker = getMarker(Dest))) {
if (Dest == end()) {
assert(DestMarker == getTrailingDbgRecords());
deleteTrailingDbgRecords();
} else {
DestMarker->removeFromParent();
}
}

// If we're moving the tail range of DbgRecords (":::"), absorb them into the
Expand Down Expand Up @@ -1005,22 +1009,14 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
} else {
// Insert them right at the start of the range we moved, ahead of First
// and the "++++" DbgRecords.
// This also covers the rare circumstance where we insert at end(), and we
// did not generate the iterator with begin() / getFirstInsertionPt(),
// meaning any trailing debug-info at the end of the block would
// "normally" have been pushed in front of "First". We move it there now.
DbgMarker *FirstMarker = createMarker(First);
FirstMarker->absorbDebugValues(*DestMarker, true);
}
DestMarker->eraseFromParent();
} else if (Dest == end() && !InsertAtHead) {
// In the rare circumstance where we insert at end(), and we did not
// generate the iterator with begin() / getFirstInsertionPt(), it means
// any trailing debug-info at the end of the block would "normally" have
// been pushed in front of "First". Move it there now.
DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
if (TrailingDbgRecords) {
DbgMarker *FirstMarker = createMarker(First);
FirstMarker->absorbDebugValues(*TrailingDbgRecords, true);
TrailingDbgRecords->eraseFromParent();
deleteTrailingDbgRecords();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
Function *F = M->getFunction("func");

BasicBlock &BB = F->getEntryBlock();
auto I = std::prev(BB.end(), 2);
auto I = std::prev(BB.end(), 2); // store i32 2, ptr %1.
BB.splitBasicBlockBefore(I, "before");

BasicBlock &BBBefore = F->getEntryBlock();
auto I2 = std::prev(BBBefore.end(), 2);
auto I2 = std::prev(BBBefore.end()); // br label %1 (new).
ASSERT_TRUE(I2->hasDbgRecords());
}

Expand Down
Loading