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 4BE1C711915; Sat, 18 Nov 2023 18:13:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4BE1C711915 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700320427; bh=RiNctTgcIKMMOQQmsmuv7NFyURX8omocOWROQIC4qTQ=; 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=MH6qvJQsm6NzoA3eXcpZ+GI9wma7AH7mhBxJE2OjWpk3mXlm6xXcW9IlknoCtjf52 LCj5czcCym6lzF1kFEGNuWoWYZKfpFFmEfddTplpBMXYlaTjB4+rG/NINi8DcybLCI RXDSRHp2sC7in4bUuir0zNUTVlrgoRrnifVbZaFc= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [95.163.41.95]) (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 842C86B2C41 for ; Sat, 18 Nov 2023 18:13:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 842C86B2C41 Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1r4N0x-00DEnH-3A; Sat, 18 Nov 2023 18:13:44 +0300 Message-ID: <4ef24841-3ff6-4dd4-9c25-ab80c2a041c5@tarantool.org> Date: Sat, 18 Nov 2023 18:13:43 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20231116084959.24798-1-skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <20231116084959.24798-1-skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD93F1575C7510F55479521A576BFABB5454161998EDE47712000894C459B0CD1B91128D1E80A1E51849222F9B5AB814A64151997312C8DD6D42D7423A3730B9CE4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7952C4D7BD0BF3359EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063706922F90966A37BA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80E61920B52F05A08D7C9386617962279117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A2AE38A8E97BAFFB1D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE364E7220B7C550592302FCEF25BFAB345C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CC2B5EEE3591E0D352E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53CC6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A550736AABCB6E6B35B51D6B03A59FAD05935D602F1671D047F87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF6C13C9BC0FE57D383B04A2D6379D1EE7D07E423DEBED992B2180FB1FDAB35524CCDF2CE9FE05F2E7FCC135EDF961F15F5A71EBE8C511CCE7FDD5375EAC6E4B2CE48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojQSTOZvjxQBUYCNUSrqMXOw== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458EBC782FCFD65DCA97E3B5E0313ADDFC519989B863DE37BB5282EC151BADDC1D3523A6D01B4765B2DFB59E2DDD9FE06B14FA522850F29BC30B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Add NaN check to IR_NEWREF. 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" Hello, Sergey, thanks for the patch. LGTM See my comments below. On 11/16/23 11:49, Sergey Kaplun wrote: > From: Mike Pall > > Thanks to Peter Cawley. > > (cherry-picked from commit 7f9907b4ed0870ba64342bcc4b26cff0a94540da) > > When emitting IR NEWREF, there is no check for a non-NaN stored key > value. Thus, when the NaN number value is given to trace, it may be > stored as a key. This patch adds the corresponding check. If fold > optimization is enabled, this IR EQ check is dropped if it references > CONV IR from any (unsigned) integer type since NaN can be created via > conversion from an integer. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1069-newref-nan-key > Tarantool PR: https://github.com/tarantool/tarantool/pull/9374 > Fuzzer link: https://oss-fuzz.com/testcase-detail/5251574662037504 Updated https://github.com/tarantool/tarantool/wiki/Fuzzing > Relate issues: > * https://github.com/LuaJIT/LuaJIT/issues/1069 > * https://github.com/tarantool/tarantool/issues/9145 > > src/lj_opt_fold.c | 5 +- > src/lj_record.c | 12 +- > .../lj-1069-newref-nan-key.test.lua | 151 ++++++++++++++++++ > 3 files changed, 164 insertions(+), 4 deletions(-) > create mode 100644 test/tarantool-tests/lj-1069-newref-nan-key.test.lua > > index 00000000..ec28b274 > --- /dev/null > +++ b/test/tarantool-tests/lj-1069-newref-nan-key.test.lua > @@ -0,0 +1,151 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT misbehaviour for NEWREF IR > +-- taken NaN value. > +-- See also, https://github.com/LuaJIT/LuaJIT/issues/1069. > + > +local test = tap.test('lj-1069-newref-nan-key'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +local table_new = require('table.new') > +local ffi = require('ffi') > + > +local NaN = tonumber('nan') > + > +test:plan(4) > + > +test:test('NaN on trace in the non-constant IR', function(subtest) > + local NKEYS = 3 > + > + -- XXX: NaN isn't stored, so the number of tests is: > + -- (NKEYS - 1) + test status + test error message + test keys > + -- amount. > + subtest:plan(NKEYS + 2) > + > + local tset_table = table_new(0, NKEYS) > + > + local function tset(t, k) > + -- Value doesn't matter. > + t[k] = true > + end > + > + -- Compile the function. > + jit.opt.start('hotloop=1') > + > + -- Use number keys to emit NEWREF. > + tset(tset_table, 0.1) > + tset(tset_table, 0.2) > + > + -- Insert NaN on the trace. > + local ok, err = pcall(tset, tset_table, NaN) > + > + subtest:ok(not ok, 'function returns an error') > + subtest:like(err, 'table index is NaN', 'correct error message') > + > + local nkeys = 0 > + for k in pairs(tset_table) do > + nkeys = nkeys + 1 > + subtest:ok(k == k, ('not NaN key by number %d'):format(nkeys)) > + end > + subtest:is(nkeys, NKEYS - 1, 'correct amount of keys') > +end) > + > +test:test('NaN on trace in the non-constant IR CONV', function(subtest) > + local tonumber = tonumber What for do you need this? > + local NKEYS = 3 > + > + -- XXX: NaN isn't stored, so the number of tests is: > + -- (NKEYS - 1) + test status + test error message + test keys > + -- amount. > + subtest:plan(NKEYS + 2) BTW TAP reports "bad plan" with reverted fix due to a reason described in the comment above: not ok - bad plan   planned: 5   run:  6 Nothing to do, just an observation.