<HTML><BODY><div>Hi!</div><div>Thanks for the fixes!</div><div>LGTM</div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Maxim Kokryashkin</div></div></div><div> </div><div> </div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div> <blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_16873382830479859928_BODY">Hi, Maxim!<br>Thanks for the review!<br>Fixed your comments on the branch!<br><br>On 16.06.23, Maxim Kokryashkin wrote:<br>><br>> Hi, Sergey!<br>> Thanks for the patch!<br>> Please consider my comments below.<br>>  <br>> > <br>> >>From: Mike Pall <mike><br>> >><br>> >>Reported by Shmuel Zeigerman.<br>> >><br>> >>(cherry-picked from commit 0e53a314d7910898e1ea5ba90385d43e8a6c5e57)<br>> >><br>> >>Use-def analysis for BC_FUNCV may consider slots greater than amount of<br>> >Typo: s/than/than the/<br><br>Fixed.<br><br>> >>non-vararg parameters as dead slots due to early return for BC_RET<br>> >Typo: s/due to/due to the/<br><br>Fixed.<br><br>> >Also, it’d be nice to mention the exact spot where the early return<br>> >is use-def analysis happens.<br><br>Added.<br><br>> >>emitted before usage of BC_VARG. This patch restricts the maxslot to be<br>> >>analyzed in such case with amount of parameters for the prototype of the<br>> >Typo: s/with/with the/<br><br>Fixed.<br><br>> >>current function being recorded.<br>> >><br>> >>Sergey Kaplun:<br>> >>* added the description and the test for the problem<br>> >><br>> >>Part of tarantool/tarantool#8516<br>> >>Relates to tarantool/tarantool#8718<br>> >>---<br>> >> src/lj_snap.c | 6 +++--<br>> >> .../lj-704-bc-varg-use-def.test.lua | 27 ++++++++++++++++++-<br>> >> 2 files changed, 30 insertions(+), 3 deletions(-)<br>> >><br>> >>diff --git a/src/lj_snap.c b/src/lj_snap.c<br>> >>index 5bbe8498..a063c316 100644<br>> >>--- a/src/lj_snap.c<br>> >>+++ b/src/lj_snap.c<br>> >>@@ -301,8 +301,10 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf,<br>> >> void lj_snap_purge(jit_State *J)<br>> >> {<br>> >>   uint8_t udf[SNAP_USEDEF_SLOTS];<br>> >>- BCReg maxslot = J->maxslot;<br>> >>- BCReg s = snap_usedef(J, udf, J->pc, maxslot);<br>> >>+ BCReg s, maxslot = J->maxslot;<br>> >>+ if (bc_op(*J->pc) == BC_FUNCV && maxslot > J->pt->numparams)<br>> >>+ maxslot = J->pt->numparams;<br>> >>+ s = snap_usedef(J, udf, J->pc, maxslot);<br>> >>   for (; s < maxslot; s++)<br>> >>     if (udf[s] != 0)<br>> >>       J->base[s] = 0; /* Purge dead slots. */<br>> >>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<br>> >>index c3ba65dd..38606686 100644<br>> >>--- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua<br>> >>+++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua<br>> >>@@ -6,7 +6,7 @@ local test = tap.test('lj-704-bc-varg-use-def'):skipcond({<br>> >>   ['Test requires JIT enabled'] = not jit.status(),<br>> >> })<br>> >> <br>> >>-test:plan(1)<br>> >>+test:plan(2)<br>> >> <br>> >> -- XXX: we don't really need to store this builtins, but this is<br>> >> -- reduces `jitdump()` output for reader significantly.<br>> >>@@ -62,4 +62,29 @@ wrap(ON_TRACE_VALUE)<br>> >> <br>> >> test:ok(result ~= 0, 'use-def analysis for BC_VARG')<br>> >> <br>> >>+-- Now check the same case, but with BC_RET before the BC_VARG,<br>> >>+-- so use-def analysis will take early return case.<br>> >Same as in the commit message, please mention the exact spot.<br>> >>+-- See `snap_usedef()` in <src/lj_snap.c> for details.<br>> >>+-- The test checks that slots greater than `numparams` are not<br>> >>+-- purged.<br>> >>+local function varg_ret_bc(...)<br>> >>+ -- XXX: This branch contains BC_RET. See the comment above.<br>> >>+ -- luacheck: ignore<br>> >>+ if false then else end<br>> >>+ local slot = ({...})[1]<br>> >>+ return fmod(ARG_ON_RECORDING, slot)<br>> >Is there any reason why it has to be `fmod`?<br><br>Added the comment.<br><br>> >>+end<br>> >>+<br>> >>+local function wrap_ret_bc(arg)<br>> >>+ _, result = pcall(varg_ret_bc, arg)<br>> >>+end<br>> >Is it possible to adapt the `wrap` function from the test<br>> >for the previous patch, so it can be used for both tests?<br><br>Unfortunately no, because we want to record not wrap function (at the<br>second test), but the one is pcall-ed.<br>Added the comment.<br><br>> >>+<br>> >>+-- Record trace with the 0 result.<br>> >>+wrap_ret_bc(ARG_ON_RECORDING)<br>> >>+wrap_ret_bc(ARG_ON_RECORDING)<br>> >>+-- Record trace with the non-zero result.<br>> >>+wrap_ret_bc(ON_TRACE_VALUE)<br>> >>+<br>> >>+test:ok(result ~= 0, 'use-def analysis for FUNCV with return before BC_VARG')<br>> >>+<br>> >> os.exit(test:check() and 0 or 1)<br>> >>--<br>> >>2.34.1<br>> >--<br>> >Best regards,<br>> >Maxim Kokryashkin<br>> > <br><br>--<br>Best regards,<br>Sergey Kaplun</div></div></div></div></blockquote><div> </div></div></blockquote></BODY></HTML>