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 D33961B6C832; Thu, 12 Mar 2026 15:25:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D33961B6C832 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1773318312; bh=OpypVr6XhYxJoHEL+aSovagaezGVcMl5Phfe6/x0JN0=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ig1eCJjma8QvN3CvqWLe4TN6ALXkPhNV3khqELz2j/8+dEupC9PCI9776WdUcZ40m ooMnTl184fdvSirvQyzn9Tj/nxaUw5qUS2MEBf0r/QgcPtPmR+uLbDYFsPhIoST9Uj V3dnmZutIbi3vozWMUwIfUQ/43LA0xcjErLaOVbQ= Received: from send151.i.mail.ru (send151.i.mail.ru [89.221.237.246]) (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 E9FCC652080 for ; Thu, 12 Mar 2026 15:25:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E9FCC652080 Received: by exim-smtp-64cdfc6c8d-ghdw9 with esmtpa (envelope-from ) id 1w0f6D-00000000Y0c-3U1f; Thu, 12 Mar 2026 15:25:10 +0300 Content-Type: multipart/alternative; boundary="------------iyKJADCc1skBsDGONN0whus2" Message-ID: <4b80f281-5598-419d-ab41-9a84b23dbef2@tarantool.org> Date: Thu, 12 Mar 2026 15:25:09 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org References: Content-Language: en-US In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD91ABAE9865AC7DC8850146831463F184C5FE898FE311831A4182A05F5380850403103CB3A10CF96FC3DE06ABAFEAF67052B0B894718275982B29DBDBD911FE86FA0EB5089CA368F65 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE71BDE6A359BD5B800EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756627194F95AE6E7C2DFE54256B9BD9FAB3FB0BC2A28F8C5C636BF5ADF7F350686E389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B636DA1BED736F9328CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249EF34D665BE9CA8B776E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8BF858E60A7739E4253AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7356436AE5DD6441DC7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5C577F3719E22ACC15002B1117B3ED6965CBD07C229B2F9143D2BBC1EF78EDEBE823CB91A9FED034534781492E4B8EEAD9CFA8CFAC159CE19BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659F94C888FC554DC1DF635F790D800ECC08B8E30F381CBBBF41C9ABD5E747589EB869FE5AA075824C3B8341EE9D5BE9A0A287E1F6E537E31ECF5620009F541967F33E12D21BE7B831A6536EB022892E5344C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVdbVVJCphTR/dV2j3kxL6hQ= X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F25884586F4DD3FC14F99E4BF33F69C7E48EA1FB298DCD556AB7182E5CC11B3213E880DE645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/3][v3] LJ_FR2: Fix stack checks in vararg calls. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------iyKJADCc1skBsDGONN0whus2 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, Sergey, thanks for review! See comments below. The branch was force-pushed. Sergey On 3/12/26 12:36, Sergey Kaplun via Tarantool-patches wrote: > Hi, Sergey! > Thanks for the patch! > > LGTM, after fixing my nits below. > Please add the iterational diff for the fixes. > > On 12.03.26, Sergey Bronnikov wrote: >> From: Mike Pall >> >> Thanks to Peter Cawley. >> >> (cherry picked from commit d1a2fef8a8f53b0055ee041f7f63d83a27444ffa) >> >> Stack overflow can cause a segmentation fault in a vararg >> function on ARM64 and MIPS64 in LJ_FR2 mode. This happens >> because the stack check in BC_IFUNCV is off by one on these >> platforms without the patch. The original stack check >> for ARM64 and MIPS64 was incorrect: >> >> | RA == BASE + (RD=NARGS)*8 + framesize * 8 >= maxstack >> >> while the stack check on x86_64 is correct and therefore is >> not affected by the problem: >> >> | RA == BASE + (RD=NARGS+1)*8 + framesize * 8 +8 > maxstack > Typo: s/ +8/ + 8/ Fixed, thanks! >> The patch partially fixes the aforementioned issue by bumping >> LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a >> vararg function as the __newindex metamethod. >> >> A fixup for a number of required slots in `call_init()` was added >> for consistency with non-GC64 flavor. The check is too strict, so >> this can't lead to any crash. >> >> This patch also corrects the number of redzone slots in >> luajit-gdb.py to match the updated LJ_STACK_EXTRA and adds the test > luajit_lldb.py should be updated as well. Right, fixed: --- a/src/luajit_lldb.py +++ b/src/luajit_lldb.py @@ -833,7 +833,7 @@ def dump_stack(L, base=None, top=None):      top = top or L.top      stack = mref(TValuePtr, L.stack)      maxstack = mref(TValuePtr, L.maxstack) -    red = 5 + 2 * LJ_FR2 +    red = 5 + 3 * LJ_FR2      dump = [          '{padding} Red zone: {nredslots: >2} slots {padding}'.format( > >> that will help to avoid > gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue > tracker. Ah, right, I've overlooked it is a LuaJIT issue, not Tarantool. Thanks! Renamed. >> a regression in the future, see details in [1]. > Just mention details here like the following: > > | The patch partially fixes the aforementioned issue by bumping > | LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a > | vararg function as the __newindex metamethod. > | > | A fixup for a number of required slots in `call_init()` was added for > | consistency with the non-GC64 flavor. The check is too strict (if > | comparing the corresponding checks in the VM BC_IFUNCV), so this can't > | lead to any crash. To avoid possible regression in the future the > | corresponding test is added. > | > | This patch also corrects the number of redzone slots in luajit-gdb.py > | and luajit_lldb.py to match the updated LJ_STACK_EXTRA. > Updated. >> Sergey Bronnikov: >> * added the description and the test for the problem >> >> Part of tarantool/tarantool#12134 >> >> 1.https://github.com/LuaJIT/LuaJIT/issues/1402 > Please, don't mention the issue during backporting, to avoid messing the > issue tracker. > >> --- >> src/lj_def.h | 2 +- >> src/lj_dispatch.c | 2 +- >> src/luajit-gdb.py | 2 +- >> src/vm_arm64.dasc | 1 + >> src/vm_mips64.dasc | 1 + >> .../gh-1402-call_init-regression.test.lua | 36 +++++++++++++ > gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue > tracker. renamed > >> ...048-fix-stack-checks-vararg-calls.test.lua | 53 +++++++++++++++++++ >> 7 files changed, 94 insertions(+), 3 deletions(-) >> create mode 100644 test/tarantool-tests/gh-1402-call_init-regression.test.lua >> create mode 100644 test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua >> >> diff --git a/src/lj_def.h b/src/lj_def.h >> index a5bca6b0..7e4f251e 100644 >> --- a/src/lj_def.h >> +++ b/src/lj_def.h > > >> diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c >> index a44a5adf..431cb3c2 100644 >> --- a/src/lj_dispatch.c >> +++ b/src/lj_dispatch.c > > >> diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py >> index 0ae2a6e0..dab07b35 100644 >> --- a/src/luajit-gdb.py >> +++ b/src/luajit-gdb.py > > >> diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc >> index 6600e226..5ef37243 100644 >> --- a/src/vm_arm64.dasc >> +++ b/src/vm_arm64.dasc > > >> diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc >> index da187a7a..6c2975b4 100644 >> --- a/src/vm_mips64.dasc >> +++ b/src/vm_mips64.dasc > > >> diff --git a/test/tarantool-tests/gh-1402-call_init-regression.test.lua b/test/tarantool-tests/gh-1402-call_init-regression.test.lua > Please, avoid _ in the file names, lets name it like: > > lj-1402-vararg-stkov-check-gc64.test.lua > > Same for the name of the test. ok, renamed once again > >> new file mode 100644 >> index 00000000..b20f9e39 >> --- /dev/null >> +++ b/test/tarantool-tests/gh-1402-call_init-regression.test.lua >> @@ -0,0 +1,36 @@ >> +local tap = require('tap') >> + >> +-- A test file to demonstrate a probably quite strict stack >> +-- check for vararg functions in call_init. > This is not about quite strict stack check. We need this to test the > behaviour of the LuaJIT while recording the vararg function. Let's > rephrase like the following: > > | -- The test file to verify correctness of stack size check during > | -- recording of vararg functions. Updated. > > The test file to verify correctness of stack size check during recording of vararg functions. >> +-- See alsohttps://github.com/LuaJIT/LuaJIT/issues/1402 >> +local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({ > gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue > tracker. renamed --- a/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua +++ b/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua @@ -1,15 +1,16 @@  local tap = require('tap') --- A test file to demonstrate a probably quite strict stack --- check for vararg functions in call_init. +-- The test file to verify correctness of stack size check during +-- recording of vararg functions.  -- See also https://github.com/LuaJIT/LuaJIT/issues/1402 -local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({ +local test = tap.test('lj-1402-vararg-stkov-check-gc64.test.lua'):skipcond({    ['Test requires JIT enabled'] = not jit.status(),  }) >> + ['Test requires JIT enabled'] = not jit.status(), >> +}) >> + >> +test:plan(1) >> + >> +local function vararg(...) -- luacheck: no unused > Let's use this comment before the vararg declaration. > It helps with the _ below as well. Updated: --- a/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua +++ b/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua @@ -1,15 +1,16 @@  local tap = require('tap') --- A test file to demonstrate a probably quite strict stack --- check for vararg functions in call_init. +-- The test file to verify correctness of stack size check during +-- recording of vararg functions.  -- See also https://github.com/LuaJIT/LuaJIT/issues/1402 -local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({ +local test = tap.test('lj-1402-vararg-stkov-check-gc64.test.lua'):skipcond({    ['Test requires JIT enabled'] = not jit.status(),  }) test:plan(1) -local function vararg(...) -- luacheck: no unused +-- luacheck: no unused +local function vararg(...)    -- None.  end > >> + -- None. >> +end >> + >> +-- Make compilation aggressive. > Excess comment. It's quite general approach in our tests. Updated: test:plan(1) -local function vararg(...) -- luacheck: no unused +-- luacheck: no unused +local function vararg(...)    -- None.  end >> +jit.opt.start("hotloop=1") > Typo: s/"/'/g > >> +  end --- Make compilation aggressive. -jit.opt.start("hotloop=1") +jit.opt.start('hotloop=1')  local function caller()    -- luacheck: push no unused > Please add the following comment: > > | -- This function utilizes the exact amount of stack slots > | -- to cause the stack reallocation during `call_init()` in the > | -- GC64 mode. --- Make compilation aggressive. -jit.opt.start("hotloop=1") +jit.opt.start('hotloop=1') +-- This function utilizes the exact amount of stack slots to cause +-- the stack reallocation during `call_init()` in the GC64 mode.  local function caller()    -- luacheck: push no unused    local _, _, _, _, _, _, _, _, _, _ >> +local function caller() >> + -- luacheck: push no unused > Lets drop this luacheck suppression, see the comment above. Updated: +-- This function utilizes the exact amount of stack slots to cause +-- the stack reallocation during `call_init()` in the GC64 mode.  local function caller() -  -- luacheck: push no unused    local _, _, _, _, _, _, _, _, _, _    local _, _, _, _, _, _, _, _, _, _    local _, _, _, _, _, _, _, _, _, _ -  -- luacheck: pop    local n = 1    while n < 3 do      vararg() >> + local _, _, _, _, _, _, _, _, _, _ >> + local _, _, _, _, _, _, _, _, _, _ >> + local _, _, _, _, _, _, _, _, _, _ >> + -- luacheck: pop >> + local n = 1 >> + while n < 3 do >> + vararg() >> + n = n + 1 >> + end >> +end >> + >> +pcall(coroutine.wrap(caller)) > The pcall is excess lets do it without it: > | coroutine.wrap(caller)() > @@ -29,7 +29,7 @@ local function caller()    end  end -pcall(coroutine.wrap(caller)) +coroutine.wrap(caller)() test:ok(true, 'no assertion for vararg functions in call_init') >> + >> +test:ok(true, 'no assertion for vararg functions in call_init') > Just mention 'no assertion failure' (this assertion isn't in the > `call_init()`, but during recording in `rec_check_slots()`). Updated: -test:ok(true, 'no assertion for vararg functions in call_init') +test:ok(true, 'no assertion') test:done(true) >> + >> +test:done(true) >> diff --git a/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua >> new file mode 100644 >> index 00000000..3a8ad63d >> --- /dev/null >> +++ b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > > >> -- >> 2.43.0 >> --------------iyKJADCc1skBsDGONN0whus2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi, Sergey,

