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 6F5B66ECE2; Mon, 23 Nov 2026 17:51:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6F5B66ECE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795445508; bh=UBjOxWiYLGDxUyO24eW70y37TIaN1HF7R4Bg4NPuaS0=; 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=a9BzIlqAF2gMcnvj5a1i8FaMoaOU1W6QUTSRbnRmQm7z/3VBEjI0C3B+JX7BRG+Io 1QgdB/OYRkjHM6Ar3MHZOGHDkC4HfGhfm2W8a3YnPWpAtuWO/QWi4IA9fEWDwZYv/b dgpbbQ4QeocAjqjnxUXtJR8UI+vNrm1trhgp3xI8= Received: from send80.i.mail.ru (send80.i.mail.ru [89.221.237.175]) (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 F096F6ECE2 for ; Mon, 23 Nov 2026 17:51:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F096F6ECE2 Received: by exim-smtp-56bb8ff957-wmnsr with esmtpa (envelope-from ) id 1xVVOU-00000000AXI-2rq7; Mon, 23 Nov 2026 17:51:47 +0300 Content-Type: multipart/alternative; boundary="------------o6bZdC8KgkLirOEDFxRaaQq0" Message-ID: <7c389fcd-976d-4471-9643-4d17d5a7ae8e@tarantool.org> Date: Mon, 23 Nov 2026 17:51:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org References: <4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD90028F27364C53ECEB6FF8847DD3FBD7CBFA6D08936E901EE182A05F5380850404C228DA9ACA6FE273FB28775AC8AD1BE3DE06ABAFEAF6705F8E547268E9F938CD413B2FA8A1533798CCE5171D93B726C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B8498AC83B273C12EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756603DA5D6BE41EFC0D4636F7FE8F9BD4E2590FA348B0835D656C21AD80772A186F389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE702706FBA10211704731C566533BA786AA5CC5B56E945C8DA X-87b9d050: 1 X-C1DE0DAB: 0D63561A33F958A514236FE70E3FAE615002B1117B3ED6968F16C95FB17F310DC66B2B37046EC9553610D81D389A125CDE35189EBF2DEA28FEA14CD2CD220BB99C5DF10A05D560A9880EC71AF561E0AAD9143641EC25BB39E386F643802F1778 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659066931C6BC927A01C72F2E02BCC6D9EABA97FA8C0DBB1AC58A53CCE3C090D2A3491792E30DEF60C4B8341EE9D5BE9A0A3C18C74E41F94DF93284CC68181CD2ABD1591AFA217E749B6536EB022892E5344C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWCW2UZQD/xzWnNR0l9D9uPM= X-Mailru-Sender: 689FA8AB762F73937C9FA53A4753B3135F2B8EEFA96C7A2C4051AE5E88A5AEC8C1A28B42E7C25859EF86D5F70DA33880E41E8EF7A07863ECB274557F927329BE2DDF8182D28ACDB545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] x86: Fix math.floor()/ceil() argument check. 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. --------------o6bZdC8KgkLirOEDFxRaaQq0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey! thanks for the patch! LGTM with minor comments. Sergey On 11/23/26 13:46, Sergey Kaplun wrote: > From: Mike Pall > > 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) --------------o6bZdC8KgkLirOEDFxRaaQq0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

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)
--------------o6bZdC8KgkLirOEDFxRaaQq0--