diff options
| author | Mike Pall <mike> | 2025-12-06 08:35:19 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2025-12-06 08:35:19 +0100 |
| commit | 406cf69b3ae0a3ecd5ede2bb97b937b7a5d92074 (patch) | |
| tree | 142a45e38720606f34f7069123e48e2004474a82 | |
| parent | 34b59f8aa93ac55d3d3492e51d455e8a0ba0308f (diff) | |
| download | luajit-406cf69b3ae0a3ecd5ede2bb97b937b7a5d92074.tar.gz luajit-406cf69b3ae0a3ecd5ede2bb97b937b7a5d92074.tar.bz2 luajit-406cf69b3ae0a3ecd5ede2bb97b937b7a5d92074.zip | |
DUALNUM: Add missing type conversion for FORI slots.
Reported by Sergey Kaplun. #1413
| -rw-r--r-- | src/lj_record.c | 25 |
1 files changed, 17 insertions, 8 deletions
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) | |||
| 307 | mode + conv); | 307 | mode + conv); |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | /* Convert FORI argument to expected target type. */ | ||
| 311 | static TRef fori_conv(jit_State *J, TRef tr, IRType t) | ||
| 312 | { | ||
| 313 | if (t == IRT_INT) { | ||
| 314 | if (!tref_isinteger(tr)) | ||
| 315 | return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK); | ||
| 316 | } else { | ||
| 317 | if (!tref_isnum(tr)) | ||
| 318 | return emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT); | ||
| 319 | } | ||
| 320 | return tr; | ||
| 321 | } | ||
| 322 | |||
| 310 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ | 323 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ |
| 311 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, | 324 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, |
| 312 | IRType t, int mode) | 325 | IRType t, int mode) |
| 313 | { | 326 | { |
| 314 | TRef tr = J->base[slot]; | 327 | TRef tr = J->base[slot]; |
| 315 | if (!tr) { | 328 | if (tr) { |
| 329 | tr = fori_conv(J, tr, t); | ||
| 330 | } else { | ||
| 316 | tr = find_kinit(J, fori, slot, t); | 331 | tr = find_kinit(J, fori, slot, t); |
| 317 | if (!tr) | 332 | if (!tr) |
| 318 | tr = fori_load(J, slot, t, mode); | 333 | tr = fori_load(J, slot, t, mode); |
| @@ -458,13 +473,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) | |||
| 458 | lua_assert(tref_isnumber_str(tr[i])); | 473 | lua_assert(tref_isnumber_str(tr[i])); |
| 459 | if (tref_isstr(tr[i])) | 474 | if (tref_isstr(tr[i])) |
| 460 | tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); | 475 | tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); |
| 461 | if (t == IRT_INT) { | 476 | tr[i] = fori_conv(J, tr[i], t); |
| 462 | if (!tref_isinteger(tr[i])) | ||
| 463 | tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK); | ||
| 464 | } else { | ||
| 465 | if (!tref_isnum(tr[i])) | ||
| 466 | tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT); | ||
| 467 | } | ||
| 468 | } | 477 | } |
| 469 | tr[FORL_EXT] = tr[FORL_IDX]; | 478 | tr[FORL_EXT] = tr[FORL_IDX]; |
| 470 | stop = tr[FORL_STOP]; | 479 | stop = tr[FORL_STOP]; |
