diff options
| author | Chris Lattner <sabre@nondot.org> | 2003-05-01 22:21:21 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2003-05-01 22:21:21 +0000 |
| commit | df7cc91159499bbf7c4454c97b97ee87d6ac576f (patch) | |
| tree | 2350dfda5c169de4708618cc81a6631e476e9853 /llvm/lib/Transforms/Scalar | |
| parent | d4e24c66dfc96e3d98838ead0e039d7da1ead2e1 (diff) | |
| download | bcm5719-llvm-df7cc91159499bbf7c4454c97b97ee87d6ac576f.tar.gz bcm5719-llvm-df7cc91159499bbf7c4454c97b97ee87d6ac576f.zip | |
Fix Bug: LowerSwitch/2003-05-01-PHIProblem.ll
llvm-svn: 5979
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LowerSwitch.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LowerSwitch.cpp b/llvm/lib/Transforms/Scalar/LowerSwitch.cpp index a30a016c45b..f71c08c3cfd 100644 --- a/llvm/lib/Transforms/Scalar/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Scalar/LowerSwitch.cpp @@ -84,7 +84,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { Instruction *Br = new BranchInst(Succ, NextBlock, Comp); CurBlock->getInstList().push_back(Br); - // If there were any PHI nodes in this success, rewrite one entry from + // If there were any PHI nodes in this successor, rewrite one entry from // OrigBlock to come from CurBlock. for (BasicBlock::iterator I = Succ->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I) { @@ -93,10 +93,20 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { PN->setIncomingBlock((unsigned)BlockIdx, CurBlock); } + if (i == e-2) { // Is this looking at the default destination? + // If there is an entry in any PHI nodes for the default edge, make sure + // to update them as well. + for (BasicBlock::iterator I = NextBlock->begin(); + PHINode *PN = dyn_cast<PHINode>(I); ++I) { + int BlockIdx = PN->getBasicBlockIndex(OrigBlock); + assert(BlockIdx != -1 && "Switch didn't go to this successor??"); + PN->setIncomingBlock((unsigned)BlockIdx, CurBlock); + } + } + CurBlock = NextBlock; // Move on to the next condition } - // We are now done with the switch instruction, delete it. delete SI; } |

