Skip to content

Commit d8a8db2

Browse files
authored
[AllocOpt] fix iterator invalidation (#42059)
We might previously accidentally visit this use after deletion, if the orig_inst ended up back in the workqueue. Fixes #41916
1 parent b5b0684 commit d8a8db2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/llvm-alloc-opt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
11491149
{
11501150
auto tag = orig_inst->getArgOperand(2);
11511151
// `julia.typeof` is only legal on the original pointer, no need to scan recursively
1152+
size_t last_deleted = removed.size();
11521153
for (auto user: orig_inst->users()) {
11531154
if (auto call = dyn_cast<CallInst>(user)) {
11541155
auto callee = call->getCalledOperand();
@@ -1161,6 +1162,8 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
11611162
}
11621163
}
11631164
}
1165+
while (last_deleted < removed.size())
1166+
removed[last_deleted++]->replaceUsesOfWith(orig_inst, UndefValue::get(orig_inst->getType()));
11641167
}
11651168

11661169
void Optimizer::splitOnStack(CallInst *orig_inst)

0 commit comments

Comments
 (0)