[llvm] [InferAddressSpaces] Safely delete duplicate dead instructions (PR #222115)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 14:47:04 PDT 2026
================
@@ -1661,8 +1661,12 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
}
}
- for (Instruction *I : DeadInstructions)
- RecursivelyDeleteTriviallyDeadInstructions(I);
+ // Deleting one instruction may recursively delete another queued
+ // instruction. Create handles before the first deletion so overlapping
+ // entries are nulled instead of leaving dangling pointers.
+ SmallVector<WeakTrackingVH> DeadInstructionHandles(DeadInstructions.begin(),
+ DeadInstructions.end());
+ RecursivelyDeleteTriviallyDeadInstructions(DeadInstructionHandles);
----------------
AlexMaclean wrote:
Nit: can we use to_vector_of<WeakTrackingVH, 16>(DeadInstructionHandles)?
https://github.com/llvm/llvm-project/pull/222115
More information about the llvm-commits
mailing list