[tarantool-patches] [PATCH] luajit: fold machinery misbehaves

sergos at tarantool.org sergos at tarantool.org
Tue Jul 30 22:59:55 MSK 2019


From: Sergey Ostanevich <sergos at tarantool.org>

 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





More information about the Tarantool-patches mailing list