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 AF15D50ADF4; Thu, 13 Jul 2023 15:23:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AF15D50ADF4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1689251038; bh=WiltL+jv/UC3yvoH4aAGktZUoveZ2alv/vAJgRCG4Ds=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TckYJ0gN3qDchj7UgrXl2OgrM84uKR0LKWj+DfEcfyH/jz0B4NP+s3y4Voo3w3xe8 DNgH65yLu189qUpL67wRebXNrqgsfKyucFAoLXzTB6UJqk/ItVhrO9WlWo7Ed/rGup 2F39o69Z4a0CSZlGgqbFSHSdBtFK/H0+6QAtKl6U= Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [95.163.41.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id AE1C150ADF4 for ; Thu, 13 Jul 2023 15:23:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AE1C150ADF4 Received: by smtp55.i.mail.ru with esmtpa (envelope-from ) id 1qJvMR-002gdj-Jm; Thu, 13 Jul 2023 15:23:56 +0300 Message-ID: Date: Thu, 13 Jul 2023 15:23:54 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: Maksim Kokryashkin , tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org References: <20230712095212.20480-1-max.kokryashkin@gmail.com> In-Reply-To: <20230712095212.20480-1-max.kokryashkin@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9B2A9E02D3479B2E0ECF741C3158F2015434C71B2B49F534A182A05F5380850401BB89706636B5AFCB38C63CB9E663A0417DE82C184342B14E9382A930D9FC954 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F2393C4755A27B53EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E347E1311495C1B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C3ACCF1154E40EBDC198614DCC08D1E7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352091ADC097FE2C3A0828451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE26055571C92BF10F302FCEF25BFAB3454AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3A367EA73E0D98AAD76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C22494854413538E1713FE827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A596758D0D1034A71E750B7C6ED378B6A3C7E118E11C68C888F87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF6DEAB9F1CF2E3903509AE7CE35BBBECFD8031F9C0C349315A371F88221A808E266DF14FFBF4EC714399DF444199BC1D1C22A4FE92B0C8A6EA9BDF9606C0E2B75A74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojmIyQFW4pVckDyxPbllCpZQ== X-Mailru-Sender: 49D287FBCBBF3A5C1746B9497B71E89EC6C372E005F78ED0B38C63CB9E663A0487D154BA7A9C8918EBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH] Mark CONV as non-weak, to prevent elimination of its side-effect. 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" Hi, Max! thanks for the patch! Links to the branch and PR are missed, but I found them: branch: https://github.com/tarantool/luajit/tree/fckxorg/mark-conv-non-weak PR: https://github.com/tarantool/tarantool/pull/8871 Test is passed after reverting the patch with fix. Sergey On 7/12/23 12:52, Maksim Kokryashkin wrote: > From: Mike Pall > > An unused guarded CONV int.num cannot be omitted in general. > > (cherry-picked from commit 881d02d3117838acaf4fb844332c8e33cc95c8c5) > > In some cases, an unused `CONV` omission may lead to a guard > absence, resulting in invalid control flow branching and > undefined behavior. For a comprehensive example of > the described situation, please refer to the comment > in `test/tarantool-tests/mark-conv-non-weak.test.lua`. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#8825 > --- > src/lj_ir.h | 2 +- > .../mark-conv-non-weak.test.lua | 58 +++++++++++++++++++ > 2 files changed, 59 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/mark-conv-non-weak.test.lua > > diff --git a/src/lj_ir.h b/src/lj_ir.h > index e8bca275..bf9b9292 100644 > --- a/src/lj_ir.h > +++ b/src/lj_ir.h > @@ -132,7 +132,7 @@ > _(XBAR, S , ___, ___) \ > \ > /* Type conversions. */ \ > - _(CONV, NW, ref, lit) \ > + _(CONV, N , ref, lit) \ > _(TOBIT, N , ref, ref) \ > _(TOSTR, N , ref, lit) \ > _(STRTO, N , ref, ___) \ > diff --git a/test/tarantool-tests/mark-conv-non-weak.test.lua b/test/tarantool-tests/mark-conv-non-weak.test.lua > new file mode 100644 > index 00000000..aad39058 > --- /dev/null > +++ b/test/tarantool-tests/mark-conv-non-weak.test.lua > @@ -0,0 +1,58 @@ > +local tap = require('tap') > +local test = tap.test('mark-conv-non-weak'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(1) > + > +local data = {0.1, 0, 0.1, 0, 0 / 0} > +local sum = 0 > + > +jit.opt.start('hotloop=1', 'hotexit=1') > + > +-- When the last trace is recorded, the traced bytecode > +-- is the following before the patch: > +-- ---- TRACE 4 start 2/3 test.lua:6 > +-- 0018 ADDVV 1 1 6 > +-- 0019 ITERC 5 3 3 > +-- 0000 . FUNCC ; ipairs_aux > +-- 0020 JITERL 5 1 > +-- 0021 GGET 2 7 ; "assert" > +-- 0022 ISEQV 1 1 > +-- 0023 JMP 4 => 0026 > +-- 0024 KPRI 4 1 > +-- 0025 JMP 5 => 0027 > +-- 0027 CALL 2 1 2 > +-- 0000 . FUNCC ; assert > +-- > +-- And the following after the patch: > +-- ---- TRACE 4 start 2/2 test.lua:5 > +-- 0016 ISNEV 6 6 > +-- 0017 JMP 7 => 0019 > +-- 0019 ITERC 5 3 3 > +-- 0000 . FUNCC ; ipairs_aux > +-- 0020 JITERL 5 1 > +-- 0021 GGET 2 7 ; "assert" > +-- 0022 ISEQV 1 1 > +-- 0023 JMP 4 => 0026 > +-- 0026 KPRI 4 2 > +-- 0027 CALL 2 1 2 > +-- 0000 . FUNCC ; assert > +-- 0028 RET0 0 1 > +-- > +-- The crucial difference here is the abscent > +-- `ISNEV` in the first case, which produces the > +-- desired guarded `CONV`, when translated to IR. > +-- > +-- Since there is no guard, NaN is added to the sum, > +-- despite the test case logic. > + > +for _, val in ipairs(data) do > + if val == val then > + sum = sum + val > + end > +end > + > +test:ok(sum == sum, 'NaN check was not omitted') > + > +os.exit(test:check() and 0 or 1)