Skip to content

Commit

Permalink
[AllocOpt] fix iterator invalidation (JuliaLang#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 JuliaLang#41916
  • Loading branch information
vtjnash authored and LilithHafner committed Feb 22, 2022
1 parent a8ee1e4 commit 5b30ad3
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 5b30ad3

Please sign in to comment.