Skip to content

Commit 98b1cfc

Browse files
igormunkinkyukhin
authored andcommitted
luajit: fix string.find recording
Fix provided within 587532e leads to invalid end index of the string being matched while recording Test related to this bug is also provided within this changeset Relates to: LuaJIT LuaJITgh-505 Fix: tarantool gh-4476
1 parent 8343862 commit 98b1cfc

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

src/lj_ffrecord.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd)
950950
TRef pos;
951951
emitir(IRTG(IR_NE, IRT_PGC), tr, trp0);
952952
/* Caveat: can't use STRREF trstr 0 here because that might be pointing into a wrong string due to folding. */
953-
pos = emitir(IRTI(IR_SUB), tr, trsptr);
954-
J->base[0] = emitir(IRTI(IR_ADD), pos, emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, 1)));
953+
pos = emitir(IRTI(IR_ADD), trstart, emitir(IRTI(IR_SUB), tr, trsptr));
954+
J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1));
955955
J->base[1] = emitir(IRTI(IR_ADD), pos, trplen);
956956
rd->nres = 2;
957957
} else {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env tarantool
2+
3+
tap = require('tap')
4+
5+
test = tap.test("fix-string-find-recording")
6+
test:plan(1)
7+
8+
local err = [[module 'kit.1.10.3-136' not found:
9+
no field package.preload['kit.1.10.3-136']
10+
no file './kit/1/10/3-136.lua'
11+
no file './kit/1/10/3-136/init.lua'
12+
no file './kit/1/10/3-136.so'
13+
no file '/bug/.rocks/share/tarantool/kit/1/10/3-136.lua'
14+
no file '/bug/.rocks/share/tarantool/kit/1/10/3-136/init.lua'
15+
no file '/.rocks/share/tarantool/kit/1/10/3-136.lua'
16+
no file '/.rocks/share/tarantool/kit/1/10/3-136/init.lua'
17+
no file '/bug/.rocks/lib/tarantool/kit/1/10/3-136.so'
18+
no file '/.rocks/lib/tarantool/kit/1/10/3-136.so'
19+
no file '/bug/app/kit/1/10/3-136.lua'
20+
no file '/bug/app/kit/1/10/3-136/init.lua'
21+
no file '/bug/libs/share/lua/5.1/kit/1/10/3-136.lua'
22+
no file '/bug/libs/share/lua/5.1/kit/1/10/3-136/init.lua'
23+
no file '/root/.luarocks/share/lua/5.1/kit/1/10/3-136.lua'
24+
no file '/root/.luarocks/share/lua/5.1/kit/1/10/3-136/init.lua'
25+
no file '/root/.luarocks/share/lua/kit/1/10/3-136.lua'
26+
no file '/root/.luarocks/share/lua/kit/1/10/3-136/init.lua'
27+
no file '/usr/local/share/tarantool/kit/1/10/3-136.lua'
28+
no file '/usr/local/share/tarantool/kit/1/10/3-136/init.lua'
29+
no file '/usr/share/tarantool/kit/1/10/3-136.lua'
30+
no file '/usr/share/tarantool/kit/1/10/3-136/init.lua'
31+
no file '/usr/local/share/lua/5.1/kit/1/10/3-136.lua'
32+
no file '/usr/local/share/lua/5.1/kit/1/10/3-136/init.lua'
33+
no file '/usr/share/lua/5.1/kit/1/10/3-136.lua'
34+
no file '/usr/share/lua/5.1/kit/1/10/3-136/init.lua'
35+
no file '/bug/libs/lib/lua/5.1/kit/1/10/3-136.so'
36+
no file '/bug/libs/lib/lua/kit/1/10/3-136.so'
37+
no file '/bug/libs/lib64/lua/5.1/kit/1/10/3-136.so'
38+
no file '/root/.luarocks/lib/lua/5.1/kit/1/10/3-136.so'
39+
no file '/root/.luarocks/lib/lua/kit/1/10/3-136.so'
40+
no file '/usr/local/lib64/tarantool/kit/1/10/3-136.so'
41+
no file '/usr/lib64/tarantool/kit/1/10/3-136.so'
42+
no file '/usr/local/lib64/lua/5.1/kit/1/10/3-136.so'
43+
no file '/usr/lib64/lua/5.1/kit/1/10/3-136.so'
44+
no file '/bug/libs/lib/lua/5.1/kit.so'
45+
no file '/bug/libs/lib/lua/kit.so'
46+
no file '/bug/libs/lib64/lua/5.1/kit.so'
47+
no file '/root/.luarocks/lib/lua/5.1/kit.so'
48+
no file '/root/.luarocks/lib/lua/kit.so'
49+
no file '/usr/local/lib64/tarantool/kit.so'
50+
no file '/usr/lib64/tarantool/kit.so'
51+
no file '/usr/local/lib64/lua/5.1/kit.so'
52+
no file '/usr/lib64/lua/5.1/kit.so']]
53+
54+
local at, s, e
55+
local count_vm = 0
56+
57+
jit.off()
58+
59+
repeat
60+
s, e = err:find("\n\t", at, true)
61+
at = e
62+
count_vm = count_vm + 1
63+
until not e
64+
65+
local count_jit = 0
66+
67+
jit.on()
68+
jit.opt.start(0, 'hotloop=1')
69+
70+
repeat
71+
s, e = err:find("\n\t", at, true)
72+
at = e
73+
count_jit = count_jit + 1
74+
assert(count_jit <= count_vm, "Trace goes in cycles")
75+
until not e
76+
77+
test:is(count_vm, count_jit)
78+
79+
test:check()

0 commit comments

Comments
 (0)