From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 33ABC5C4041; Mon, 11 Mar 2024 15:34:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 33ABC5C4041 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1710160455; bh=JWZTa+q9Q8PmQdSgczS1iF1iJdra8ZryuvDdYuKJ2Ww=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WRSug3cdXu0oF6dNgBY9GqKEPxKItjU8p+xdL1PlEQJrVC6aUyXHLWvs+sYSZ3GZG t/ypLNOPlxULxike1TYFeHvGZdKYgJ8HfYzdb4QorfdY6UGvQ2ntLgL+SJIdVMI9Bt fCGZpqmDf7x5J0iPNoDzcu9COT8+7BnuJzAC6FNo= Received: from smtp16.i.mail.ru (smtp16.i.mail.ru [95.163.41.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 035775C4041 for ; Mon, 11 Mar 2024 15:34:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 035775C4041 Received: by smtp16.i.mail.ru with esmtpa (envelope-from ) id 1rjer7-00000008wqd-0WzD; Mon, 11 Mar 2024 15:34:13 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 11 Mar 2024 15:30:07 +0300 Message-ID: <20240311123007.25384-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD987C0EE6E7F0A597D8D64E6F18B2E2E3258EF6A9BB0633F3C182A05F53808504049CA56FC56079896C7A4B249DE6549FDF7BEED09D8C4130583A1D6A8ABB318072F60CAED319836FF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7408FFE705ACEE2A7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377D46B81CF91B0E148638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F8A5FEF961B89A285BB6AA7B72A6EFCC047E34E0B97E1DC6CC7F00164DA146DAFE8445B8C89999728AA50765F7900637028599BB38096F4F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC821E93C0F2A571C7BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CB28C6475D0D323309735652A29929C6C4AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C38FC461068341CE01BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF17B107DEF921CE791DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C39D7D3120FB43BDE335872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A587B74EA7C9F582F85002B1117B3ED6965D9E5855C5C4FE213E67C18142C611B7823CB91A9FED034534781492E4B8EEAD3BF9A24AEF94352CC79554A2A72441328621D336A7BC284946AD531847A6065AED8438A78DFE0A9EBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFA9599B7F7CB7124F47BA80EF56B2555B1C9AF40F90C73A67A2D83FEC1B6B256A248F49047001ACAA748ED927723DE83F6CEE3CC9DB70C04A7CD22F28E18D92120FC9BB0E6FF739B5C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojT+KSurEfQae0WFRQiIDFiA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7692E2E1D66E248A965C7A4B249DE6549FDF7BEED09D8C41305B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] Fix recording of __concat metamethod. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Thanks to Sergey Kaplun. (cherry picked from commit bcc5125a9188179d23c223b8865ed94951fb91b3) `lj_record_ret()` uses `J->L->base` as a base for recording concatenation with remaining operands, even if there is a vararg frame or pcall frame (so it uses the wrong Lua stack slots from a frame above). This leads to the corresponding assertion failure in the `lj_record_mm_lookup()`. This patch adds the calculation of the base adjusment necessary for correct frame usage. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#9595 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1164-record-meta-concat-varg-pcall Tarantool PR: https://github.com/tarantool/tarantool/pull/9788 Related issues: * https://github.com/tarantool/tarantool/issues/9595 * https://github.com/LuaJIT/LuaJIT/issues/1164 src/lj_record.c | 8 ++- ...164-record-meta-concat-varg-pcall.test.lua | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/tarantool-tests/lj-1164-record-meta-concat-varg-pcall.test.lua diff --git a/src/lj_record.c b/src/lj_record.c index c01c1f0b..77818fec 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -819,6 +819,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) { TValue *frame = J->L->base - 1; ptrdiff_t i; + BCReg baseadj = 0; for (i = 0; i < gotresults; i++) (void)getslot(J, rbase+i); /* Ensure all results have a reference. */ while (frame_ispcall(frame)) { /* Immediately resolve pcall() returns. */ @@ -827,6 +828,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) lj_trace_err(J, LJ_TRERR_NYIRETL); lj_assertJ(J->baseslot > 1+LJ_FR2, "bad baseslot for return"); gotresults++; + baseadj += cbase; rbase += cbase; J->baseslot -= (BCReg)cbase; J->base -= cbase; @@ -851,6 +853,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */ lj_trace_err(J, LJ_TRERR_NYIRETL); lj_assertJ(J->baseslot > 1+LJ_FR2, "bad baseslot for return"); + baseadj += cbase; rbase += cbase; J->baseslot -= (BCReg)cbase; J->base -= cbase; @@ -918,7 +921,8 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) BCReg bslot = bc_b(*(frame_contpc(frame)-1)); TRef tr = gotresults ? J->base[cbase+rbase] : TREF_NIL; if (bslot != J->maxslot) { /* Concatenate the remainder. */ - TValue *b = J->L->base, save; /* Simulate lower frame and result. */ + /* Simulate lower frame and result. */ + TValue *b = J->L->base - baseadj, save; /* Can't handle MM_concat + CALLT + fast func side-effects. */ if (J->postproc != LJ_POST_NONE) lj_trace_err(J, LJ_TRERR_NYIRETL); @@ -931,7 +935,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) J->L->base = b - cbase; tr = rec_cat(J, bslot, cbase-(2<L->base + cbase; /* Undo. */ - J->L->base = b; + J->L->base = b + baseadj; copyTV(J->L, b-(2<