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 2457B6ECE2; Mon, 23 Nov 2026 13:44:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2457B6ECE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795430661; bh=/ds0y3VbgOsbDQ4gfXVQIdBuxUhhsXRmMnj0NUAmsnU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tqvh/myJNBzxPBxHg+MTZnmSXEChh91sGF3EDMqB5TjyzgUBHpgPhqniiolsFkXPJ WAezKq2HiRc7RZfwDgp+BME5RDAMbz8cNJmO2ZWLDY6zvP1MrmdplltF09fd2eWaL+ DMVUnvvcM2KqWfcJBvqIpbNTCB95UxB2fROCOj1A= Received: from send104.i.mail.ru (send104.i.mail.ru [89.221.237.199]) (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 46D9F6ECE2 for ; Mon, 23 Nov 2026 13:43:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 46D9F6ECE2 Received: by exim-smtp-canary-30-7cf57c478c-srcq7 with esmtpa (envelope-from ) id 1xVRWY-00000000QTa-0mee; Mon, 23 Nov 2026 13:43:50 +0300 To: Evgeniy Temirgaleev , Sergey Bronnikov Date: Mon, 23 Nov 2026 13:46:00 +0300 Message-ID: <4a3e159dc353186f5ab439952190b83218e9cbf0.1795430601.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9DFC18640EC9820974E0A2AFB2F721A5B68E9CC541465F511182A05F53808504082943926B9421A283DE06ABAFEAF6705831AC6059828311AD7F7A5FBB25FAD09739E20DD193DB474 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BCC85671EC7A750CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756603DA5D6BE41EFC0DDADF7188510F24265076B0CFB90E84E9467B919F31E0432A389733CBF5DBD5E9D5E8D9A59859A8B601F8F2FECC0250C8CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8090A508E0FED6299176DF2183F8FC7C009ED9CCF91863AE1CD04E86FAF290E2DB606B96278B59C421DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B69DC5D3EDC80DC730089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5E27512019F6DF2395002B1117B3ED696825BA6FE0929478514DB8790748E3E77823CB91A9FED034534781492E4B8EEAD2B25D9E4C92BC8ACC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659A6189DA193EA3B793BC1541F0FE20423853408A9E13A6BCCB857ADAC3BF9B5FA47A8EC358F1FC8EBB8341EE9D5BE9A0A387221B125188BA699657C4F8BF576603F4D9E977CE305BFC7CEAA0681F5848F4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWA6s3iLD+8Kjsl0Q2O/NArY= X-Mailru-Sender: 520A125C2F17F0B17094CDC02B85F11BE1A66B0124463D2F3DE06ABAFEAF6705831AC6059828311AB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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. +local function stack() + return 1.2 +end + +local function call_wp(f) + stack() -- Push some value to the stack to mark the slot. + -- 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) -- 2.56.0