Skip to content

Commit b5084ab

Browse files
committed
Fix double-release of registers when compiling conditionals
Coercion already releases the source registers.
1 parent 6a7be00 commit b5084ab

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/vm/moar/QAST/QASTOperationsMAST.nqp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,14 @@ for <if unless with without> -> $op_name {
889889
$*MAST_FRAME.insert_bytecode($then-subbuffer, nqp::elems($*MAST_FRAME.bytecode));
890890

891891
if (!$is_void && @comp_ops[1].result_kind != $res_kind) {
892+
# coercion will automatically release @comp_ops[1].result_reg
892893
my $coercion := $qastcomp.coercion(@comp_ops[1], $res_kind);
893894
op_set($res_reg, $coercion.result_reg);
894895
}
895896
elsif !$is_void {
896897
op_set($res_reg, @comp_ops[1].result_reg);
898+
$regalloc.release_register(@comp_ops[1].result_reg, nqp::unbox_i(@comp_ops[1].result_kind));
897899
}
898-
$regalloc.release_register(@comp_ops[1].result_reg, @comp_ops[1].result_kind);
899900

900901
# Handle else branch (coercion of condition result if 2-arg).
901902
if $operands == 3 {
@@ -907,17 +908,21 @@ for <if unless with without> -> $op_name {
907908

908909
if !$is_void {
909910
if @comp_ops[2].result_kind != $res_kind {
911+
# coercion will automatically release @comp_ops[2].result_reg
910912
my $coercion := $qastcomp.coercion(@comp_ops[2], $res_kind);
911913
op_set($res_reg, $coercion.result_reg);
912914
}
913915
else {
914916
op_set($res_reg, @comp_ops[2].result_reg);
917+
$regalloc.release_register(@comp_ops[2].result_reg, nqp::unbox_i(@comp_ops[2].result_kind));
915918
}
916919
}
917-
$regalloc.release_register(@comp_ops[2].result_reg, @comp_ops[2].result_kind);
918920
}
919921

920-
$regalloc.release_register(@comp_ops[0].result_reg, @comp_ops[0].result_kind);
922+
unless $operands == 2 && !$is_void {
923+
# coercion will automatically release @comp_ops[0].result_reg
924+
$regalloc.release_register(@comp_ops[0].result_reg, nqp::unbox_i(@comp_ops[0].result_kind));
925+
}
921926

922927
$*MAST_FRAME.add-label($end_lbl);
923928

0 commit comments

Comments
 (0)