summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2019-09-19 00:35:32 +0000
committerDavid Blaikie <dblaikie@gmail.com>2019-09-19 00:35:32 +0000
commitfa7f168a371200456b1dd237302597260c22f99e (patch)
tree09912eb8cad5b13e795cefca0c8a0f030e6a3208 /llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
parent4fd11c1e456ef36ce7c49c51c9daef6d0ffd8cbc (diff)
downloadbcm5719-llvm-fa7f168a371200456b1dd237302597260c22f99e.tar.gz
bcm5719-llvm-fa7f168a371200456b1dd237302597260c22f99e.zip
llvm-reduce: Avoid use-after-free when removing a branch instruction
Found my msan buildbot & pointed out by Nico Weber - thanks Nico! llvm-svn: 372280
Diffstat (limited to 'llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp')
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
index f05017984c9..f9e6b913614 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -36,6 +36,11 @@ static void replaceBranchTerminator(BasicBlock &BB,
if (ChunkSucessors.size() == Term->getNumSuccessors())
return;
+ bool IsBranch = isa<BranchInst>(Term);
+ Value *Address = nullptr;
+ if (auto IndBI = dyn_cast<IndirectBrInst>(Term))
+ Address = IndBI->getAddress();
+
Term->eraseFromParent();
if (ChunkSucessors.empty()) {
@@ -43,12 +48,12 @@ static void replaceBranchTerminator(BasicBlock &BB,
return;
}
- if (isa<BranchInst>(Term))
+ if (IsBranch)
BranchInst::Create(ChunkSucessors[0], &BB);
if (auto IndBI = dyn_cast<IndirectBrInst>(Term)) {
auto NewIndBI =
- IndirectBrInst::Create(IndBI->getAddress(), ChunkSucessors.size(), &BB);
+ IndirectBrInst::Create(Address, ChunkSucessors.size(), &BB);
for (auto Dest : ChunkSucessors)
NewIndBI->addDestination(Dest);
}
OpenPOWER on IntegriCloud