From c981e151aeb4dbd46cb74c495f8292ad645f8e24 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 15 Apr 2023 20:52:43 +0900 Subject: [PATCH] Sign extension with `OP_LOADI32` in `get_int_operand()` Previously, the following code did not give the expected result. ``` % bin/mruby -e 'p "%08X" % ~(-1 << 16)' "..F0000FFFF" % ruby32 -e 'p "%08X" % ~(-1 << 24)' "00FFFFFF" ``` For information: this problem arises in the process of folding numbers through optimisation. --- mrbgems/mruby-compiler/core/codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 41e269e66..7315832ba 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -771,7 +771,7 @@ get_int_operand(codegen_scope *s, struct mrb_insn_data *data, mrb_int *n) return TRUE; case OP_LOADI32: - *n = (mrb_int)((uint32_t)data->b<<16)+data->c; + *n = (int32_t)((uint32_t)data->b<<16)+data->c; return TRUE; case OP_LOADL: