Index: lib/IR/BasicBlock.cpp =================================================================== --- lib/IR/BasicBlock.cpp +++ lib/IR/BasicBlock.cpp @@ -399,8 +399,8 @@ // incoming values... BasicBlock *Successor = *I; PHINode *PN; - for (BasicBlock::iterator II = Successor->begin(); - (PN = dyn_cast(II)); ++II) { + for (BasicBlock::iterator II = Successor->begin(), E = Successor->end(); + II != E && (PN = dyn_cast(II)); ++II) { int IDX = PN->getBasicBlockIndex(this); while (IDX != -1) { PN->setIncomingBlock((unsigned)IDX, New);