Skip to content

Commit 2265a15

Browse files
committed
Handle HOTCNT in for loop
1 parent ebaa578 commit 2265a15

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/jit/lj_record.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,9 @@ void lj_record_ins(jit_State *J)
18121812
if (!tvistruecond(&J2G(J)->tmptv2))
18131813
lj_trace_err(J, LJ_TRERR_GFAIL);
18141814

1815+
if (bc_op(ins) == BC_HOTCNT)
1816+
ins = *(J->pc - 2);
1817+
18151818
/*
18161819
* In case of tail call, ins will point to CALL from caller function,
18171820
* not to the original CALLT/CALLMT made in callee.

tests/impl/uJIT-tests-Lua/suite/chunks/table/rindex/tailcall.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ do --- rindex return value check must not be broken
5353
bar(tab)
5454
bar(tab) -- should exit normally
5555
end
56+
57+
do --- ensure correct HOTCNT handling (i.e. applying LJ_POST_FFSPECRET while J->pc-1 points to HOTCNT)
58+
local function foo(tab)
59+
return ujit.table.rindex(tab, "k1", "k2")
60+
end
61+
62+
local function bar(tab)
63+
for _ = 1, 5 do
64+
foo(tab)
65+
end
66+
end
67+
68+
bar({k1 = {k2 = false}})
69+
end

tests/impl/uJIT-tests-Lua/suite/table.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ $tester->run('rindex/tailcall.lua', args => '-Ohotloop=3 -Ohotexit=2 -p-')
301301
0027.+>.+p32.RETF\s
302302
.+SNAP.+\#1\s
303303
.+TRACE.6.mcode.+/xs)
304+
->stdout_matches(qr/.+TRACE.7.IR.+\s
305+
0025.rax.+p64.CALLL.+lj_tab_rawrindex_jit.+\(0024\)\s
306+
0026.+>.+p64.NE.+0025.+\[NULL\]\s
307+
0027.+>.+fal.TVLOAD.0025\s
308+
.+LOOP.+\s
309+
0034.rax.+p64.CALLL.+lj_tab_rawrindex_jit.+\(0033\)\s
310+
0035.+>.+p64.NE.+0034.+\[NULL\]\s
311+
0036.+>.+fal.TVLOAD.0034\s
312+
.+TRACE.7.mcode.+/xs)
304313
;
305314

306315
exit;

0 commit comments

Comments
 (0)