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 3EC39503765; Fri, 9 Jun 2023 12:38:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3EC39503765 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1686303487; bh=E27MnLw0yd908DcaQKTcXUseqPOgQkI4uJrlrIj8P+I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Tqar0QSlpONvQyMEKxL2Ov3GrgohHd6aoJxlR2cQnN08JxQ2g95bcNYSr9H+em9Oe tYwZIcUXX+Fn1lLfJu/BKNUJnhcNJBBuAhnlSSCFeIFMFzufGgNOaX3PbfZt9v5yDb IckFcOQV9y+dvgsIl2XGl2n1dDLs5E1Cqsuy2eM4= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [95.163.41.100]) (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 1FCC8503748 for ; Fri, 9 Jun 2023 12:37:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1FCC8503748 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1q7YYO-00CuxR-2D; Fri, 09 Jun 2023 12:37:08 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Fri, 9 Jun 2023 12:32:53 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD965EFE7F2AC62B27ABD5035243EB759DF19757AA44DCF9876182A05F538085040B29AB63D368849044470FE316090D168ACABF7A40F27DB205E4644ACFB66C2F6 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F2393C4755A27B53EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063736901D4B68B3D4FF8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8AC5FF8126D1BD08B3FB78937A82EEC33117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCE2CCD8F0CAA010FB389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC88C83961949B2167BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CA09ADEE969FA4D8B6136E347CC761E074AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C386712D2D5FBAF151BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF17B107DEF921CE791DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3C9BE88FFEDFA497A35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5416B066454DF801F88FADD76790359D707362B2D0A160375F87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E5559C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1CE4D3E6416BCAD79AEA722670DA9B5BFF5793DEFFDFD0B5B7044CBEEC3881F06F890FCD3CEE011BB5655EA6190D4CDAA41E25F7966185BF9B425630AEAC4841A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojRLo8CqjALXgEiMptVgWzCw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769515CBA71EE11FAF84470FE316090D168DDEE725E12766E67DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix use-def analysis for vararg functions. 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 Reported by Shmuel Zeigerman. (cherry-picked from commit 0e53a314d7910898e1ea5ba90385d43e8a6c5e57) Use-def analysis for BC_FUNCV may consider slots greater than amount of non-vararg parameters as dead slots due to early return for BC_RET emitted before usage of BC_VARG. This patch restricts the maxslot to be analyzed in such case with amount of parameters for the prototype of the current function being recorded. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#8516 Relates to tarantool/tarantool#8718 --- src/lj_snap.c | 6 +++-- .../lj-704-bc-varg-use-def.test.lua | 27 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/lj_snap.c b/src/lj_snap.c index 5bbe8498..a063c316 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -301,8 +301,10 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf, void lj_snap_purge(jit_State *J) { uint8_t udf[SNAP_USEDEF_SLOTS]; - BCReg maxslot = J->maxslot; - BCReg s = snap_usedef(J, udf, J->pc, maxslot); + BCReg s, maxslot = J->maxslot; + if (bc_op(*J->pc) == BC_FUNCV && maxslot > J->pt->numparams) + maxslot = J->pt->numparams; + s = snap_usedef(J, udf, J->pc, maxslot); for (; s < maxslot; s++) if (udf[s] != 0) J->base[s] = 0; /* Purge dead slots. */ diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua index c3ba65dd..38606686 100644 --- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua +++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua @@ -6,7 +6,7 @@ local test = tap.test('lj-704-bc-varg-use-def'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), }) -test:plan(1) +test:plan(2) -- XXX: we don't really need to store this builtins, but this is -- reduces `jitdump()` output for reader significantly. @@ -62,4 +62,29 @@ wrap(ON_TRACE_VALUE) test:ok(result ~= 0, 'use-def analysis for BC_VARG') +-- Now check the same case, but with BC_RET before the BC_VARG, +-- so use-def analysis will take early return case. +-- See `snap_usedef()` in for details. +-- The test checks that slots greater than `numparams` are not +-- purged. +local function varg_ret_bc(...) + -- XXX: This branch contains BC_RET. See the comment above. + -- luacheck: ignore + if false then else end + local slot = ({...})[1] + return fmod(ARG_ON_RECORDING, slot) +end + +local function wrap_ret_bc(arg) + _, result = pcall(varg_ret_bc, arg) +end + +-- Record trace with the 0 result. +wrap_ret_bc(ARG_ON_RECORDING) +wrap_ret_bc(ARG_ON_RECORDING) +-- Record trace with the non-zero result. +wrap_ret_bc(ON_TRACE_VALUE) + +test:ok(result ~= 0, 'use-def analysis for FUNCV with return before BC_VARG') + os.exit(test:check() and 0 or 1) -- 2.34.1