summaryrefslogtreecommitdiff
path: root/lib/IR/Instruction.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-17 01:54:41 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-17 01:54:41 +0000
commit3b3dd8847fc759ea68aa756721689248cda98cc7 (patch)
tree9478586fd5dc070cec538282b7eae6da1cef56ad /lib/IR/Instruction.cpp
parentc49441293bdd5398aff3e01b653078af56c40ed2 (diff)
Scalar: Avoid dereferencing end() in IndVarSimplify
IndVarSimplify::sinkUnusedInvariants calls BasicBlock::getFirstInsertionPt on the ExitBlock and moves instructions before it. This can return end(), so it's not safe to dereference. Add an iterator-based overload to Instruction::moveBefore to avoid the UB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278886 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/Instruction.cpp')
-rw-r--r--lib/IR/Instruction.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp
index ed08f85c60b..cfddbf78f0c 100644
--- a/lib/IR/Instruction.cpp
+++ b/lib/IR/Instruction.cpp
@@ -92,8 +92,13 @@ void Instruction::insertAfter(Instruction *InsertPos) {
/// Unlink this instruction from its current basic block and insert it into the
/// basic block that MovePos lives in, right before MovePos.
void Instruction::moveBefore(Instruction *MovePos) {
- MovePos->getParent()->getInstList().splice(
- MovePos->getIterator(), getParent()->getInstList(), getIterator());
+ moveBefore(*MovePos->getParent(), MovePos->getIterator());
+}
+
+void Instruction::moveBefore(BasicBlock &BB,
+ SymbolTableList<Instruction>::iterator I) {
+ assert(I == BB.end() || I->getParent() == &BB);
+ BB.getInstList().splice(I, getParent()->getInstList(), getIterator());
}
void Instruction::setHasNoUnsignedWrap(bool b) {