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 974A9CF2D94; Wed, 2 Oct 2024 11:10:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 974A9CF2D94 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1727856608; bh=LzNYHwncIgkAAjVPAtIK7d1Z0hz2YaUhC/UW+l0VMk8=; 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=nhJ6XqDFKwe9YqD0R6incmZhFWj51e7OR0S3IaKNruGLaIkK+87bdtdQJBCL25EJ3 iA60h43dgsa38lMzESiwCmX1pO+uzvElqQ5rO7V0Idkmupw9P33Hw2sZsZ13Wk8E5U 0OiRhtZOqT8hlVhs4ICN7tD64/zrnE9Zi7KhAqrQ= Received: from smtp17.i.mail.ru (smtp17.i.mail.ru [95.163.41.70]) (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 4F328CF2D94 for ; Wed, 2 Oct 2024 11:09:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F328CF2D94 Received: by exim-smtp-5858d4dbf5-4gl25 with esmtpa (envelope-from ) id 1svuQT-000000009d0-14PC; Wed, 02 Oct 2024 11:09:37 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Wed, 2 Oct 2024 11:09:05 +0300 Message-ID: <7efd063772135322abfcc8de1214d20ebea69bad.1727855711.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD964E86F54238FCC398BBAD82B66982E3DC4938CC247E11C67182A05F538085040B00EB874BE31CB513DE06ABAFEAF67058A8355C3BAA9BDC362434EF88ABBD523984125FF27271FD8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E4182CE4FE3052C2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637802D3462438662818638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85480809DD85DC7E774F16426BBA326CBFDD4F13D34FEE698CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC821E93C0F2A571C7BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C0085B890FD2717DAC0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3FF9AE5E544BDEAB7BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE76515C59FC18CEA6D731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5BBF7CE0522999DD15002B1117B3ED69624E1E34E4CAE770430C8F815570A3530823CB91A9FED034534781492E4B8EEAD619183A7BD6BC6F1F36E2E0160E5C55395B8A2A0B6518DF68C46860778A80D548E8926FB43031F38 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF3D5FEC77A079350D80223166A64410AAE0AED222772A2BCD11C6EB67551F5F0786260C86DC1AF146A06F21331F7F71AFBBCD908CBEC8284620289672AD59FC02EF352BEA6800F2E2C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojHMr0s/SL0PXTNbIX8dU62g== X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B590B173EF589B2CB373DE06ABAFEAF67058A8355C3BAA9BDC3B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/2] Fix bit op coercion in DUALNUM builds. 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 Sergey Kaplun. (cherry picked from commit f5fd22203eadf57ccbaa4a298010d23974b22fc0) The `lj_carith_check64()` function coerces the given number value to the 32-bit wide value. In this case, the 64-bit-wide operands will lose upper bits. This patch removes the excess coercion for the DUALNUM mode. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#10199 --- src/lj_carith.c | 4 +--- .../lj-1273-dualnum-bit-coercion.test.lua | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua diff --git a/src/lj_carith.c b/src/lj_carith.c index 90b3220f..eb56d552 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -349,9 +349,7 @@ uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id) if (LJ_LIKELY(tvisint(o))) { return (uint32_t)intV(o); } else { - int32_t i = lj_num2bit(numV(o)); - if (LJ_DUALNUM) setintV(o, i); - return (uint32_t)i; + return (uint32_t)lj_num2bit(numV(o)); } } diff --git a/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua new file mode 100644 index 00000000..e83dbbcd --- /dev/null +++ b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua @@ -0,0 +1,19 @@ +local tap = require('tap') + +-- Test file to demonstrate LuaJIT misbehaviour on operating +-- for 64-bit operands in built-in `bit` library in DUALNUM mode. +-- See also, https://github.com/LuaJIT/LuaJIT/issues/1273. + +local test = tap.test('lj-1273-dualnum-bit-coercion') +test:plan(1) + +local bit = require('bit') + +-- The cdata value for 2 ^ 33. +local EXPECTED = 2 ^ 33 + 0LL +-- Same value is used as mask for `bit.band()`. +local MASK = EXPECTED + +test:is(bit.band(2 ^ 33, MASK), EXPECTED, 'correct bit.band result') + +test:done(true) -- 2.46.2