Compare commits

..

1 Commits

Author SHA1 Message Date
David Mak e97ceb0da9 core: Fix restoration of loop target in try statement
old_loop_target is only assigned if ctx.loop_target is overwritten,
meaning that if ctx.loop_target is never overwritten, ctx.loop_target
will always be overwritten to None.

We fix this by only restoring from old_loop_target if we previously
assigned to old_loop_target.
2023-09-25 16:36:21 +08:00
1 changed files with 2 additions and 7 deletions

View File

@ -789,10 +789,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
ctx.outer_catch_clauses = old_clauses;
ctx.unwind_target = old_unwind;
ctx.return_target = old_return;
if let Some(old_loop_target) = old_loop_target {
ctx.loop_target.replace(old_loop_target);
}
old_loop_target = None;
ctx.loop_target = old_loop_target.or(ctx.loop_target).take();
let old_unwind = if !finalbody.is_empty() {
let final_landingpad = ctx.ctx.append_basic_block(current_fun, "try.catch.final");
@ -913,9 +910,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
}
ctx.unwind_target = old_unwind;
if let Some(old_loop_target) = old_loop_target {
ctx.loop_target.replace(old_loop_target);
}
ctx.loop_target = old_loop_target.or(ctx.loop_target).take();
ctx.return_target = old_return;
ctx.builder.position_at_end(landingpad);