[clang] [llvm] [NFC] Implicit container copy cleanup (PR #174702)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 7 01:18:06 PST 2026


================
@@ -1089,10 +1089,10 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
       }
       LLVM_DEBUG(dbgs() << "V2S copy " << *C.Copy
                         << " is being turned to VALU\n");
+      Copies.insert(C.Copy);
       // TODO: MapVector::erase is inefficient. Do bulk removal with remove_if
       // instead.
       V2SCopies.erase(C.ID);
-      Copies.insert(C.Copy);
----------------
sfu2 wrote:

`C.Copy` is valid if `CurInfoIt` valid, which is then fetched from `V2SCopies`. By reordering`Copies.insert(C.Copy)` we can ensure that our reference `C` will not become dangling after `V2SCopies.erase(C.ID)`.

https://github.com/llvm/llvm-project/pull/174702


More information about the cfe-commits mailing list