diff options
author | Dale Johannesen <dalej@apple.com> | 2009-08-06 22:56:40 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2009-08-06 22:56:40 +0000 |
commit | 14e545d18e46187b0f02e7c705a3da3ad82225c2 (patch) | |
tree | e4957262172a65109fe1260c2efa236975acefa2 /lib/CodeGen/BranchFolding.cpp | |
parent | 76711246d9905575290fa7eebac4d1cad6000c60 (diff) |
Fix PR 4626, a crash in branch folding after OptimizeBlock
produced a CFG it wasn't prepared for.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78351 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 193bbb610f..d25152b1e4 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -893,8 +893,24 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { while (!MBB->pred_empty()) { MachineBasicBlock *Pred = *(MBB->pred_end()-1); Pred->ReplaceUsesOfBlockWith(MBB, FallThrough); + // If this resulted in a predecessor with true and false edges + // both going to the fallthrough block, clean up; + // BranchFolding doesn't like this. + MachineBasicBlock::succ_iterator SI = Pred->succ_begin(); + bool found = false; + while (SI != Pred->succ_end()) { + if (*SI == FallThrough) { + if (!found) { + found = true; + ++SI; + } else { + SI = Pred->removeSuccessor(SI); + } + } else { + ++SI; + } + } } - // If MBB was the target of a jump table, update jump tables to go to the // fallthrough instead. MBB->getParent()->getJumpTableInfo()-> |