From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>, Sergey Bronnikov <sergeyb@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix use-def analysis for vararg functions. Date: Fri, 9 Jun 2023 12:32:53 +0300 [thread overview] Message-ID: <eba440def9810cad711b3a74489013476a60cc96.1686299850.git.skaplun@tarantool.org> (raw) In-Reply-To: <cover.1686299850.git.skaplun@tarantool.org> From: Mike Pall <mike> Reported by Shmuel Zeigerman. (cherry-picked from commit 0e53a314d7910898e1ea5ba90385d43e8a6c5e57) Use-def analysis for BC_FUNCV may consider slots greater than amount of non-vararg parameters as dead slots due to early return for BC_RET emitted before usage of BC_VARG. This patch restricts the maxslot to be analyzed in such case with amount of parameters for the prototype of the current function being recorded. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#8516 Relates to tarantool/tarantool#8718 --- src/lj_snap.c | 6 +++-- .../lj-704-bc-varg-use-def.test.lua | 27 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/lj_snap.c b/src/lj_snap.c index 5bbe8498..a063c316 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -301,8 +301,10 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf, void lj_snap_purge(jit_State *J) { uint8_t udf[SNAP_USEDEF_SLOTS]; - BCReg maxslot = J->maxslot; - BCReg s = snap_usedef(J, udf, J->pc, maxslot); + BCReg s, maxslot = J->maxslot; + if (bc_op(*J->pc) == BC_FUNCV && maxslot > J->pt->numparams) + maxslot = J->pt->numparams; + s = snap_usedef(J, udf, J->pc, maxslot); for (; s < maxslot; s++) if (udf[s] != 0) J->base[s] = 0; /* Purge dead slots. */ diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua index c3ba65dd..38606686 100644 --- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua +++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua @@ -6,7 +6,7 @@ local test = tap.test('lj-704-bc-varg-use-def'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), }) -test:plan(1) +test:plan(2) -- XXX: we don't really need to store this builtins, but this is -- reduces `jitdump()` output for reader significantly. @@ -62,4 +62,29 @@ wrap(ON_TRACE_VALUE) test:ok(result ~= 0, 'use-def analysis for BC_VARG') +-- Now check the same case, but with BC_RET before the BC_VARG, +-- so use-def analysis will take early return case. +-- See `snap_usedef()` in <src/lj_snap.c> for details. +-- The test checks that slots greater than `numparams` are not +-- purged. +local function varg_ret_bc(...) + -- XXX: This branch contains BC_RET. See the comment above. + -- luacheck: ignore + if false then else end + local slot = ({...})[1] + return fmod(ARG_ON_RECORDING, slot) +end + +local function wrap_ret_bc(arg) + _, result = pcall(varg_ret_bc, arg) +end + +-- Record trace with the 0 result. +wrap_ret_bc(ARG_ON_RECORDING) +wrap_ret_bc(ARG_ON_RECORDING) +-- Record trace with the non-zero result. +wrap_ret_bc(ON_TRACE_VALUE) + +test:ok(result ~= 0, 'use-def analysis for FUNCV with return before BC_VARG') + os.exit(test:check() and 0 or 1) -- 2.34.1
next prev parent reply other threads:[~2023-06-09 9:38 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-09 9:32 [Tarantool-patches] [PATCH luajit 0/2] Fix use-def analysis for varargs Sergey Kaplun via Tarantool-patches 2023-06-09 9:32 ` [Tarantool-patches] [PATCH luajit 1/2] Fix use-def analysis for BC_VARG Sergey Kaplun via Tarantool-patches 2023-06-14 14:46 ` Maxim Kokryashkin via Tarantool-patches 2023-06-21 8:40 ` Sergey Kaplun via Tarantool-patches 2023-06-21 8:52 ` Sergey Kaplun via Tarantool-patches 2023-06-22 8:50 ` Maxim Kokryashkin via Tarantool-patches 2023-06-28 10:19 ` Sergey Kaplun via Tarantool-patches 2023-06-28 18:44 ` Maxim Kokryashkin via Tarantool-patches 2023-07-04 10:34 ` Igor Munkin via Tarantool-patches 2023-06-09 9:32 ` Sergey Kaplun via Tarantool-patches [this message] 2023-06-16 9:23 ` [Tarantool-patches] [PATCH luajit 2/2] Fix use-def analysis for vararg functions Maxim Kokryashkin via Tarantool-patches 2023-06-21 9:00 ` Sergey Kaplun via Tarantool-patches 2023-06-22 8:57 ` Maxim Kokryashkin via Tarantool-patches 2023-07-04 11:41 ` Igor Munkin via Tarantool-patches 2023-07-04 17:09 ` [Tarantool-patches] [PATCH luajit 0/2] Fix use-def analysis for varargs Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=eba440def9810cad711b3a74489013476a60cc96.1686299850.git.skaplun@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=sergeyb@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 2/2] Fix use-def analysis for vararg functions.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox