[llvm] r230923 - [AArch64] fix an invalid-iterator-use bug.

Sanjoy Das sanjoy at playingwithpointers.com
Sun Mar 1 16:17:18 PST 2015


Author: sanjoy
Date: Sun Mar  1 18:17:18 2015
New Revision: 230923

URL: http://llvm.org/viewvc/llvm-project?rev=230923&view=rev
Log:
[AArch64] fix an invalid-iterator-use bug.

Summary:
In AArch64PromoteConstant::appendAndTransferDominatedUses,
`InsertPts[NewPt]` invalidates IPI.  Therefore, `InsertPts[NewPt] =
std::move(IPI->second)` is not legal.

This was caught by running `make check` with
http://reviews.llvm.org/D7931.

Reviewers: t.p.northover, grosbach, bkramer

Reviewed By: bkramer

Subscribers: aemerson, llvm-commits

Differential Revision: http://reviews.llvm.org/D7988

Modified:
    llvm/trunk/lib/Target/AArch64/AArch64PromoteConstant.cpp

Modified: llvm/trunk/lib/Target/AArch64/AArch64PromoteConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64PromoteConstant.cpp?rev=230923&r1=230922&r2=230923&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64PromoteConstant.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64PromoteConstant.cpp Sun Mar  1 18:17:18 2015
@@ -189,9 +189,11 @@ private:
     IPI->second.push_back(&Use);
     // Transfer the dominated uses of IPI to NewPt
     // Inserting into the DenseMap may invalidate existing iterator.
-    // Keep a copy of the key to find the iterator to erase.
+    // Keep a copy of the key to find the iterator to erase.  Keep a copy of the
+    // value so that we don't have to dereference IPI->second.
     Instruction *OldInstr = IPI->first;
-    InsertPts[NewPt] = std::move(IPI->second);
+    Uses OldUses = std::move(IPI->second);
+    InsertPts[NewPt] = std::move(OldUses);
     // Erase IPI.
     InsertPts.erase(OldInstr);
   }





More information about the llvm-commits mailing list