diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-04-21 23:54:12 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-04-21 23:54:12 +0000 |
commit | 01d17e7c5f8c19b3e63ab3bf90ecf11b60175c5e (patch) | |
tree | 68ccffab7d15085ff6bf196b9bad0a0c9a9a3fc1 /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | 81503554986331c683163f436643a0f327da264f (diff) | |
download | bcm5719-llvm-01d17e7c5f8c19b3e63ab3bf90ecf11b60175c5e.tar.gz bcm5719-llvm-01d17e7c5f8c19b3e63ab3bf90ecf11b60175c5e.zip |
LowerSwitch: Fix producing invalid IR on unreachable code
If a switch was in an unreachable block that branched
to a block with a phi, it would leave phis with missing
predecessors.
llvm-svn: 301064
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index b375d51005d..8959e77438e 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -403,6 +403,14 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, Value *Val = SI->getCondition(); // The value we are switching on... BasicBlock* Default = SI->getDefaultDest(); + // Don't handle unreachable blocks. If there are successors with phis, this + // would leave them behind with missing predecessors. + if ((CurBlock != &F->getEntryBlock() && pred_empty(CurBlock)) || + CurBlock->getSinglePredecessor() == CurBlock) { + DeleteList.insert(CurBlock); + return; + } + // If there is only the default destination, just branch. if (!SI->getNumCases()) { BranchInst::Create(Default, CurBlock); |