Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Igor Munkin <imun@tarantool.org>,
	Maxim Kokryashkin <m.kokryashkin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 1/2] Fix maxslots when recording BC_VARG.
Date: Mon, 10 Jul 2023 13:46:48 +0300	[thread overview]
Message-ID: <323f1c0c6a33a31f0ad7691bd68886bfd195eae4.1688985402.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1688985402.git.skaplun@tarantool.org>

From: Mike Pall <mike>

Analyzed by Sergey Kaplun.

(cherry-picked from commit 94ada59628dd6ce5d6d2dad1d35a68ad30127f53)

While recording BC_VARG `J->maxslot` isn't shrunk to the effective stack
top. This leads to dead value stored in the JIT slots and the following
assertion failure for these slots check in `rec_check_slots()`. Note,
that `rec_varg()` modifies `maxslot` only under the condition that
`maxslot` should be increased, but the dead values are left for the
opposite case.

This patch removes the condition inside `rec_varg()` only for the case
when varargs are not defined on trace (`framedepth` is 0), but the
similar issue still occurs for the case when vararg are defined on the
trace.

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

Part of tarantool/tarantool#8825
---
 src/lj_record.c                               |  3 +--
 .../lj-1024-varg-maxslot.test.lua             | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 test/tarantool-tests/lj-1024-varg-maxslot.test.lua

diff --git a/src/lj_record.c b/src/lj_record.c
index a90cba77..112524d3 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1812,8 +1812,7 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
       }
       for (i = nvararg; i < nresults; i++)
 	J->base[dst+i] = TREF_NIL;
-      if (dst + (BCReg)nresults > J->maxslot)
-	J->maxslot = dst + (BCReg)nresults;
+      J->maxslot = dst + (BCReg)nresults;
     } else if (select_detect(J)) {  /* y = select(x, ...) */
       TRef tridx = J->base[dst-1];
       TRef tr = TREF_NIL;
diff --git a/test/tarantool-tests/lj-1024-varg-maxslot.test.lua b/test/tarantool-tests/lj-1024-varg-maxslot.test.lua
new file mode 100644
index 00000000..14270595
--- /dev/null
+++ b/test/tarantool-tests/lj-1024-varg-maxslot.test.lua
@@ -0,0 +1,23 @@
+local tap = require('tap')
+local test = tap.test('lj-noticket-varg-usedef'):skipcond({
+  ['Test requires JIT enabled'] = not jit.status(),
+})
+
+test:plan(1)
+
+jit.opt.start('hotloop=1')
+
+local counter = 0
+-- luacheck: ignore
+local anchor
+while counter < 3 do
+  counter = counter + 1
+  -- BC_VARG 5 1 0. `...` is nil (argument for the script).
+  -- luacheck: ignore
+  -- XXX: some condition to use several slots on the Lua stack.
+  anchor = 1 >= 1, ...
+end
+
+test:ok(true, 'BC_VARG recording 0th frame depth')
+
+os.exit(test:check() and 0 or 1)
-- 
2.34.1


  reply	other threads:[~2023-07-10 10:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 10:46 [Tarantool-patches] [PATCH luajit 0/2] " Sergey Kaplun via Tarantool-patches
2023-07-10 10:46 ` Sergey Kaplun via Tarantool-patches [this message]
2023-07-14 12:16   ` [Tarantool-patches] [PATCH luajit 1/2] " Maxim Kokryashkin via Tarantool-patches
2023-07-15 15:11     ` Sergey Kaplun via Tarantool-patches
2023-07-17 11:00       ` Maxim Kokryashkin via Tarantool-patches
2023-07-18  8:18   ` Igor Munkin via Tarantool-patches
2023-07-18 14:12     ` Sergey Kaplun via Tarantool-patches
2023-07-18 14:23       ` Igor Munkin via Tarantool-patches
2023-07-10 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] Fix maxslots when recording BC_VARG, part 2 Sergey Kaplun via Tarantool-patches
2023-07-14 12:41   ` Maxim Kokryashkin via Tarantool-patches
2023-07-15 15:08     ` Sergey Kaplun via Tarantool-patches
2023-07-17 11:03       ` Maxim Kokryashkin via Tarantool-patches
2023-07-18  8:18   ` Igor Munkin via Tarantool-patches
2023-07-18 14:19     ` Sergey Kaplun via Tarantool-patches
2023-07-18 14:24       ` Igor Munkin via Tarantool-patches
2023-07-20 18:37 ` [Tarantool-patches] [PATCH luajit 0/2] Fix maxslots when recording BC_VARG 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=323f1c0c6a33a31f0ad7691bd68886bfd195eae4.1688985402.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] Fix maxslots when recording BC_VARG.' \
    /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