Skip to content

Commit

Permalink
[AllocOpt] Track deleted instructions
Browse files Browse the repository at this point in the history
It was possible for the instruction contained in first_safepoint to
be delted, causing use-after-free problems later. Use a WeakVH
rather than a raw Instruction* to null-out the entry when the
Instruction gets deleted. In the future we may want to pay closer
attention to live ranges to avoid this problem entirely.

Fixes #30116

(cherry picked from commit 437d87c)
  • Loading branch information
Keno authored and KristofferC committed Dec 12, 2018
1 parent 23a30f0 commit 02096a0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ struct Optimizer {
CheckInst::Stack check_stack;
Lifetime::Stack lifetime_stack;
ReplaceUses::Stack replace_stack;
std::map<BasicBlock*,Instruction*> first_safepoint;
std::map<BasicBlock*, llvm::WeakVH> first_safepoint;
};

void Optimizer::pushInstruction(Instruction *I)
Expand Down Expand Up @@ -423,8 +423,11 @@ bool Optimizer::isSafepoint(Instruction *inst)
Instruction *Optimizer::getFirstSafepoint(BasicBlock *bb)
{
auto it = first_safepoint.find(bb);
if (it != first_safepoint.end())
return it->second;
if (it != first_safepoint.end()) {
Value *Val = it->second;
if (Val)
return cast<Instruction>(Val);
}
Instruction *first = nullptr;
for (auto &I: *bb) {
if (isSafepoint(&I)) {
Expand Down

0 comments on commit 02096a0

Please sign in to comment.