Skip to content

Commit

Permalink
[AllocOpt] fix iterator invalidation
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
  • Loading branch information
vtjnash committed Aug 30, 2021
1 parent 915a212 commit 589f843
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,9 @@ 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
for (auto user: orig_inst->users()) {
size_t last_deleted = removed.size();
for (auto &use: orig_inst->uses()) {
auto user = use.getUser();
if (auto call = dyn_cast<CallInst>(user)) {
auto callee = call->getCalledOperand();
if (pass.typeof_func == callee) {
Expand All @@ -1161,6 +1163,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 589f843

Please sign in to comment.