Skip to content

Commit

Permalink
[DebugInfo][RemoveDIs] Erase ranges of instructions individually (#81007
Browse files Browse the repository at this point in the history
)

The BasicBlock::erase method simply removes a range of instructions from
the instlist by unlinking them. However, now that we're attaching
debug-info directly to instructions, some cleanup is required, so use
eraseFromParent on each instruction instead.

This is less efficient, but rare, and seemingly only WASM EH Prepare
uses this method of BasicBlock. Detected via a memory leak check in
asan.

(asan is always the final boss for whatever I do).
  • Loading branch information
jmorse authored Feb 8, 2024
1 parent 8f2378d commit 1a42b38
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {

BasicBlock::iterator BasicBlock::erase(BasicBlock::iterator FromIt,
BasicBlock::iterator ToIt) {
return InstList.erase(FromIt, ToIt);
for (Instruction &I : make_early_inc_range(make_range(FromIt, ToIt)))
I.eraseFromParent();
return ToIt;
}

void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
Expand Down

0 comments on commit 1a42b38

Please sign in to comment.