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 01A7DBF77A0; Mon, 1 Jul 2024 13:12:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 01A7DBF77A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1719828759; bh=XXweOmjGOdwtibDwcxB4CQgAR87QETHLTw8fp0tueks=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uVhl7RmF6HOrEDcgfhIl4/1SYyYpG3zpYjseYdpjAqSMQ0fmo45FZD0QrzPT74KzV JuGIzV0tMp9SjrnMQ2I3nJeS38DKDfYOAf1WBsqMFUdT5Yj+wt8ASOikOi74N5uc5d 3Y3DMXdxqQaJX+DkuvMik4Nyns1hINBLbdBygZCA= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [95.163.41.88]) (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 CFD20BF7781 for ; Mon, 1 Jul 2024 13:12:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CFD20BF7781 Received: by exim-smtp-84f7fbf7d8-mqhph with esmtpa (envelope-from ) id 1sOE1S-00000000FCA-3Jsa; Mon, 01 Jul 2024 13:12:35 +0300 Date: Mon, 1 Jul 2024 13:12:29 +0300 To: Maxim Kokryashkin Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92EE09148F40C5446592FCD463AEFA28E5E23593483BA128B182A05F53808504034E868DABF1BC8433DE06ABAFEAF6705831613D3F31ECDCC2013C9F3E49817EB97FFBCB1194FBF86 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE741A8F2705CF52F55EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063754D7F012132A27898638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D50949C4AB52CD90849CCB03DE313E57D4EAE45CC192CCA2CC7F00164DA146DAFE8445B8C89999728AA50765F7900637B18CEC08E50EEB57389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC813BDA61BF53F5E1DF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BEB1A37DF9DABAA8F75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5E5C13AD95AFA910F5002B1117B3ED6964B2A5C9307E35C76250A03108B67251B823CB91A9FED034534781492E4B8EEAD8D8BB953E4894305BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF85D4437223E7849B62058CCC08AE3AB8AF8C8DC93BAFEFDC277E95E1E9F76D03C6BFA615E6C3782A9DF1169A732047E3ECC2346622A2B4FDF4CE35D70E86D2DCAE1F37E8586706D95F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojn+1t2APtxW8kHwkPq5mCZA== X-DA7885C5: 309F35906A15ECCBF255D290C0D534F9FB52BB6F985B2088DF92C424EE730650AB99B6CB1A5AE4A15B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393C6D0B12EA33CAA9B67A15106DE3D38B3C9175CDF29B2400CBE4BB21875F0EDC7E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Avoid negation of signed integers in C that may hold INT*_MIN. 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" Hi, Maxim! Thanks for the review! Fixed your comments, see the iterative patch below. Branch is force-pushed. =================================================================== diff --git a/test/tarantool-tests/lj-928-int-min-negation.test.lua b/test/tarantool-tests/lj-928-int-min-negation.test.lua index 26f4ed8e..982bba73 100644 --- a/test/tarantool-tests/lj-928-int-min-negation.test.lua +++ b/test/tarantool-tests/lj-928-int-min-negation.test.lua @@ -12,7 +12,7 @@ local INT32_MIN = -0x80000000 local INT64_MIN = -0x8000000000000000 local TOBIT_CHAR_MAX = 254 --- XXX: Many tests (`tonumber()`-related) are failed under UBSan +-- XXX: Many tests (`tonumber()`-related) are failing under UBSan -- with DUALNUM enabled. They are included to avoid regressions in -- the future if such a build becomes the default. local ffi = require('ffi') @@ -23,7 +23,7 @@ test:plan(14) jit.opt.start('hotloop=1') -- Temporary variable for the results. -local r +local result -- :`lj_vm_modi()` for _ = 1, 4 do @@ -31,16 +31,16 @@ for _ = 1, 4 do -- Operands should be constants on the trace. local x = -0x80000000 local y = -0x80000000 - r = x % y + result = x % y end -test:is(r, 0, 'no UB during lj_vm_modi') +test:is(result, 0, 'no UB during lj_vm_modi') -- :`lj_strfmt_wint()` for _ = 1, 4 do - -- Operand should be the constant on the trace. - r = tostring(bit.tobit(0x80000000)) + -- Operand should be a constant on the trace. + result = tostring(bit.tobit(0x80000000)) end -test:is(r, '-2147483648', 'no UB during lj_strfmt_wint') +test:is(result, '-2147483648', 'no UB during lj_strfmt_wint') -- :`lj_strfmt_putfxint()` test:is(('%d'):format(INT64_MIN), '-9223372036854775808', @@ -70,17 +70,17 @@ test:is(bit.tohex(0, INT32_MIN), TOHEX_EXPECTED, 'no UB during bit_tohex') -- The second argument is the number of bytes to be represented. -- The negative value stands for uppercase. for _ = 1, 4 do - -- The second argument should be the constant on the trace. - r = bit.tohex(0, -0x80000000) + -- The second argument should be a constant on the trace. + result = bit.tohex(0, -0x80000000) end -test:is(r, TOHEX_EXPECTED, 'no UB during recording bit.tohex') +test:is(result, TOHEX_EXPECTED, 'no UB during recording bit.tohex') -- :`simplify_intsub_k()` -r = 0 +result = 0 for _ = 1, 4 do - r = r - 0x8000000000000000LL + result = result - 0x8000000000000000LL end -test:is(r, 0LL, 'no UB during simplify_intsub_k') +test:is(result, 0LL, 'no UB during simplify_intsub_k') -- :`strscan_hex()` test:is(tonumber('-0x80000000'), INT32_MIN, 'no UB during strscan_hex') =================================================================== On 01.07.24, Maxim Kokryashkin wrote: > Hi, Sergey! > Thanks for the patch! > LGTM, except for a few nits below. > > On Tue, Jun 25, 2024 at 06:54:25PM GMT, Sergey Kaplun wrote: > > From: Mike Pall > > > > diff --git a/test/tarantool-tests/lj-928-int-min-negation.test.lua b/test/tarantool-tests/lj-928-int-min-negation.test.lua > > new file mode 100644 > > index 00000000..26f4ed8e > > --- /dev/null > > +++ b/test/tarantool-tests/lj-928-int-min-negation.test.lua > > @@ -0,0 +1,121 @@ > > +local tap = require('tap') > > + > > +-- Test file to demonstrate LuaJIT's UBSan failures during > > +-- `INT*_MIN` negation. > > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/928. > > + > > +local test = tap.test('lj-928-int-min-negation.'):skipcond({ > > + ['Test requires JIT enabled'] = not jit.status(), > > +}) > > + > > +local INT32_MIN = -0x80000000 > > +local INT64_MIN = -0x8000000000000000 > > +local TOBIT_CHAR_MAX = 254 > > + > > +-- XXX: Many tests (`tonumber()`-related) are failed under UBSan > Typo: s/are failed/are failing/ Fixed, thanks! > > +-- with DUALNUM enabled. They are included to avoid regressions in > > +-- the future if such a build becomes the default. > > +local ffi = require('ffi') > > +local LL_T = ffi.typeof(1LL) > > + > > +test:plan(14) > > + > > +jit.opt.start('hotloop=1') > > + > > +-- Temporary variable for the results. > > +local r > Let's name it `result` or `tmp_result` then. Renamed. > > > + > > +-- :`lj_vm_modi()` > > +for _ = 1, 4 do > > + -- Use additional variables to avoid folding during parsing. > > + -- Operands should be constants on the trace. > > + local x = -0x80000000 > > + local y = -0x80000000 > > + r = x % y > > +end > > +test:is(r, 0, 'no UB during lj_vm_modi') > > + > > +-- :`lj_strfmt_wint()` > > +for _ = 1, 4 do > > + -- Operand should be the constant on the trace. > Typo: s/the constant/a constant/ Fixed. > > + r = tostring(bit.tobit(0x80000000)) > > -- > > 2.45.1 > > -- Best regards, Sergey Kaplun