Skip to content

Commit

Permalink
mruby-compiler/codegen.c: stop too aggressive optimization; fix #6210
Browse files Browse the repository at this point in the history
The old code assumes unary minus (`-@`) does not cause any side effect
(including errors). Considering the code like `-nil; nil`, the
assumption was too aggressive.
  • Loading branch information
matz committed Mar 19, 2024
1 parent 7404fab commit a810b9b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions mrbgems/mruby-compiler/core/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3366,19 +3366,14 @@ codegen(codegen_scope *s, node *tree, int val)
break;

default:
if (val) {
codegen(s, tree, VAL);
pop();
push_n(2);pop_n(2); /* space for receiver&block */
mrb_sym minus = MRB_OPSYM_2(s->mrb, minus);
if (!gen_uniop(s, minus, cursp())) {
genop_3(s, OP_SEND, cursp(), new_sym(s, minus), 0);
}
push();
}
else {
codegen(s, tree, NOVAL);
codegen(s, tree, VAL);
pop();
push_n(2);pop_n(2); /* space for receiver&block */
mrb_sym minus = MRB_OPSYM_2(s->mrb, minus);
if (!gen_uniop(s, minus, cursp())) {
genop_3(s, OP_SEND, cursp(), new_sym(s, minus), 0);
}
if (val) push();
break;
}
}
Expand Down

0 comments on commit a810b9b

Please sign in to comment.