Fix anchoring for string buffer set() method (again).

Thanks to Peter Cawley. #1125
This commit is contained in:
Mike Pall 2023-12-10 19:42:22 +01:00
parent 8d5ea4ceb9
commit ff204d0350

View File

@ -1205,14 +1205,11 @@ static void LJ_FASTCALL recff_buffer_method_set(jit_State *J, RecordFFData *rd)
TRef trp = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0)); TRef trp = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0));
TRef len = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN); TRef len = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);
IRIns *irp = IR(tref_ref(trp)); IRIns *irp = IR(tref_ref(trp));
/* Anchor (potentially different) obj into which trp points after fold. */ /* trp must point into the anchored obj, even after folding. */
if (irp->o == IR_STRREF) { if (irp->o == IR_STRREF)
tr = irp->op1; tr = irp->op1;
} else if (irp->o == IR_KKPTR && !tref_isk(tr)) { else if (!tref_isk(tr))
GCstr *str = strV(&rd->argv[1]); /* Constify the argument. */ trp = emitir(IRT(IR_ADD, IRT_PGC), tr, lj_ir_kintpgc(J, sizeof(GCstr)));
tr = lj_ir_kstr(J, str);
trp = lj_ir_kkptr(J, (char *)strdata(str));
}
lj_ir_call(J, IRCALL_lj_bufx_set, trbuf, trp, len, tr); lj_ir_call(J, IRCALL_lj_bufx_set, trbuf, trp, len, tr);
#if LJ_HASFFI #if LJ_HASFFI
} else if (tref_iscdata(tr)) { } else if (tref_iscdata(tr)) {