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 7CE8E6FC83; Fri, 20 Aug 2021 18:50:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7CE8E6FC83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629474608; bh=eiD9enizvYBm12d2TeBH8/PqO18svOkrBpnTMUtiPXY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Zw7Pcooh0i6lL4n7QTP1oBOykdECERWzdAAp/qxQn63pMoZQB7ajusL/NLcdJZhov kbVNr1qYnncgecrvqQt3piAYqiHX1+jVhknfWOfDJTYYwnRHwCr0xQRl8TEJUb8rTE kgylxQ2i9Tnjea+zhL57crtjibVdStGWYb6h2O8c= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 D226E6FC83 for ; Fri, 20 Aug 2021 18:50:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D226E6FC83 Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1mH6mT-0001lr-0W; Fri, 20 Aug 2021 18:50:05 +0300 To: Igor Munkin , Sergey Ostanevich Date: Fri, 20 Aug 2021 18:48:46 +0300 Message-Id: <20210820154846.5515-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9F9A2272A1D086A28553D1D5C4B4124EF182A05F538085040D2D3E7B656D7ACA77FD215A28258CD55C498DE889FD8898A9D9934BFD80839AF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE701173C01F417A2A6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BD378188104BC8BE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85B18C625AE8D962B657E0C31C412F68A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C8DC2057B3FE6961B2FE01E629DB9A1FF3E461C21D416D9E19C2B6934AE262D3EE7EAB7254005DCEDA0EE70D6C6970CA79510FB958DCE06DB6ED91DBE5ABE359AC8952F428387DEC01F9270390973918F93EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AC632F0BE69382F34299555FFE1469F3C6A39A96ABBB58ED2464EE28BC4BD6B15F231F1B365B3E661D7E09C32AA3244CE77CB85E4FEC74F3BAB10C1AF2D331F4E646F07CC2D4F3D8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojZWOt9KMsrmd6OMOQemb6PA== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4B394AB7A82008F2470A49F4A4F31B20E1CEEFA1C7950CE11F2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] Fix string.char() recording with no arguments. 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 (cherry picked from commit dfa692b746c9de067857d5fc992a41730be3d99a) `string.char()` call without arguments yields an empty string. When JIT machinery records the aforementioned call it doesn't handle this case. Each recording fast function expects 1 result by default. Hence, when return from this call is recorded the framelink slot is used as a result. It is loaded into the corresponding slot as an IR with `IRT_NUM` type. It leads to assertion failure in `rec_check_slots()`, when a next bytecode is recorded, because type of TValue on the stack (`LJ_STR`) isn't the same as IR (and TRef) type. This patch handles the case without arguments by the loading of IR with empty string reference into the corresponding slot. Sergey Kaplun: * added the description and the test for the problem Resolves tarantool/tarantool#6371 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-6371-string-char-no-arg Issue: https://github.com/tarantool/tarantool/issues/6371 Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-6371-string-char-no-arg Side note: CI is totally red, but AFAICS it's unrelated with my patch. Side note: See also Changelog at the Tarantool branch. src/lj_ffrecord.c | 2 ++ .../gh-6371-string-char-no-arg.test.lua | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/tarantool-tests/gh-6371-string-char-no-arg.test.lua diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 8dfa80ed..be890a93 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -866,6 +866,8 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd) for (i = 0; J->base[i] != 0; i++) tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, J->base[i]); J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); + } else if (i == 0) { + J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty); } UNUSED(rd); } diff --git a/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua b/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua new file mode 100644 index 00000000..6df93f07 --- /dev/null +++ b/test/tarantool-tests/gh-6371-string-char-no-arg.test.lua @@ -0,0 +1,28 @@ +local tap = require('tap') + +-- Test file to demonstrate assertion after `string.char()` +-- recording. +-- See also, https://github.com/tarantool/tarantool/issues/6371. + +local test = tap.test('gh-6371-string-char-no-arg') +-- XXX: Number of loop iterations. +-- 1, 2 -- instruction becomes hot +-- 3 -- trace is recorded (considering loop recording specifics), +-- but bytecodes are still executed via VM +-- 4 -- trace is executed, need to check that emitted mcode is +-- correct +local NTEST = 4 +test:plan(NTEST) + +-- Storage for the results to avoid trace aborting by `test:ok()`. +local results = {} +jit.opt.start('hotloop=1') +for _ = 1, NTEST do + table.insert(results, string.char()) +end + +for i = 1, NTEST do + test:ok(results[i] == '', 'correct recording of string.char() without args') +end + +os.exit(test:check() and 0 or 1) -- 2.31.0