Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Igor Munkin <imun@tarantool.org>
Subject: [tarantool-patches] [PATCH 1/1] luajit: fix string.find recording
Date: Thu,  5 Sep 2019 20:57:28 +0300	[thread overview]
Message-ID: <9756499526738c87e10c8c7fb2107beb6dd60e74.1567706117.git.imun@tarantool.org> (raw)
In-Reply-To: <cover.1567706117.git.imun@tarantool.org>

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 gh-505
Fix: tarantool gh-4476
---
 src/lj_ffrecord.c                       |  4 +-
 test/fix_string_find_recording.test.lua | 79 +++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)
 create mode 100755 test/fix_string_find_recording.test.lua

diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index 632b8f2..8dfa80e 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -950,8 +950,8 @@ static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd)
       TRef pos;
       emitir(IRTG(IR_NE, IRT_PGC), tr, trp0);
       /* Caveat: can't use STRREF trstr 0 here because that might be pointing into a wrong string due to folding. */
-      pos = emitir(IRTI(IR_SUB), tr, trsptr);
-      J->base[0] = emitir(IRTI(IR_ADD), pos, emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, 1)));
+      pos = emitir(IRTI(IR_ADD), trstart, emitir(IRTI(IR_SUB), tr, trsptr));
+      J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1));
       J->base[1] = emitir(IRTI(IR_ADD), pos, trplen);
       rd->nres = 2;
     } else {
diff --git a/test/fix_string_find_recording.test.lua b/test/fix_string_find_recording.test.lua
new file mode 100755
index 0000000..d3fc9e1
--- /dev/null
+++ b/test/fix_string_find_recording.test.lua
@@ -0,0 +1,79 @@
+#!/usr/bin/env tarantool
+
+tap = require('tap')
+
+test = tap.test("fix-string-find-recording")
+test:plan(1)
+
+local err = [[module 'kit.1.10.3-136' not found:
+	no field package.preload['kit.1.10.3-136']
+	no file './kit/1/10/3-136.lua'
+	no file './kit/1/10/3-136/init.lua'
+	no file './kit/1/10/3-136.so'
+	no file '/bug/.rocks/share/tarantool/kit/1/10/3-136.lua'
+	no file '/bug/.rocks/share/tarantool/kit/1/10/3-136/init.lua'
+	no file '/.rocks/share/tarantool/kit/1/10/3-136.lua'
+	no file '/.rocks/share/tarantool/kit/1/10/3-136/init.lua'
+	no file '/bug/.rocks/lib/tarantool/kit/1/10/3-136.so'
+	no file '/.rocks/lib/tarantool/kit/1/10/3-136.so'
+	no file '/bug/app/kit/1/10/3-136.lua'
+	no file '/bug/app/kit/1/10/3-136/init.lua'
+	no file '/bug/libs/share/lua/5.1/kit/1/10/3-136.lua'
+	no file '/bug/libs/share/lua/5.1/kit/1/10/3-136/init.lua'
+	no file '/root/.luarocks/share/lua/5.1/kit/1/10/3-136.lua'
+	no file '/root/.luarocks/share/lua/5.1/kit/1/10/3-136/init.lua'
+	no file '/root/.luarocks/share/lua/kit/1/10/3-136.lua'
+	no file '/root/.luarocks/share/lua/kit/1/10/3-136/init.lua'
+	no file '/usr/local/share/tarantool/kit/1/10/3-136.lua'
+	no file '/usr/local/share/tarantool/kit/1/10/3-136/init.lua'
+	no file '/usr/share/tarantool/kit/1/10/3-136.lua'
+	no file '/usr/share/tarantool/kit/1/10/3-136/init.lua'
+	no file '/usr/local/share/lua/5.1/kit/1/10/3-136.lua'
+	no file '/usr/local/share/lua/5.1/kit/1/10/3-136/init.lua'
+	no file '/usr/share/lua/5.1/kit/1/10/3-136.lua'
+	no file '/usr/share/lua/5.1/kit/1/10/3-136/init.lua'
+	no file '/bug/libs/lib/lua/5.1/kit/1/10/3-136.so'
+	no file '/bug/libs/lib/lua/kit/1/10/3-136.so'
+	no file '/bug/libs/lib64/lua/5.1/kit/1/10/3-136.so'
+	no file '/root/.luarocks/lib/lua/5.1/kit/1/10/3-136.so'
+	no file '/root/.luarocks/lib/lua/kit/1/10/3-136.so'
+	no file '/usr/local/lib64/tarantool/kit/1/10/3-136.so'
+	no file '/usr/lib64/tarantool/kit/1/10/3-136.so'
+	no file '/usr/local/lib64/lua/5.1/kit/1/10/3-136.so'
+	no file '/usr/lib64/lua/5.1/kit/1/10/3-136.so'
+	no file '/bug/libs/lib/lua/5.1/kit.so'
+	no file '/bug/libs/lib/lua/kit.so'
+	no file '/bug/libs/lib64/lua/5.1/kit.so'
+	no file '/root/.luarocks/lib/lua/5.1/kit.so'
+	no file '/root/.luarocks/lib/lua/kit.so'
+	no file '/usr/local/lib64/tarantool/kit.so'
+	no file '/usr/lib64/tarantool/kit.so'
+	no file '/usr/local/lib64/lua/5.1/kit.so'
+	no file '/usr/lib64/lua/5.1/kit.so']]
+
+local at, s, e
+local count_vm = 0
+
+jit.off()
+
+repeat
+  s, e = err:find("\n\t", at, true)
+  at = e
+  count_vm = count_vm + 1
+until not e
+
+local count_jit = 0
+
+jit.on()
+jit.opt.start(0, 'hotloop=1')
+
+repeat
+  s, e = err:find("\n\t", at, true)
+  at = e
+  count_jit = count_jit + 1
+  assert(count_jit <= count_vm, "Trace goes in cycles")
+until not e
+
+test:is(count_vm, count_jit)
+
+test:check()
-- 
2.22.1

       reply	other threads:[~2019-09-05 17:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1567706117.git.imun@tarantool.org>
2019-09-05 17:57 ` Igor Munkin [this message]
2019-09-06 12:05   ` [tarantool-patches] " Sergey Ostanevich
2019-09-11 18:23   ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9756499526738c87e10c8c7fb2107beb6dd60e74.1567706117.git.imun@tarantool.org \
    --to=imun@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/1] luajit: fix string.find recording' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox