Skip to content

Commit

Permalink
Fix state restore when recording __concat metamethod.
Browse files Browse the repository at this point in the history
Reported by Sergey Kaplun.

(cherry picked from commit eee16ef)

This commit is a follow-up to the previous one. It fixes the case when
the `topslot` is adjusting for simple concatenation results. This patch
adds the update of the corresponding Lua stack slots to be restored.

This fixes back the <lj-839-concat-recording.test.lua> test.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#11055
  • Loading branch information
Mike Pall authored and Buristan committed Mar 10, 2025
1 parent 9dbb7d4 commit 47c0d44
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lj_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ static TRef rec_tnew(jit_State *J, uint32_t ah)
/* -- Concatenation ------------------------------------------------------- */

typedef struct RecCatDataCP {
TValue savetv[5+LJ_FR2];
jit_State *J;
BCReg baseslot, topslot;
TRef tr;
Expand Down Expand Up @@ -1982,7 +1983,9 @@ static TValue *rec_mm_concat_cp(lua_State *L, lua_CFunction dummy, void *ud)
return NULL;
}
/* Pass partial result. */
topslot = J->maxslot--;
rcd->topslot = topslot = J->maxslot--;
/* Save updated range of slots. */
memcpy(rcd->savetv, &L->base[topslot-1], sizeof(rcd->savetv));
*xbase = tr;
top = xbase;
setstrV(J->L, &ix.keyv, &J2G(J)->strempty); /* Simulate string result. */
Expand All @@ -2002,16 +2005,18 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
{
lua_State *L = J->L;
ptrdiff_t delta = L->top - L->base;
TValue savetv[5+LJ_FR2], errobj;
TValue errobj;
RecCatDataCP rcd;
int errcode;
rcd.J = J;
rcd.baseslot = baseslot;
rcd.topslot = topslot;
memcpy(savetv, &L->base[topslot-1], sizeof(savetv)); /* Save slots. */
/* Save slots. */
memcpy(rcd.savetv, &L->base[topslot-1], sizeof(rcd.savetv));
errcode = lj_vm_cpcall(L, NULL, &rcd, rec_mm_concat_cp);
if (errcode) copyTV(L, &errobj, L->top-1);
memcpy(&L->base[topslot-1], savetv, sizeof(savetv)); /* Restore slots. */
/* Restore slots. */
memcpy(&L->base[rcd.topslot-1], rcd.savetv, sizeof(rcd.savetv));
if (errcode) {
L->top = L->base + delta;
copyTV(L, L->top++, &errobj);
Expand Down

0 comments on commit 47c0d44

Please sign in to comment.