thanks for review! See comments below. The branch was force-pushed.

Sergey

On 3/12/26 12:36, Sergey Kaplun via Tarantool-patches wrote:
Hi, Sergey!
Thanks for the patch!

LGTM, after fixing my nits below.
Please add the iterational diff for the fixes.

On 12.03.26, Sergey Bronnikov wrote:
From: Mike Pall <mike>

Thanks to Peter Cawley.

(cherry picked from commit d1a2fef8a8f53b0055ee041f7f63d83a27444ffa)

Stack overflow can cause a segmentation fault in a vararg
function on ARM64 and MIPS64 in LJ_FR2 mode. This happens
because the stack check in BC_IFUNCV is off by one on these
platforms without the patch. The original stack check
for ARM64 and MIPS64 was incorrect:

| RA == BASE + (RD=NARGS)*8 + framesize * 8 >= maxstack

while the stack check on x86_64 is correct and therefore is
not affected by the problem:

| RA == BASE + (RD=NARGS+1)*8 + framesize * 8 +8 > maxstack
Typo: s/ +8/ + 8/
Fixed, thanks!

      
The patch partially fixes the aforementioned issue by bumping
LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a
vararg function as the __newindex metamethod.

A fixup for a number of required slots in `call_init()` was added
for consistency with non-GC64 flavor. The check is too strict, so
this can't lead to any crash.

