Skip to content

Commit 100a6fc

Browse files
authored
Merge pull request #22993 from JuliaLang/jn/22973
codegen: fix use-after-free
2 parents 45a037b + d2f0b3c commit 100a6fc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/codegen.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -5694,10 +5694,15 @@ static std::unique_ptr<Module> emit_function(
56945694
}
56955695
}
56965696
if (!have_real_use) {
5697+
Instruction *use = NULL;
56975698
for (Use &U : root->uses()) {
5699+
if (use) // erase after the iterator moves on
5700+
use->eraseFromParent();
56985701
User *RU = U.getUser();
5699-
cast<Instruction>(RU)->eraseFromParent();
5702+
use = cast<Instruction>(RU);
57005703
}
5704+
if (use)
5705+
use->eraseFromParent();
57015706
root->eraseFromParent();
57025707
if (store_value)
57035708
store_value->eraseFromParent();

0 commit comments

Comments
 (0)