summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-02-25 00:35:07 +0000
committerChris Lattner <sabre@nondot.org>2002-02-25 00:35:07 +0000
commite8e320d2faa997605c76a7c3ab9e9b4fb578e8c0 (patch)
treecae2a38eae967c7169411a073832e2f167826c9d /lib
parent664c953b39b5bc3c2e6cf3feb5bb4ea92355d886 (diff)
downloadllvm-e8e320d2faa997605c76a7c3ab9e9b4fb578e8c0.tar.gz
llvm-e8e320d2faa997605c76a7c3ab9e9b4fb578e8c0.tar.bz2
llvm-e8e320d2faa997605c76a7c3ab9e9b4fb578e8c0.tar.xz
Fix bug: test/Regression/Other/2002-02-24-InlineBrokePHINodes.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/BasicBlock.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 222bb14019..45ae72bc1e 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -155,5 +155,25 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I) {
// Add a branch instruction to the newly formed basic block.
InstList.push_back(new BranchInst(New));
+
+ // Now we must loop through all of the successors of the New block (which
+ // _were_ the successors of the 'this' block), and update any PHI nodes in
+ // successors. If there were PHI nodes in the successors, then they need to
+ // know that incoming branches will be from New, not from Old.
+ //
+ for (BasicBlock::succ_iterator I = succ_begin(New), E = succ_end(New);
+ I != E; ++I) {
+ // Loop over any phi nodes in the basic block, updating the BB field of
+ // incoming values...
+ BasicBlock *Successor = *I;
+ for (BasicBlock::iterator II = Successor->begin();
+ PHINode *PN = dyn_cast<PHINode>(*II); ++II) {
+ int IDX = PN->getBasicBlockIndex(this);
+ while (IDX != -1) {
+ PN->setIncomingBlock((unsigned)IDX, New);
+ IDX = PN->getBasicBlockIndex(this);
+ }
+ }
+ }
return New;
}