1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

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
This commit is contained in:
David Blaikie 2019-09-19 00:35:32 +00:00
parent 7afab9f42f
commit 7867f03df9

View File

@ -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);
}