diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-02 08:53:50 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-02 08:53:50 +0900 |
| commit | 9902ab50fcc397d8a6a7dffff35db1310c6b7fa5 (patch) | |
| tree | fdb0b5c4dc1925f9e634a5fdd545a4e56ea5342c /mrbgems/mruby-compiler/core/codegen.c | |
| parent | a9d721ea8fcb8c725e26a1ac0884ba3227ea5a08 (diff) | |
| download | mruby-9902ab50fcc397d8a6a7dffff35db1310c6b7fa5.tar.gz mruby-9902ab50fcc397d8a6a7dffff35db1310c6b7fa5.zip | |
codegen.c: fix a bug in bit shift constant folding.
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 9221cd91b..00cdc0059 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -798,6 +798,8 @@ gen_muldiv(codegen_scope *s, uint8_t op, uint16_t dst) } } +mrb_bool mrb_num_shift(mrb_state *mrb, mrb_int val, mrb_int width, mrb_int *num); + static mrb_bool gen_binop(codegen_scope *s, mrb_sym op, uint16_t dst) { @@ -814,24 +816,11 @@ gen_binop(codegen_scope *s, mrb_sym op, uint16_t dst) return FALSE; } if (op == MRB_OPSYM_2(s->mrb, lshift)) { - if (n < 0) { - if (-63 > n || -n >= sizeof(mrb_int)*8) return FALSE; - n = n0 >> (-n); - } - else { - if (n >= sizeof(mrb_int)*8-1) return FALSE; - n = n0 << n; - } + if (!mrb_num_shift(s->mrb, n0, n, &n)) return FALSE; } else if (op == MRB_OPSYM_2(s->mrb, rshift)) { - if (n < 0) { - if (-63 > n || -n > sizeof(mrb_int)*8-1) return FALSE; - n = n0 << (-n); - } - else { - if (n >= sizeof(mrb_int)*8-1) return FALSE; - n = n0 >> n; - } + if (n == MRB_INT_MIN) return FALSE; + if (!mrb_num_shift(s->mrb, n0, -n, &n)) return FALSE; } else if (op == MRB_OPSYM_2(s->mrb, mod)) { if (n0 < 0 || n < 0) return FALSE; |
