Skip to content

Commit

Permalink
[AllocOpt] fix iterator invalidation (#42059)
Browse files Browse the repository at this point in the history
We might previously accidentally visit this use after deletion, if the
orig_inst ended up back in the workqueue.

Fixes #41916

(cherry picked from commit d8a8db2)
  • Loading branch information
vtjnash authored and KristofferC committed Sep 2, 2021
1 parent 0824c1b commit a8e6b33
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
{
auto tag = orig_inst->getArgOperand(2);
// `julia.typeof` is only legal on the original pointer, no need to scan recursively
size_t last_deleted = removed.size();
for (auto user: orig_inst->users()) {
if (auto call = dyn_cast<CallInst>(user)) {
auto callee = call->getCalledOperand();
Expand All @@ -1161,6 +1162,8 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
}
}
}
while (last_deleted < removed.size())
removed[last_deleted++]->replaceUsesOfWith(orig_inst, UndefValue::get(orig_inst->getType()));
}

void Optimizer::splitOnStack(CallInst *orig_inst)
Expand Down

0 comments on commit a8e6b33

Please sign in to comment.