summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorKyle Butt <kyle+llvm@iteratee.net>2016-10-27 21:37:20 +0000
committerKyle Butt <kyle+llvm@iteratee.net>2016-10-27 21:37:20 +0000
commitab9cca7b0c3af9c427ec83799570e77a056560bc (patch)
tree5178bd9b1c636aaf68bc9ed3630c1b2f08e760a3 /llvm/lib
parent44fa48f986beb1c6de1563eb903cdd18966e9ec9 (diff)
downloadbcm5719-llvm-ab9cca7b0c3af9c427ec83799570e77a056560bc.tar.gz
bcm5719-llvm-ab9cca7b0c3af9c427ec83799570e77a056560bc.zip
CodeGen: Handle missed case of block removal during BlockPlacement.
There is a use after free bug in the existing code. Loop layout selects a preferred exit block, and then lays out the loop. If this block is removed during layout, it needs to be invalidated to prevent a use after free. llvm-svn: 285348
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index aa440b2e1ca..b131bbcb3ae 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -282,6 +282,11 @@ class MachineBlockPlacement : public MachineFunctionPass {
/// \brief A handle to the loop info.
MachineLoopInfo *MLI;
+ /// \brief Preferred loop exit.
+ /// Member variable for convenience. It may be removed by duplication deep
+ /// in the call stack.
+ MachineBasicBlock *PreferredLoopExit;
+
/// \brief A handle to the target's instruction info.
const TargetInstrInfo *TII;
@@ -1474,9 +1479,9 @@ void MachineBlockPlacement::buildLoopChains(MachineLoop &L) {
// If we selected just the header for the loop top, look for a potentially
// profitable exit block in the event that rotating the loop can eliminate
// branches by placing an exit edge at the bottom.
- MachineBasicBlock *ExitingBB = nullptr;
+ PreferredLoopExit = nullptr;
if (!RotateLoopWithProfile && LoopTop == L.getHeader())
- ExitingBB = findBestLoopExit(L, LoopBlockSet);
+ PreferredLoopExit = findBestLoopExit(L, LoopBlockSet);
BlockChain &LoopChain = *BlockToChain[LoopTop];
@@ -1495,7 +1500,7 @@ void MachineBlockPlacement::buildLoopChains(MachineLoop &L) {
if (RotateLoopWithProfile)
rotateLoopWithProfile(LoopChain, L, LoopBlockSet);
else
- rotateLoop(LoopChain, ExitingBB, LoopBlockSet);
+ rotateLoop(LoopChain, PreferredLoopExit, LoopBlockSet);
DEBUG({
// Crash at the end so we get all of the debugging output first.
@@ -1928,8 +1933,9 @@ bool MachineBlockPlacement::maybeTailDuplicateBlock(
// Remove the block from loop info.
MLI->removeBlock(RemBB);
+ if (RemBB == PreferredLoopExit)
+ PreferredLoopExit = nullptr;
- // TailDuplicator handles removing it from loops.
DEBUG(dbgs() << "TailDuplicator deleted block: "
<< getBlockName(RemBB) << "\n");
};
OpenPOWER on IntegriCloud