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 3, 2021
1 parent 2f74e1e commit 7559703
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 @@ -1156,6 +1156,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 @@ -1168,6 +1169,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 7559703

Please sign in to comment.