]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Fix ITERN loop detection when hook checks are enabled.
authorMike Pall <mike>
Thu, 2 Jun 2022 11:18:10 +0000 (13:18 +0200)
committerMike Pall <mike>
Thu, 2 Jun 2022 11:18:10 +0000 (13:18 +0200)
Reported by Myria.

src/lj_record.c

index 533f49950efc41f59afb37c73b89ebc40b4f6cf7..faa9a5087ec45b5d33db1d138780c0cbfda15102 100644 (file)
@@ -664,12 +664,17 @@ static LoopEvent rec_itern(jit_State *J, BCReg ra, BCReg rb)
   RecordIndex ix;
   /* Since ITERN is recorded at the start, we need our own loop detection. */
   if (J->pc == J->startpc &&
-      (J->cur.nins > REF_FIRST+1 ||
-       (J->cur.nins == REF_FIRST+1 && J->cur.ir[REF_FIRST].o != IR_PROF)) &&
       J->framedepth + J->retdepth == 0 && J->parent == 0 && J->exitno == 0) {
-    J->instunroll = 0;  /* Cannot continue unrolling across an ITERN. */
-    lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Looping trace. */
-    return LOOPEV_ENTER;
+    IRRef ref = REF_FIRST + LJ_HASPROFILE;
+#ifdef LUAJIT_ENABLE_CHECKHOOK
+    ref += 3;
+#endif
+    if (J->cur.nins > ref ||
+       (LJ_HASPROFILE && J->cur.nins == ref && J->cur.ir[ref-1].o != IR_PROF)) {
+      J->instunroll = 0;  /* Cannot continue unrolling across an ITERN. */
+      lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Looping trace. */
+      return LOOPEV_ENTER;
+    }
   }
   J->maxslot = ra;
   lj_snap_add(J);  /* Required to make JLOOP the first ins in a side-trace. */