[llvm] r372280 - llvm-reduce: Avoid use-after-free when removing a branch instruction
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 17:35:32 PDT 2019
Author: dblaikie
Date: Wed Sep 18 17:35:32 2019
New Revision: 372280
URL: http://llvm.org/viewvc/llvm-project?rev=372280&view=rev
Log:
llvm-reduce: Avoid use-after-free when removing a branch instruction
Found my msan buildbot & pointed out by Nico Weber - thanks Nico!
Modified:
llvm/trunk/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Modified: llvm/trunk/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp?rev=372280&r1=372279&r2=372280&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp (original)
+++ llvm/trunk/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp Wed Sep 18 17:35:32 2019
@@ -36,6 +36,11 @@ static void replaceBranchTerminator(Basi
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(Basi
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);
}
More information about the llvm-commits
mailing list