summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LowerSwitch.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-01 22:21:21 +0000
committerChris Lattner <sabre@nondot.org>2003-05-01 22:21:21 +0000
commit20af3222da5dea65246ecd9f64a53ea3e3cc1b8a (patch)
treee913696af43e8ef5d1facfaa953e610e50186518 /lib/Transforms/Utils/LowerSwitch.cpp
parent3d73c706e1dc8a80b11f1c66397eed5d47f225d9 (diff)
downloadllvm-20af3222da5dea65246ecd9f64a53ea3e3cc1b8a.tar.gz
llvm-20af3222da5dea65246ecd9f64a53ea3e3cc1b8a.tar.bz2
llvm-20af3222da5dea65246ecd9f64a53ea3e3cc1b8a.tar.xz
Fix Bug: LowerSwitch/2003-05-01-PHIProblem.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5979 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index a30a016c45..f71c08c3cf 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/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;
}