<HTML><BODY><div>Hi, Sergey!</div><div>Thanks for the patch!</div><div>Please consider my comments below.</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_16863034280604156815_BODY">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</div></div></div></div></blockquote><div>Typo: s/than/than the/</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>non-vararg parameters as dead slots due to early return for BC_RET</div></div></div></div></blockquote><div>Typo: s/due to/due to the/</div><div>Also, it’d be nice to mention the exact spot where the early return</div><div>is use-def analysis happens.</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>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</div></div></div></div></blockquote><div>Typo: s/with/with the/</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>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.</div></div></div></div></blockquote><div>Same as in the commit message, please mention the exact spot.</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>+-- 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)</div></div></div></div></blockquote><div>Is there any reason why it has to be `fmod`?</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>+end<br>+<br>+local function wrap_ret_bc(arg)<br>+ _, result = pcall(varg_ret_bc, arg)<br>+end</div></div></div></div></blockquote><div>Is it possible to adapt the `wrap` function from the test</div><div>for the previous patch, so it can be used for both tests?</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div><div class="js-helper js-readmsg-msg"><div><div>+<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</div></div></div></div></blockquote><div><div>--<br>Best regards,</div><div>Maxim Kokryashkin</div></div><div> </div></div></blockquote></BODY></HTML>