Skip to content

Commit 0a5d153

Browse files
Mike PallBuristan
authored andcommitted
Fix state restore when recording __concat metamethod.
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 for the problem Part of tarantool/tarantool#11055
1 parent 67021b7 commit 0a5d153

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/lj_record.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,7 @@ static TRef rec_tnew(jit_State *J, uint32_t ah)
19421942
/* -- Concatenation ------------------------------------------------------- */
19431943

19441944
typedef struct RecCatDataCP {
1945+
TValue savetv[5+LJ_FR2];
19451946
jit_State *J;
19461947
BCReg baseslot, topslot;
19471948
TRef tr;
@@ -1982,7 +1983,9 @@ static TValue *rec_mm_concat_cp(lua_State *L, lua_CFunction dummy, void *ud)
19821983
return NULL;
19831984
}
19841985
/* Pass partial result. */
1985-
topslot = J->maxslot--;
1986+
rcd->topslot = topslot = J->maxslot--;
1987+
/* Save updated range of slots. */
1988+
memcpy(rcd->savetv, &L->base[topslot-1], sizeof(rcd->savetv));
19861989
*xbase = tr;
19871990
top = xbase;
19881991
setstrV(J->L, &ix.keyv, &J2G(J)->strempty); /* Simulate string result. */
@@ -2002,16 +2005,18 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
20022005
{
20032006
lua_State *L = J->L;
20042007
ptrdiff_t delta = L->top - L->base;
2005-
TValue savetv[5+LJ_FR2], errobj;
2008+
TValue errobj;
20062009
RecCatDataCP rcd;
20072010
int errcode;
20082011
rcd.J = J;
20092012
rcd.baseslot = baseslot;
20102013
rcd.topslot = topslot;
2011-
memcpy(savetv, &L->base[topslot-1], sizeof(savetv)); /* Save slots. */
2014+
/* Save slots. */
2015+
memcpy(rcd.savetv, &L->base[topslot-1], sizeof(rcd.savetv));
20122016
errcode = lj_vm_cpcall(L, NULL, &rcd, rec_mm_concat_cp);
20132017
if (errcode) copyTV(L, &errobj, L->top-1);
2014-
memcpy(&L->base[topslot-1], savetv, sizeof(savetv)); /* Restore slots. */
2018+
/* Restore slots. */
2019+
memcpy(&L->base[rcd.topslot-1], rcd.savetv, sizeof(rcd.savetv));
20152020
if (errcode) {
20162021
L->top = L->base + delta;
20172022
copyTV(L, L->top++, &errobj);

0 commit comments

Comments
 (0)