From: Sanjoy Das Date: Mon, 2 Mar 2015 00:17:18 +0000 (+0000) Subject: [AArch64] fix an invalid-iterator-use bug. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e125c1adb7402c62966c0557b2fd7dc79559bb9;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230923 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AArch64/AArch64PromoteConstant.cpp b/lib/Target/AArch64/AArch64PromoteConstant.cpp index c037c86c152..4a4118ae775 100644 --- a/lib/Target/AArch64/AArch64PromoteConstant.cpp +++ b/lib/Target/AArch64/AArch64PromoteConstant.cpp @@ -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); }