From: Mike Pall Date: Sat, 6 Dec 2025 07:35:19 +0000 (+0100) Subject: DUALNUM: Add missing type conversion for FORI slots. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=thirdparty%2FLuaJIT.git DUALNUM: Add missing type conversion for FORI slots. Reported by Sergey Kaplun. #1413 --- diff --git a/src/lj_record.c b/src/lj_record.c index 1d535a22..04a37925 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -307,12 +307,27 @@ static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode) mode + conv); } +/* Convert FORI argument to expected target type. */ +static TRef fori_conv(jit_State *J, TRef tr, IRType t) +{ + if (t == IRT_INT) { + if (!tref_isinteger(tr)) + return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK); + } else { + if (!tref_isnum(tr)) + return emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); + } + return tr; +} + /* Peek before FORI to find a const initializer. Otherwise load from slot. */ static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, IRType t, int mode) { TRef tr = J->base[slot]; - if (!tr) { + if (tr) { + tr = fori_conv(J, tr, t); + } else { tr = find_kinit(J, fori, slot, t); if (!tr) tr = fori_load(J, slot, t, mode); @@ -458,13 +473,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) lua_assert(tref_isnumber_str(tr[i])); if (tref_isstr(tr[i])) tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); - if (t == IRT_INT) { - if (!tref_isinteger(tr[i])) - tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK); - } else { - if (!tref_isnum(tr[i])) - tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT); - } + tr[i] = fori_conv(J, tr[i], t); } tr[FORL_EXT] = tr[FORL_IDX]; stop = tr[FORL_STOP];