Skip to content

Commit 5e641b9

Browse files
vtjnashKristofferC
authored andcommitted
[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 (cherry picked from commit d8a8db2)
1 parent d384d78 commit 5e641b9

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
@@ -1156,6 +1156,7 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
11561156
{
11571157
auto tag = orig_inst->getArgOperand(2);
11581158
// `julia.typeof` is only legal on the original pointer, no need to scan recursively
1159+
size_t last_deleted = removed.size();
11591160
for (auto user: orig_inst->users()) {
11601161
if (auto call = dyn_cast<CallInst>(user)) {
11611162
auto callee = call->getCalledOperand();
@@ -1168,6 +1169,8 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
11681169
}
11691170
}
11701171
}
1172+
while (last_deleted < removed.size())
1173+
removed[last_deleted++]->replaceUsesOfWith(orig_inst, UndefValue::get(orig_inst->getType()));
11711174
}
11721175

11731176
void Optimizer::splitOnStack(CallInst *orig_inst)

0 commit comments

Comments
 (0)