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 206D66E0FD; Tue, 24 Nov 2026 19:39:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 206D66E0FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795538344; bh=ndvqMlDSaQK9ymHbYhKFDHsvxbzxjuYpNx9kaEMS0HM=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Jhs4DbCNa5/rxe2a7cYSX2nZLj77KEp7rJq22t0fO45/jK9H7YKMoklqxgh2yNQTm KUZzCfBDu3n8Tc/vwXxDJE58EAklOVzlCGR1dWHeXKUyXGIy1Sf2m6oso1Q01JYlde V/3Ua4h4vRf70HX0fFAS1B4t4I4WVfBeMi/XzknE= Received: from send279.i.mail.ru (send279.i.mail.ru [95.163.59.118]) (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 E3EBF6E0FD for ; Tue, 24 Nov 2026 19:39:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E3EBF6E0FD Received: by exim-smtp-56bb8ff957-qctst with esmtpa (envelope-from ) id 1xVtXp-00000000MGF-38iy; Tue, 24 Nov 2026 19:39:02 +0300 Message-ID: Date: Tue, 24 Nov 2026 19:39:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun References: <20261124155125.1713061-1-skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <20261124155125.1713061-1-skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD977B76FDA87AFA8B9B22819EEF13868C596FBFE8158AD8C0A182A05F5380850407C82AE1E71465C113DE06ABAFEAF6705253B6A19827341C988C312F6E1E3F1C87FF062E1587DD9E3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70B8ADF238913687CB287FD4696A6DC2FA8DF7F3B2552694A4E2F5AFA99E116B42401471946AA11AFA417C69337E82CC2BCF491FFA38154B6B5C8C57E37DE458B543C44CD4AFD0029C6CDE5D1141D2B1C036E9F792DA9C46B80572D8EAAB3C7141EF3EFD7D2F6F89C454A5B3D5E8F34AA8941B15DA834481F8AA50765F7900637F3E38EE449E3E2AE389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998E0A6AB1C7CE11FEE35E3BF8C76DC23F74BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE75AB67F7B7331F814731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A586D6CFA918D6B5665002B1117B3ED69628A750FB533BEC33715D9AB585B0EB04823CB91A9FED034534781492E4B8EEADA79578C5CF9A9009BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659D30E9E3A6E1229FD324563B8E5E01509C8E2E33FE5E9ADED5B72EE6359C6C0734FC8690A69EEE0EFB8341EE9D5BE9A0A121D17FBBA968302DE74E7DF68D97F997A37DB637D16B971C7CEAA0681F5848F4C41F94D744909CEEF9E35A692215F79327F81E6EEE0AEB67A0F9F91F029B6AF33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWINzZLnZxDcnDLEd9SnCO68= X-Mailru-Sender: 015BA6FC0EFA223AFF5DE35D6D355F4395903FF2461B4871D4570605F44DF53705A9E359239577268A22182D06F00E568C34D365DA2E1307B60569B44082A3A3197AF8DA6C69D34BA7BD66BEAC8CCB0C4198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] FFI: Adjust J->maxslot after ffi.offsetof. 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: Evgeniy Temirgaleev via Tarantool-patches Reply-To: Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! LGTM with a minor comment. On 11/24/26 6:51 PM, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Elias Hogstvedt. > > (cherry picked from commit 3000f7cdb1123f2a4d8b690d4292c541359c670c) > > The `recff_ffi_xof()` for `ffi.offsetof()` records 3 slots returned to > the Lua stack unconditionally, while the VM returns this much only for > bitfields. This leads to the maximum slot assertion failure in the > `rec_check_slots()`. > > This patch fixes this by adjusting the `maxslot` before the recording of > the next instruction in the `LJ_POST_FIXCONST` fixup step by the correct > slots delta. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#13442 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1514-ffi-offsetof-maxslot > Related issues: > * https://github.com/LuaJIT/LuaJIT/issues/1514 > * https://github.com/tarantool/tarantool/issues/13442 > > src/lj_record.c | 2 ++ > .../lj-1514-ffi-offsetof-maxslot.test.lua | 34 +++++++++++++++++++ > 2 files changed, 36 insertions(+) > create mode 100644 test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua > > diff --git a/src/lj_record.c b/src/lj_record.c > index dbfc7f47..ffc07b52 100644 > --- a/src/lj_record.c > +++ b/src/lj_record.c > @@ -2118,6 +2118,8 @@ void lj_record_ins(jit_State *J) > { > BCReg s; > TValue *tv = J->L->base; > + ptrdiff_t delta = J->L->top - tv; > + if (J->maxslot > (BCReg)delta) J->maxslot = (BCReg)delta; > for (s = 0; s < J->maxslot; s++) /* Constify stack slots (if any). */ > if (J->base[s] == TREF_NIL && !tvisnil(&tv[s])) > J->base[s] = lj_record_constify(J, &tv[s]); > diff --git a/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua b/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua > new file mode 100644 > index 00000000..dd6cc50f > --- /dev/null > +++ b/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua > @@ -0,0 +1,34 @@ > +local tap = require('tap') > + > +-- The test file to demonstrate an incorrect JIT slots recording > +-- for the `ffi.offsetof()` fast function. > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1514. > +local test = tap.test('lj-1514-ffi-offsetof-maxslot'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) Nit, may we skip test if LUA_USE_ASERT build flag is off and the test passed without a patch? > + > +test:plan(1) > + > +local ffi = require('ffi') > + > +ffi.cdef[[ > + struct test {int a;} > +]] > + > +jit.opt.start('hotloop=1') > + > +local ct = ffi.typeof('struct test') > + > +local res > +for _ = 1, 4 do > + -- Need to use CALLM for the `ffi.offsetof()` call to adjust > + -- JIT slots to occupy extra slots above the top of the Lua > + -- stack. Use `tonumber()` as an external function as the > + -- simplest proxy. `ffi.offsetof()` returns 1 value for regular > + -- fields. > + res = tonumber(ffi.offsetof(ct, 'a')) > +end > + > +test:is(res, 0, 'correct offset value') > + > +test:done(true) -- -- Best regards, Evgeniy Temirgaleev