[llvm] 1a42b38 - [DebugInfo][RemoveDIs] Erase ranges of instructions individually (#81007)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 02:27:40 PST 2024


Author: Jeremy Morse
Date: 2024-02-08T10:27:34Z
New Revision: 1a42b3804f0ed1c4958c4f17216543a1623e3452

URL: https://github.com/llvm/llvm-project/commit/1a42b3804f0ed1c4958c4f17216543a1623e3452
DIFF: https://github.com/llvm/llvm-project/commit/1a42b3804f0ed1c4958c4f17216543a1623e3452.diff

LOG: [DebugInfo][RemoveDIs] Erase ranges of instructions individually (#81007)

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).

Added: 
    

Modified: 
    llvm/lib/IR/BasicBlock.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index bb55f48df4b314..fe9d0d08c5fe97 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -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) {


        


More information about the llvm-commits mailing list