From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
Evgeniy Temirgaleev <e.temirgaleev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check.
Date: Mon, 23 Nov 2026 17:51:45 +0300 [thread overview]
Message-ID: <7c389fcd-976d-4471-9643-4d17d5a7ae8e@tarantool.org> (raw)
In-Reply-To: <4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org>
[-- Attachment #1: Type: text/plain, Size: 3095 bytes --]
Hi, Sergey!
thanks for the patch! LGTM with minor comments.
Sergey
On 11/23/26 13:46, Sergey Kaplun wrote:
> From: Mike Pall <mike>
>
> Thanks to RaphaelIT7.
>
> (cherry picked from commit acf8fcbd932a68d130fa3e3654e1b622e10fd6af)
>
> The `math.floor()`, `math.ceil()` VM implementation uses the `.ffunc`
> macro, which doesn't check the given arguments. If the top stack value
> contains some garbage number value, it will be used as the function
> result instead of raising an error.
>
> This patch fixes the behaviour for non-GC64 mode by using the correct
> `.ffunc_1` macro. The GC64 VM will be fixed in the next patch.
>
> Sergey Kaplun:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#13442
> ---
> src/vm_x86.dasc | 2 +-
> .../lj-1532-math-floor-ceil-argcheck.test.lua | 36 +++++++++++++++++++
> 2 files changed, 37 insertions(+), 1 deletion(-)
> create mode 100644 test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
>
> diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
> index 19653fee..e875d073 100644
> --- a/src/vm_x86.dasc
> +++ b/src/vm_x86.dasc
> @@ -2212,7 +2212,7 @@ static void build_subroutines(BuildCtx *ctx)
> |.endif
> |
> |.macro math_round, func
> - | .ffunc math_ .. func
> + | .ffunc_1 math_ .. func
> |.if DUALNUM
> | cmp dword [BASE+4], LJ_TISNUM; jne >1
> | mov RB, dword [BASE]; jmp ->fff_resi
> diff --git a/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua b/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
> new file mode 100644
> index 00000000..b9def637
> --- /dev/null
> +++ b/test/tarantool-tests/lj-1532-math-floor-ceil-argcheck.test.lua
> @@ -0,0 +1,36 @@
> +local tap = require('tap')
> +
> +-- Test file to demonstrate LuaJIT incorrect handling of no
> +-- arguments for `math.ceil()`, `math.floor()` functions.
> +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1532.
> +
> +local test = tap.test('lj-1532-math-floor-ceil-argcheck')
> +
> +test:plan(2)
> +
> +-- A simple function to push a number value for `math.floor()`,
> +-- `math.ceil()` to the Lua stack.
In fact, a function can push a value for any function, not only
`math.floor()` or `math.ceil()`.
I would omit the comment at all.
> +local function stack()
> + return 1.2
> +end
> +
> +local function call_wp(f)
> + stack() -- Push some value to the stack to mark the slot.
nit: we usually put a comments before the line, isn't it?
> + -- Use non-inlined variant for function name in the error
> + -- message.
> + local res = f()
> + return res
> +end
> +
> +local function math_func_test(subtest, f)
> + subtest:plan(2)
> + local err, msg = pcall(call_wp, f)
> + subtest:is(err, false, 'correct status for empty ' .. subtest.name)
> + subtest:like(msg, "bad argument #1 to 'f' %(number expected, got no value%)",
> + 'correct error message for empty ' .. subtest.name)
> +end
> +
> +test:test('math.ceil', math_func_test, math.ceil)
> +test:test('math.floor', math_func_test, math.floor)
> +
> +test:done(true)
[-- Attachment #2: Type: text/html, Size: 4108 bytes --]
next prev parent reply other threads:[~2026-11-23 14:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:45 [Tarantool-patches] [PATCH luajit 0/2] " Sergey Kaplun via Tarantool-patches
2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 1/2] x86: " Sergey Kaplun via Tarantool-patches
2026-11-23 14:51 ` Sergey Bronnikov via Tarantool-patches [this message]
2026-11-23 10:46 ` [Tarantool-patches] [PATCH luajit 2/2] x64: " Sergey Kaplun via Tarantool-patches
2026-11-23 14:58 ` Sergey Bronnikov 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=7c389fcd-976d-4471-9643-4d17d5a7ae8e@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=e.temirgaleev@tarantool.org \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check.' \
/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