From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 84130237A6 for ; Thu, 5 Sep 2019 13:55:24 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I9mjWhEK9R58 for ; Thu, 5 Sep 2019 13:55:24 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 43C5223437 for ; Thu, 5 Sep 2019 13:55:24 -0400 (EDT) From: Igor Munkin Subject: [tarantool-patches] [PATCH 1/1] luajit: fix string.find recording Date: Thu, 5 Sep 2019 20:57:28 +0300 Message-Id: <9756499526738c87e10c8c7fb2107beb6dd60e74.1567706117.git.imun@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Igor Munkin 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