summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-09-20 10:37:11 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-09-20 10:37:11 +0900
commit2083d99392ada4081c574abe6939d18685a2c917 (patch)
tree846ad13f1df4c3a2722bd1650150fc47dd8478f6 /mrbgems
parentf85c50543b4ec93f327b9b064ea193493b046766 (diff)
downloadmruby-2083d99392ada4081c574abe6939d18685a2c917.tar.gz
mruby-2083d99392ada4081c574abe6939d18685a2c917.zip
codegen.c: check `no_peephole(s)` before `mrb_last_insn(s)`.
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 380cd9317..9e2b1c5e2 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -653,10 +653,12 @@ gen_getupvar(codegen_scope *s, uint16_t dst, mrb_sym id)
int idx;
int lv = search_upvar(s, id, &idx);
- struct mrb_insn_data data = mrb_last_insn(s);
- if (!no_peephole(s) && data.insn == OP_SETUPVAR && data.a == dst && data.b == idx && data.c == lv) {
- /* skip GETUPVAR right after SETUPVAR */
- return;
+ if (!no_peephole(s)) {
+ struct mrb_insn_data data = mrb_last_insn(s);
+ if (data.insn == OP_SETUPVAR && data.a == dst && data.b == idx && data.c == lv) {
+ /* skip GETUPVAR right after SETUPVAR */
+ return;
+ }
}
genop_3(s, OP_GETUPVAR, dst, idx, lv);
}
@@ -667,10 +669,12 @@ gen_setupvar(codegen_scope *s, uint16_t dst, mrb_sym id)
int idx;
int lv = search_upvar(s, id, &idx);
- struct mrb_insn_data data = mrb_last_insn(s);
- if (!no_peephole(s) && data.insn == OP_MOVE && data.a == dst) {
- dst = data.b;
- rewind_pc(s);
+ if (!no_peephole(s)) {
+ struct mrb_insn_data data = mrb_last_insn(s);
+ if (data.insn == OP_MOVE && data.a == dst) {
+ dst = data.b;
+ rewind_pc(s);
+ }
}
genop_3(s, OP_SETUPVAR, dst, idx, lv);
}
@@ -1091,9 +1095,9 @@ static void
gen_setxv(codegen_scope *s, uint8_t op, uint16_t dst, mrb_sym sym, int val)
{
int idx = new_sym(s, sym);
- if (!val) {
+ if (!val && !no_peephole(s)) {
struct mrb_insn_data data = mrb_last_insn(s);
- if (!no_peephole(s) && data.insn == OP_MOVE && data.a == dst) {
+ if (data.insn == OP_MOVE && data.a == dst) {
dst = data.b;
rewind_pc(s);
}