[llvm-commits] [llvm] r137175 - /llvm/trunk/lib/VMCore/BasicBlock.cpp
NAKAMURA Takumi
geek4civic at gmail.com
Tue Aug 9 16:13:05 PDT 2011
Author: chapuni
Date: Tue Aug 9 18:13:05 2011
New Revision: 137175
URL: http://llvm.org/viewvc/llvm-project?rev=137175&view=rev
Log:
VMCore/BasicBlock.cpp: Don't assume BasicBlock::iterator might end with a non-PHInode Instruction in successors.
Frontends(eg. clang) might pass incomplete form of IR, to step off the way beyond iterator end. In the case I had met, it took infinite loop due to meeting bogus PHInode.
Thanks to Jay Foad and John McCall.
Modified:
llvm/trunk/lib/VMCore/BasicBlock.cpp
Modified: llvm/trunk/lib/VMCore/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/BasicBlock.cpp?rev=137175&r1=137174&r2=137175&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/BasicBlock.cpp (original)
+++ llvm/trunk/lib/VMCore/BasicBlock.cpp Tue Aug 9 18:13:05 2011
@@ -336,8 +336,12 @@
return;
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
BasicBlock *Succ = TI->getSuccessor(i);
- for (iterator II = Succ->begin(); PHINode *PN = dyn_cast<PHINode>(II);
- ++II) {
+ // N.B. Succ might not be a complete BasicBlock, so don't assume
+ // that it ends with a non-phi instruction.
+ for (iterator II = Succ->begin(), IE = Succ->end(); II != IE; ++II) {
+ PHINode *PN = dyn_cast<PHINode>(II);
+ if (!PN)
+ break;
int i;
while ((i = PN->getBasicBlockIndex(this)) >= 0)
PN->setIncomingBlock(i, New);
More information about the llvm-commits
mailing list