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 244F525959 for ; Tue, 30 Jul 2019 16:00:02 -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 wBYhDlr8cFgI for ; Tue, 30 Jul 2019 16:00:02 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (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 D82D72594B for ; Tue, 30 Jul 2019 16:00:01 -0400 (EDT) From: sergos@tarantool.org Subject: [tarantool-patches] [PATCH] luajit: fold machinery misbehaves Date: Tue, 30 Jul 2019 19:59:55 +0000 Message-Id: <20190730195955.41309-1-sergos@tarantool.org> 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: Sergey Ostanevich From: Sergey Ostanevich This is a solution from the reference LuaJIT for https://github.com/LuaJIT/LuaJIT/issues/505 Picking up ahead of reference repo since it's abandoned resolves: #4376 available at: https://github.com/tarantool/luajit/tree/sergos/luajit-gh-505-folder-problems-v2 --- src/lj_ffrecord.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index dfdee2d..632b8f2 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -949,8 +949,9 @@ static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd) str->len-(MSize)start, pat->len)) { TRef pos; emitir(IRTG(IR_NE, IRT_PGC), tr, trp0); - pos = emitir(IRTI(IR_SUB), tr, emitir(IRT(IR_STRREF, IRT_PGC), trstr, tr0)); - J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1)); + /* 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))); J->base[1] = emitir(IRTI(IR_ADD), pos, trplen); rd->nres = 2; } else { -- 2.17.1