diff options
| author | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-08-09 23:13:05 +0000 |
|---|---|---|
| committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-08-09 23:13:05 +0000 |
| commit | 4f041651ddab92f330d46bf164dc1048d5bf1c38 (patch) | |
| tree | a535f925b02488d67f154d71379bf25e0b3b8afd /llvm/lib | |
| parent | 5b64b8108880604c7a257fbd0f5ed913b7ff8b1c (diff) | |
| download | bcm5719-llvm-4f041651ddab92f330d46bf164dc1048d5bf1c38.tar.gz bcm5719-llvm-4f041651ddab92f330d46bf164dc1048d5bf1c38.zip | |
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.
llvm-svn: 137175
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/BasicBlock.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp index df6d1f4ce4d..5fab1d39ae8 100644 --- a/llvm/lib/VMCore/BasicBlock.cpp +++ b/llvm/lib/VMCore/BasicBlock.cpp @@ -336,8 +336,12 @@ void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) { 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); |

