[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

llvm-svn: 230923
This commit is contained in:
Sanjoy Das 2015-03-02 00:17:18 +00:00
parent 201a48471b
commit e5d1466ab3
1 changed files with 4 additions and 2 deletions

View File

@ -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);
}