This patch also corrects the number of redzone slots in
luajit-gdb.py to match the updated LJ_STACK_EXTRA and adds the test
luajit_lldb.py should be updated as well.

Right, fixed:

--- a/src/luajit_lldb.py
+++ b/src/luajit_lldb.py
@@ -833,7 +833,7 @@ def dump_stack(L, base=None, top=None):
     top = top or L.top
     stack = mref(TValuePtr, L.stack)
     maxstack = mref(TValuePtr, L.maxstack)
-    red = 5 + 2 * LJ_FR2
+    red = 5 + 3 * LJ_FR2
 
     dump = [
         '{padding} Red zone: {nredslots: >2} slots {padding}'.format(


<gh-1402-call_init-regression.test.lua> that will help to avoid
gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue
tracker.

Ah, right, I've overlooked it is a LuaJIT issue, not Tarantool. Thanks!

Renamed.


      
a regression in the future, see details in [1].
Just mention details here like the following:

| The patch partially fixes the aforementioned issue by bumping
| LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a
| vararg function as the __newindex metamethod.
|
| A fixup for a number of required slots in `call_init()` was added for
| consistency with the non-GC64 flavor. The check is too strict (if
| comparing the corresponding checks in the VM BC_IFUNCV), so this can't
| lead to any crash. To avoid possible regression in the future the
| corresponding test is added.
|
| This patch also corrects the number of redzone slots in luajit-gdb.py
| and luajit_lldb.py to match the updated LJ_STACK_EXTRA.

Updated.
Sergey Bronnikov:
* added the description and the test for the problem

Part of tarantool/tarantool#12134

1. https://github.com/LuaJIT/LuaJIT/issues/1402
Please, don't mention the issue during backporting, to avoid messing the
issue tracker.

---
 src/lj_def.h                                  |  2 +-
 src/lj_dispatch.c                             |  2 +-
 src/luajit-gdb.py                             |  2 +-
 src/vm_arm64.dasc                             |  1 +
 src/vm_mips64.dasc                            |  1 +
 .../gh-1402-call_init-regression.test.lua     | 36 +++++++++++++
gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue
tracker.
renamed

 ...048-fix-stack-checks-vararg-calls.test.lua | 53 +++++++++++++++++++
 7 files changed, 94 insertions(+), 3 deletions(-)
 create mode 100644 test/tarantool-tests/gh-1402-call_init-regression.test.lua
 create mode 100644 test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua

diff --git a/src/lj_def.h b/src/lj_def.h
index a5bca6b0..7e4f251e 100644
--- a/src/lj_def.h
+++ b/src/lj_def.h
<snipped>

diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c
index a44a5adf..431cb3c2 100644
--- a/src/lj_dispatch.c
+++ b/src/lj_dispatch.c
<snipped>

diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py
index 0ae2a6e0..dab07b35 100644
--- a/src/luajit-gdb.py
+++ b/src/luajit-gdb.py
<snipped>

diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index 6600e226..5ef37243 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
<snipped>

diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc
index da187a7a..6c2975b4 100644
--- a/src/vm_mips64.dasc
+++ b/src/vm_mips64.dasc
<snipped>

diff --git a/test/tarantool-tests/gh-1402-call_init-regression.test.lua b/test/tarantool-tests/gh-1402-call_init-regression.test.lua
Please, avoid _ in the file names, lets name it like:

lj-1402-vararg-stkov-check-gc64.test.lua

Same for the name of the test.
ok, renamed once again

new file mode 100644
index 00000000..b20f9e39
--- /dev/null
+++ b/test/tarantool-tests/gh-1402-call_init-regression.test.lua
@@ -0,0 +1,36 @@
+local tap = require('tap')
+
+-- A test file to demonstrate a probably quite strict stack
+-- check for vararg functions in call_init.
This is not about quite strict stack check. We need this to test the
behaviour of the LuaJIT while recording the vararg function. Let's
rephrase like the following:

| -- The test file to verify correctness of stack size check during
| -- recording of vararg functions.
Updated.

The test file to verify correctness of stack size check during recording of vararg functions.
+-- See also https://github.com/LuaJIT/LuaJIT/issues/1402
+local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({
gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue
tracker.

renamed

--- a/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua
+++ b/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua
@@ -1,15 +1,16 @@
 local tap = require('tap')
 
--- A test file to demonstrate a probably quite strict stack
--- check for vararg functions in call_init.
+-- The test file to verify correctness of stack size check during
+-- recording of vararg functions.
 -- See also https://github.com/LuaJIT/LuaJIT/issues/1402
-local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({
+local test = tap.test('lj-1402-vararg-stkov-check-gc64.test.lua'):skipcond({
   ['Test requires JIT enabled'] = not jit.status(),
 })
 


      
+  ['Test requires JIT enabled'] = not jit.status(),
+})
+
+test:plan(1)
+
+local function vararg(...) -- luacheck: no unused
Let's use this comment before the vararg declaration.
It helps with the _ below as well.

Updated:

--- a/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua
+++ b/test/tarantool-tests/lj-1402-vararg-stkov-check-gc64.test.lua
@@ -1,15 +1,16 @@
 local tap = require('tap')
 
--- A test file to demonstrate a probably quite strict stack
--- check for vararg functions in call_init.
+-- The test file to verify correctness of stack size check during
+-- recording of vararg functions.
 -- See also https://github.com/LuaJIT/LuaJIT/issues/1402
-local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({
+local test = tap.test('lj-1402-vararg-stkov-check-gc64.test.lua'):skipcond({
   ['Test requires JIT enabled'] = not jit.status(),
 })
 
 test:plan(1)
 
-local function vararg(...) -- luacheck: no unused
+-- luacheck: no unused
+local function vararg(...)
   -- None.
 end
 


+  -- None.
+end
+
+-- Make compilation aggressive.
Excess comment. It's quite general approach in our tests.


Updated:

 test:plan(1)
 
-local function vararg(...) -- luacheck: no unused
+-- luacheck: no unused
+local function vararg(...)
   -- None.
 end
 


      
+jit.opt.start("hotloop=1")
Typo: s/"/'/g

+
 end
 
--- Make compilation aggressive.
-jit.opt.start("hotloop=1")
+jit.opt.start('hotloop=1')
 
 local function caller()
   -- luacheck: push no unused

Please add the following comment:

| -- This function utilizes the exact amount of stack slots
| -- to cause the stack reallocation during `call_init()` in the
| -- GC64 mode.
--- Make compilation aggressive.
-jit.opt.start("hotloop=1")
+jit.opt.start('hotloop=1')
 
+-- This function utilizes the exact amount of stack slots to cause
+-- the stack reallocation during `call_init()` in the GC64 mode.
 local function caller()
   -- luacheck: push no unused
   local _, _, _, _, _, _, _, _, _, _


      
+local function caller()
+  -- luacheck: push no unused
Lets drop this luacheck suppression, see the comment above.

Updated:

+-- This function utilizes the exact amount of stack slots to cause
+-- the stack reallocation during `call_init()` in the GC64 mode.
 local function caller()
-  -- luacheck: push no unused
   local _, _, _, _, _, _, _, _, _, _
   local _, _, _, _, _, _, _, _, _, _
   local _, _, _, _, _, _, _, _, _, _
-  -- luacheck: pop
   local n = 1
   while n < 3 do
     vararg()


      
+  local _, _, _, _, _, _, _, _, _, _
+  local _, _, _, _, _, _, _, _, _, _
+  local _, _, _, _, _, _, _, _, _, _
+  -- luacheck: pop
+  local n = 1
+  while n < 3 do
+    vararg()
+    n = n + 1
+  end
+end
+
+pcall(coroutine.wrap(caller))
The pcall is excess lets do it without it:
| coroutine.wrap(caller)()

@@ -29,7 +29,7 @@ local function caller()
   end
 end
 
-pcall(coroutine.wrap(caller))
+coroutine.wrap(caller)()
 
 test:ok(true, 'no assertion for vararg functions in call_init')

+
+test:ok(true, 'no assertion for vararg functions in call_init')
Just mention 'no assertion failure' (this assertion isn't in the
`call_init()`, but during recording in `rec_check_slots()`).

Updated:

 
-test:ok(true, 'no assertion for vararg functions in call_init')
+test:ok(true, 'no assertion')
 
 test:done(true)


      
+
+test:done(true)
diff --git a/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua
new file mode 100644
index 00000000..3a8ad63d
--- /dev/null
+++ b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua
<snipped>

-- 
2.43.0


    
--------------iyKJADCc1skBsDGONN0whus2--