diff options
author | David Blaikie <dblaikie@gmail.com> | 2019-09-19 00:35:32 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2019-09-19 00:35:32 +0000 |
commit | fa7f168a371200456b1dd237302597260c22f99e (patch) | |
tree | 09912eb8cad5b13e795cefca0c8a0f030e6a3208 /llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp | |
parent | 4fd11c1e456ef36ce7c49c51c9daef6d0ffd8cbc (diff) | |
download | bcm5719-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.cpp | 9 |
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); } |