Skip to content

Commit

Permalink
[AArch64] fix an invalid-iterator-use bug.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanjoy committed Mar 2, 2015
1 parent 201a484 commit e5d1466
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ class AArch64PromoteConstant : public ModulePass {
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);
}
Expand Down

0 comments on commit e5d1466

Please sign in to comment.