Fix edge cases when generating IR for string.byte/sub/find.

Contributed by XmiliaH. #1407
This commit is contained in:
Mike Pall
2025-11-14 20:15:44 +01:00
parent c94312d348
commit af9763a50d

View File

@@ -697,7 +697,7 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
emitir(IRTGI(IR_EQ), trstart, tr0);
trstart = tr0;
} else {
trstart = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1));
trstart = emitir(IRTGI(IR_ADDOV), trstart, lj_ir_kint(J, -1));
emitir(IRTGI(IR_GE), trstart, tr0);
start--;
}
@@ -705,7 +705,7 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
if (rd->data) { /* Return string.sub result. */
if (end - start >= 0) {
/* Also handle empty range here, to avoid extra traces. */
TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart);
TRef trptr, trslen = emitir(IRTGI(IR_SUBOV), trend, trstart);
emitir(IRTGI(IR_GE), trslen, tr0);
trptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart);
J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen);
@@ -716,7 +716,7 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
} else { /* Return string.byte result(s). */
ptrdiff_t i, len = end - start;
if (len > 0) {
TRef trslen = emitir(IRTI(IR_SUB), trend, trstart);
TRef trslen = emitir(IRTGI(IR_SUBOV), trend, trstart);
emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len));
if (J->baseslot + len > LJ_MAX_JSLOTS)
lj_trace_err_info(J, LJ_TRERR_STACKOV);