From 4de13f6a1ae9e83527cf1bc20dd8fb8fc3308563 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 14 Nov 2014 00:34:59 +0000 Subject: [PATCH] CodeGen: assert an instruction is being inserted with the correct iterator. When "MBB->Insert(It, ...)" is called, we want It to be pointing inside the correct basic block. No actual failures at the moment, but it's caused problems before. llvm-svn: 221953 --- include/llvm/CodeGen/MachineBasicBlock.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index a08cc2eb508..1440b967aea 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -486,11 +486,15 @@ public: /// Insert a range of instructions into the instruction list before I. template void insert(iterator I, IT S, IT E) { + assert((I == end() || I->getParent() == this) && + "iterator points outside of basic block"); Insts.insert(I.getInstrIterator(), S, E); } /// Insert MI into the instruction list before I. iterator insert(iterator I, MachineInstr *MI) { + assert((I == end() || I->getParent() == this) && + "iterator points outside of basic block"); assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && "Cannot insert instruction with bundle flags"); return Insts.insert(I.getInstrIterator(), MI); @@ -498,6 +502,8 @@ public: /// Insert MI into the instruction list after I. iterator insertAfter(iterator I, MachineInstr *MI) { + assert((I == end() || I->getParent() == this) && + "iterator points outside of basic block"); assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && "Cannot insert instruction with bundle flags"); return Insts.insertAfter(I.getInstrIterator(), MI);