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 3F8366F153; Mon, 12 Sep 2022 11:04:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3F8366F153 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1662969883; bh=cXBaStvyiZk4xXoKPH8jonAKwYOhWCV89q6p54G+r8I=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uwvbQ/9Zk7PtaNd+0nDyFfvEjvZxjvkSJLpypJXKWhuRRUIi37zE5rWSgPezbM0GD /FXwZc+XMtG7/ftrnQqngoSW9+JEvwnz8lcy0SPJsWsvYkxSE7wK4jBGIW4/OyjxEN 7yP50XfvABFSiKkynA8CIrx3+BC70WrhWhPPxEQ8= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 D5C936F153 for ; Mon, 12 Sep 2022 11:04:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D5C936F153 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1oXeQp-0006Cq-P5; Mon, 12 Sep 2022 11:04:40 +0300 To: Sergey Ostanevich , Maxim Kokryashkin Date: Mon, 12 Sep 2022 11:01:58 +0300 Message-Id: <20220912080158.12220-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD98A32D11463CB84D89DFE7B8F177B90544BDBC0B360903937182A05F538085040ABC160385A579A696B8B60FE5386ED61660A0A4989A72C2CF7BE4CFDB6188BB4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B114C2C2C20B7E62EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A975286280E7A0BD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81EEA85CE6625CF65D9660EDA38F50B70117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC4AFB60FD1831C04CA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EED76C6ED7039589DEA68A47777D5C6D9CD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3CF7CD7A0D5AA5F25C0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637BF1C901A33650803EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C41E93BD56E7067354307CAA32FF218580205367B2BCC23E5B095F8A1277419AFFE7E65F06B2D3BF1CAD91A466A1DEF99B6ED91DBE5ABE359ADBCB5631A0A9D21FC7A0BC55FA0FE5FCD7F66F2279C11E18219DA6F9DDB1AD24E8C2CC3720828FE8B1881A6453793CE9C32612AADDFBE061D915B5B670273ACBA71A35648BE338CE9510FB958DCE06DB58C12E6D310A6D5333F7A9E5587C79A693EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AA13E2DDB9067862252218174563249C88DADB3174942F5E8CAEB95372F7AB1DD200DE0A54A661C01D7E09C32AA3244C571EBE2D234E43DB109B669037D2C02905AB220A9D022EBC927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjIqesh230IjlMz47jZbx9t X-Mailru-Sender: F16D9CAFEEA6770E7B6EAD4ADB3BCAF0679FF5EDFBA36606616F919E9D89CADD07EE7E7276D6C22CF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] FFI: Add tonumber() specialization for failed conversions. 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 Contributed by Javier Guerra Giraldez. (cherry picked from commit 02b521981a1ab919ff2cd4d9bcaee80baf77dce2) When `tonumber()` is recorded (as a part of a trace) for cdata argument can't be converted to number the `nil` value is recorded as the yielded result. But without special check on trace for cdata type this nil will be returned for another type of cdata that can be converted. This patch adds the corresponding check for recoding of failed cdata conversions. Sergey Kaplun: * added the description and the test for the problem Resolves tarantool/tarantool#7655 Part of tarantool/tarantool#7230 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-408-tonumber-cdata-record-full-ci Issues and PRs: * https://github.com/tarantool/tarantool/issues/7655 * https://github.com/tarantool/tarantool/issues/7230 * https://github.com/LuaJIT/LuaJIT/issues/408 * https://github.com/LuaJIT/LuaJIT/pull/412 Tarantool PR: https://github.com/tarantool/tarantool/pull/7668 src/lj_crecord.c | 2 + .../lj-408-tonumber-cdata-record.test.lua | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/tarantool-tests/lj-408-tonumber-cdata-record.test.lua diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 0d7b71f0..32c767e3 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1895,6 +1895,8 @@ void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) d = ctype_get(cts, CTID_DOUBLE); J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]); } else { + /* Specialize to the ctype that couldn't be converted. */ + argv2cdata(J, J->base[0], &rd->argv[0]); J->base[0] = TREF_NIL; } } diff --git a/test/tarantool-tests/lj-408-tonumber-cdata-record.test.lua b/test/tarantool-tests/lj-408-tonumber-cdata-record.test.lua new file mode 100644 index 00000000..1c175de1 --- /dev/null +++ b/test/tarantool-tests/lj-408-tonumber-cdata-record.test.lua @@ -0,0 +1,44 @@ +local ffi = require('ffi') +local tap = require('tap') + +-- Test file to demonstrate the incorrect JIT recording for +-- `tonumber()` function with cdata argument for failed +-- conversions. +-- See also https://github.com/LuaJIT/LuaJIT/issues/408, +-- https://github.com/LuaJIT/LuaJIT/pull/412, +-- https://github.com/LuaJIT/LuaJIT/pull/412, +-- https://github.com/tarantool/tarantool/issues/7655. +local test = tap.test('lj-408-tonumber-cdata-record') + +local NULL = ffi.cast('void *', 0) + +test:plan(4) + +local function check(x) + -- Don't use a tail call to avoid "leaving loop in root trace" + -- error, so the trace will be compiled. + local res = tonumber(x) + return res +end + +jit.opt.start('hotloop=1') +-- Record `check()` with `tonumber(NULL)` -- not converted. +check(NULL) +check(NULL) + +test:ok(not check(NULL), 'recorded with NULL and not converted for NULL') +test:ok(check(0LL), 'recorded with NULL and converted for 0LL') + +-- Reset JIT. +jit.off() +jit.flush() +jit.on() + +-- Record `check()` with `tonumber(0LL)` -- converted. +check(0LL) +check(0LL) + +test:ok(check(0LL), 'recorded with 0LL and converted for 0LL') +test:ok(not check(NULL), 'recorded with 0LL and not converted for NULL') + +os.exit(test:check() and 0 or 1) -- 2.34.1