mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
py/compile: For dynamic compiler, widen literal 1 to get correct shift.
Without this patch, on 64-bit architectures the "1 << (small_int_bits - 1)" is computed using only 32-bit values (since small_int_bits is a uint8_t) and so will overflow (and give the wrong result) if small_int_bits is larger than 32.
This commit is contained in:
parent
86e0b25532
commit
cbec17f2cd
@ -2685,7 +2685,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
|||||||
} else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) {
|
} else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) {
|
||||||
mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn);
|
mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn);
|
||||||
#if MICROPY_DYNAMIC_COMPILER
|
#if MICROPY_DYNAMIC_COMPILER
|
||||||
mp_uint_t sign_mask = -(1 << (mp_dynamic_compiler.small_int_bits - 1));
|
mp_uint_t sign_mask = -((mp_uint_t)1 << (mp_dynamic_compiler.small_int_bits - 1));
|
||||||
if ((arg & sign_mask) == 0 || (arg & sign_mask) == sign_mask) {
|
if ((arg & sign_mask) == 0 || (arg & sign_mask) == sign_mask) {
|
||||||
// integer fits in target runtime's small-int
|
// integer fits in target runtime's small-int
|
||||||
EMIT_ARG(load_const_small_int, arg);
|
EMIT_ARG(load_const_small_int, arg);
|
||||||
|
Loading…
Reference in New Issue
Block a user