aboutsummaryrefslogtreecommitdiff
path: root/src/lj_record.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_record.c')
-rw-r--r--src/lj_record.c162
1 files changed, 98 insertions, 64 deletions
diff --git a/src/lj_record.c b/src/lj_record.c
index 4fc22742..2a4a766e 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -50,34 +50,52 @@
50static void rec_check_ir(jit_State *J) 50static void rec_check_ir(jit_State *J)
51{ 51{
52 IRRef i, nins = J->cur.nins, nk = J->cur.nk; 52 IRRef i, nins = J->cur.nins, nk = J->cur.nk;
53 lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536); 53 lj_assertJ(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536,
54 "inconsistent IR layout");
54 for (i = nk; i < nins; i++) { 55 for (i = nk; i < nins; i++) {
55 IRIns *ir = IR(i); 56 IRIns *ir = IR(i);
56 uint32_t mode = lj_ir_mode[ir->o]; 57 uint32_t mode = lj_ir_mode[ir->o];
57 IRRef op1 = ir->op1; 58 IRRef op1 = ir->op1;
58 IRRef op2 = ir->op2; 59 IRRef op2 = ir->op2;
60 const char *err = NULL;
59 switch (irm_op1(mode)) { 61 switch (irm_op1(mode)) {
60 case IRMnone: lua_assert(op1 == 0); break; 62 case IRMnone:
61 case IRMref: lua_assert(op1 >= nk); 63 if (op1 != 0) err = "IRMnone op1 used";
62 lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break; 64 break;
65 case IRMref:
66 if (op1 < nk || (i >= REF_BIAS ? op1 >= i : op1 <= i))
67 err = "IRMref op1 out of range";
68 break;
63 case IRMlit: break; 69 case IRMlit: break;
64 case IRMcst: lua_assert(i < REF_BIAS); 70 case IRMcst:
71 if (i >= REF_BIAS) { err = "constant in IR range"; break; }
65 if (irt_is64(ir->t) && ir->o != IR_KNULL) 72 if (irt_is64(ir->t) && ir->o != IR_KNULL)
66 i++; 73 i++;
67 continue; 74 continue;
68 } 75 }
69 switch (irm_op2(mode)) { 76 switch (irm_op2(mode)) {
70 case IRMnone: lua_assert(op2 == 0); break; 77 case IRMnone:
71 case IRMref: lua_assert(op2 >= nk); 78 if (op2) err = "IRMnone op2 used";
72 lua_assert(i >= REF_BIAS ? op2 < i : op2 > i); break; 79 break;
80 case IRMref:
81 if (op2 < nk || (i >= REF_BIAS ? op2 >= i : op2 <= i))
82 err = "IRMref op2 out of range";
83 break;
73 case IRMlit: break; 84 case IRMlit: break;
74 case IRMcst: lua_assert(0); break; 85 case IRMcst: err = "IRMcst op2"; break;
75 } 86 }
76 if (ir->prev) { 87 if (!err && ir->prev) {
77 lua_assert(ir->prev >= nk); 88 if (ir->prev < nk || (i >= REF_BIAS ? ir->prev >= i : ir->prev <= i))
78 lua_assert(i >= REF_BIAS ? ir->prev < i : ir->prev > i); 89 err = "chain out of range";
79 lua_assert(ir->o == IR_NOP || IR(ir->prev)->o == ir->o); 90 else if (ir->o != IR_NOP && IR(ir->prev)->o != ir->o)
91 err = "chain to different op";
80 } 92 }
93 lj_assertJ(!err, "bad IR %04d op %d(%04d,%04d): %s",
94 i-REF_BIAS,
95 ir->o,
96 irm_op1(mode) == IRMref ? op1-REF_BIAS : op1,
97 irm_op2(mode) == IRMref ? op2-REF_BIAS : op2,
98 err);
81 } 99 }
82} 100}
83 101
@@ -87,9 +105,10 @@ static void rec_check_slots(jit_State *J)
87 BCReg s, nslots = J->baseslot + J->maxslot; 105 BCReg s, nslots = J->baseslot + J->maxslot;
88 int32_t depth = 0; 106 int32_t depth = 0;
89 cTValue *base = J->L->base - J->baseslot; 107 cTValue *base = J->L->base - J->baseslot;
90 lua_assert(J->baseslot >= 1+LJ_FR2); 108 lj_assertJ(J->baseslot >= 1+LJ_FR2, "bad baseslot");
91 lua_assert(J->baseslot == 1+LJ_FR2 || (J->slot[J->baseslot-1] & TREF_FRAME)); 109 lj_assertJ(J->baseslot == 1+LJ_FR2 || (J->slot[J->baseslot-1] & TREF_FRAME),
92 lua_assert(nslots <= LJ_MAX_JSLOTS); 110 "baseslot does not point to frame");
111 lj_assertJ(nslots <= LJ_MAX_JSLOTS, "slot overflow");
93 for (s = 0; s < nslots; s++) { 112 for (s = 0; s < nslots; s++) {
94 TRef tr = J->slot[s]; 113 TRef tr = J->slot[s];
95 if (tr) { 114 if (tr) {
@@ -97,56 +116,65 @@ static void rec_check_slots(jit_State *J)
97 IRRef ref = tref_ref(tr); 116 IRRef ref = tref_ref(tr);
98 IRIns *ir = NULL; /* Silence compiler. */ 117 IRIns *ir = NULL; /* Silence compiler. */
99 if (!LJ_FR2 || ref || !(tr & (TREF_FRAME | TREF_CONT))) { 118 if (!LJ_FR2 || ref || !(tr & (TREF_FRAME | TREF_CONT))) {
100 lua_assert(ref >= J->cur.nk && ref < J->cur.nins); 119 lj_assertJ(ref >= J->cur.nk && ref < J->cur.nins,
120 "slot %d ref %04d out of range", s, ref - REF_BIAS);
101 ir = IR(ref); 121 ir = IR(ref);
102 lua_assert(irt_t(ir->t) == tref_t(tr)); 122 lj_assertJ(irt_t(ir->t) == tref_t(tr), "slot %d IR type mismatch", s);
103 } 123 }
104 if (s == 0) { 124 if (s == 0) {
105 lua_assert(tref_isfunc(tr)); 125 lj_assertJ(tref_isfunc(tr), "frame slot 0 is not a function");
106#if LJ_FR2 126#if LJ_FR2
107 } else if (s == 1) { 127 } else if (s == 1) {
108 lua_assert((tr & ~TREF_FRAME) == 0); 128 lj_assertJ((tr & ~TREF_FRAME) == 0, "bad frame slot 1");
109#endif 129#endif
110 } else if ((tr & TREF_FRAME)) { 130 } else if ((tr & TREF_FRAME)) {
111 GCfunc *fn = gco2func(frame_gc(tv)); 131 GCfunc *fn = gco2func(frame_gc(tv));
112 BCReg delta = (BCReg)(tv - frame_prev(tv)); 132 BCReg delta = (BCReg)(tv - frame_prev(tv));
113#if LJ_FR2 133#if LJ_FR2
114 if (ref) 134 lj_assertJ(!ref || ir_knum(ir)->u64 == tv->u64,
115 lua_assert(ir_knum(ir)->u64 == tv->u64); 135 "frame slot %d PC mismatch", s);
116 tr = J->slot[s-1]; 136 tr = J->slot[s-1];
117 ir = IR(tref_ref(tr)); 137 ir = IR(tref_ref(tr));
118#endif 138#endif
119 lua_assert(tref_isfunc(tr)); 139 lj_assertJ(tref_isfunc(tr),
120 if (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir)); 140 "frame slot %d is not a function", s-LJ_FR2);
121 lua_assert(s > delta + LJ_FR2 ? (J->slot[s-delta] & TREF_FRAME) 141 lj_assertJ(!tref_isk(tr) || fn == ir_kfunc(ir),
122 : (s == delta + LJ_FR2)); 142 "frame slot %d function mismatch", s-LJ_FR2);
143 lj_assertJ(s > delta + LJ_FR2 ? (J->slot[s-delta] & TREF_FRAME)
144 : (s == delta + LJ_FR2),
145 "frame slot %d broken chain", s-LJ_FR2);
123 depth++; 146 depth++;
124 } else if ((tr & TREF_CONT)) { 147 } else if ((tr & TREF_CONT)) {
125#if LJ_FR2 148#if LJ_FR2
126 if (ref) 149 lj_assertJ(!ref || ir_knum(ir)->u64 == tv->u64,
127 lua_assert(ir_knum(ir)->u64 == tv->u64); 150 "cont slot %d continuation mismatch", s);
128#else 151#else
129 lua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void)); 152 lj_assertJ(ir_kptr(ir) == gcrefp(tv->gcr, void),
153 "cont slot %d continuation mismatch", s);
130#endif 154#endif
131 lua_assert((J->slot[s+1+LJ_FR2] & TREF_FRAME)); 155 lj_assertJ((J->slot[s+1+LJ_FR2] & TREF_FRAME),
156 "cont slot %d not followed by frame", s);
132 depth++; 157 depth++;
133 } else { 158 } else {
134 if (tvisnumber(tv)) 159 /* Number repr. may differ, but other types must be the same. */
135 lua_assert(tref_isnumber(tr)); /* Could be IRT_INT etc., too. */ 160 lj_assertJ(tvisnumber(tv) ? tref_isnumber(tr) :
136 else 161 itype2irt(tv) == tref_type(tr),
137 lua_assert(itype2irt(tv) == tref_type(tr)); 162 "slot %d type mismatch: stack type %d vs IR type %d",
163 s, itypemap(tv), tref_type(tr));
138 if (tref_isk(tr)) { /* Compare constants. */ 164 if (tref_isk(tr)) { /* Compare constants. */
139 TValue tvk; 165 TValue tvk;
140 lj_ir_kvalue(J->L, &tvk, ir); 166 lj_ir_kvalue(J->L, &tvk, ir);
141 if (!(tvisnum(&tvk) && tvisnan(&tvk))) 167 lj_assertJ((tvisnum(&tvk) && tvisnan(&tvk)) ?
142 lua_assert(lj_obj_equal(tv, &tvk)); 168 (tvisnum(tv) && tvisnan(tv)) :
143 else 169 lj_obj_equal(tv, &tvk),
144 lua_assert(tvisnum(tv) && tvisnan(tv)); 170 "slot %d const mismatch: stack %016llx vs IR %016llx",
171 s, tv->u64, tvk.u64);
145 } 172 }
146 } 173 }
147 } 174 }
148 } 175 }
149 lua_assert(J->framedepth == depth); 176 lj_assertJ(J->framedepth == depth,
177 "frame depth mismatch %d vs %d", J->framedepth, depth);
150} 178}
151#endif 179#endif
152 180
@@ -182,7 +210,7 @@ static TRef getcurrf(jit_State *J)
182{ 210{
183 if (J->base[-1-LJ_FR2]) 211 if (J->base[-1-LJ_FR2])
184 return J->base[-1-LJ_FR2]; 212 return J->base[-1-LJ_FR2];
185 lua_assert(J->baseslot == 1+LJ_FR2); 213 lj_assertJ(J->baseslot == 1+LJ_FR2, "bad baseslot");
186 return sloadt(J, -1-LJ_FR2, IRT_FUNC, IRSLOAD_READONLY); 214 return sloadt(J, -1-LJ_FR2, IRT_FUNC, IRSLOAD_READONLY);
187} 215}
188 216
@@ -427,7 +455,8 @@ static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev,
427 TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode); 455 TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode);
428 TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode); 456 TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode);
429 int tc, dir = rec_for_direction(&tv[FORL_STEP]); 457 int tc, dir = rec_for_direction(&tv[FORL_STEP]);
430 lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); 458 lj_assertJ(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI,
459 "bad bytecode %d instead of FORI/JFORI", bc_op(*fori));
431 scev->t.irt = t; 460 scev->t.irt = t;
432 scev->dir = dir; 461 scev->dir = dir;
433 scev->stop = tref_ref(stop); 462 scev->stop = tref_ref(stop);
@@ -483,7 +512,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
483 IRT_NUM; 512 IRT_NUM;
484 for (i = FORL_IDX; i <= FORL_STEP; i++) { 513 for (i = FORL_IDX; i <= FORL_STEP; i++) {
485 if (!tr[i]) sload(J, ra+i); 514 if (!tr[i]) sload(J, ra+i);
486 lua_assert(tref_isnumber_str(tr[i])); 515 lj_assertJ(tref_isnumber_str(tr[i]), "bad FORI argument type");
487 if (tref_isstr(tr[i])) 516 if (tref_isstr(tr[i]))
488 tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0); 517 tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);
489 if (t == IRT_INT) { 518 if (t == IRT_INT) {
@@ -615,7 +644,8 @@ static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)
615static int rec_profile_need(jit_State *J, GCproto *pt, const BCIns *pc) 644static int rec_profile_need(jit_State *J, GCproto *pt, const BCIns *pc)
616{ 645{
617 GCproto *ppt; 646 GCproto *ppt;
618 lua_assert(J->prof_mode == 'f' || J->prof_mode == 'l'); 647 lj_assertJ(J->prof_mode == 'f' || J->prof_mode == 'l',
648 "bad profiler mode %c", J->prof_mode);
619 if (!pt) 649 if (!pt)
620 return 0; 650 return 0;
621 ppt = J->prev_pt; 651 ppt = J->prev_pt;
@@ -793,7 +823,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
793 BCReg cbase = (BCReg)frame_delta(frame); 823 BCReg cbase = (BCReg)frame_delta(frame);
794 if (--J->framedepth <= 0) 824 if (--J->framedepth <= 0)
795 lj_trace_err(J, LJ_TRERR_NYIRETL); 825 lj_trace_err(J, LJ_TRERR_NYIRETL);
796 lua_assert(J->baseslot > 1+LJ_FR2); 826 lj_assertJ(J->baseslot > 1+LJ_FR2, "bad baseslot for return");
797 gotresults++; 827 gotresults++;
798 rbase += cbase; 828 rbase += cbase;
799 J->baseslot -= (BCReg)cbase; 829 J->baseslot -= (BCReg)cbase;
@@ -817,7 +847,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
817 BCReg cbase = (BCReg)frame_delta(frame); 847 BCReg cbase = (BCReg)frame_delta(frame);
818 if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */ 848 if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */
819 lj_trace_err(J, LJ_TRERR_NYIRETL); 849 lj_trace_err(J, LJ_TRERR_NYIRETL);
820 lua_assert(J->baseslot > 1+LJ_FR2); 850 lj_assertJ(J->baseslot > 1+LJ_FR2, "bad baseslot for return");
821 rbase += cbase; 851 rbase += cbase;
822 J->baseslot -= (BCReg)cbase; 852 J->baseslot -= (BCReg)cbase;
823 J->base -= cbase; 853 J->base -= cbase;
@@ -844,7 +874,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
844 J->maxslot = cbase+(BCReg)nresults; 874 J->maxslot = cbase+(BCReg)nresults;
845 if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */ 875 if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */
846 J->framedepth--; 876 J->framedepth--;
847 lua_assert(J->baseslot > cbase+1+LJ_FR2); 877 lj_assertJ(J->baseslot > cbase+1+LJ_FR2, "bad baseslot for return");
848 J->baseslot -= cbase+1+LJ_FR2; 878 J->baseslot -= cbase+1+LJ_FR2;
849 J->base -= cbase+1+LJ_FR2; 879 J->base -= cbase+1+LJ_FR2;
850 } else if (J->parent == 0 && J->exitno == 0 && 880 } else if (J->parent == 0 && J->exitno == 0 &&
@@ -859,7 +889,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
859 emitir(IRTG(IR_RETF, IRT_PGC), trpt, trpc); 889 emitir(IRTG(IR_RETF, IRT_PGC), trpt, trpc);
860 J->retdepth++; 890 J->retdepth++;
861 J->needsnap = 1; 891 J->needsnap = 1;
862 lua_assert(J->baseslot == 1+LJ_FR2); 892 lj_assertJ(J->baseslot == 1+LJ_FR2, "bad baseslot for return");
863 /* Shift result slots up and clear the slots of the new frame below. */ 893 /* Shift result slots up and clear the slots of the new frame below. */
864 memmove(J->base + cbase, J->base-1-LJ_FR2, sizeof(TRef)*nresults); 894 memmove(J->base + cbase, J->base-1-LJ_FR2, sizeof(TRef)*nresults);
865 memset(J->base-1-LJ_FR2, 0, sizeof(TRef)*(cbase+1+LJ_FR2)); 895 memset(J->base-1-LJ_FR2, 0, sizeof(TRef)*(cbase+1+LJ_FR2));
@@ -907,12 +937,13 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
907 } /* Otherwise continue with another __concat call. */ 937 } /* Otherwise continue with another __concat call. */
908 } else { 938 } else {
909 /* Result type already specialized. */ 939 /* Result type already specialized. */
910 lua_assert(cont == lj_cont_condf || cont == lj_cont_condt); 940 lj_assertJ(cont == lj_cont_condf || cont == lj_cont_condt,
941 "bad continuation type");
911 } 942 }
912 } else { 943 } else {
913 lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */ 944 lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */
914 } 945 }
915 lua_assert(J->baseslot >= 1+LJ_FR2); 946 lj_assertJ(J->baseslot >= 1+LJ_FR2, "bad baseslot for return");
916} 947}
917 948
918/* -- Metamethod handling ------------------------------------------------- */ 949/* -- Metamethod handling ------------------------------------------------- */
@@ -1167,7 +1198,7 @@ static void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm)
1167 ix->tab = ix->val; 1198 ix->tab = ix->val;
1168 copyTV(J->L, &ix->tabv, &ix->valv); 1199 copyTV(J->L, &ix->tabv, &ix->valv);
1169 } else { 1200 } else {
1170 lua_assert(tref_iscdata(ix->key)); 1201 lj_assertJ(tref_iscdata(ix->key), "cdata expected");
1171 ix->tab = ix->key; 1202 ix->tab = ix->key;
1172 copyTV(J->L, &ix->tabv, &ix->keyv); 1203 copyTV(J->L, &ix->tabv, &ix->keyv);
1173 } 1204 }
@@ -1264,7 +1295,8 @@ static void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize)
1264 /* Got scalar evolution analysis results for this reference? */ 1295 /* Got scalar evolution analysis results for this reference? */
1265 if (ref == J->scev.idx) { 1296 if (ref == J->scev.idx) {
1266 int32_t stop; 1297 int32_t stop;
1267 lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD); 1298 lj_assertJ(irt_isint(J->scev.t) && ir->o == IR_SLOAD,
1299 "only int SCEV supported");
1268 stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]); 1300 stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]);
1269 /* Runtime value for stop of loop is within bounds? */ 1301 /* Runtime value for stop of loop is within bounds? */
1270 if ((uint64_t)stop + ofs < (uint64_t)asize) { 1302 if ((uint64_t)stop + ofs < (uint64_t)asize) {
@@ -1382,7 +1414,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1382 1414
1383 while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */ 1415 while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */
1384 /* Never call raw lj_record_idx() on non-table. */ 1416 /* Never call raw lj_record_idx() on non-table. */
1385 lua_assert(ix->idxchain != 0); 1417 lj_assertJ(ix->idxchain != 0, "bad usage");
1386 if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index)) 1418 if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index))
1387 lj_trace_err(J, LJ_TRERR_NOMM); 1419 lj_trace_err(J, LJ_TRERR_NOMM);
1388 handlemm: 1420 handlemm:
@@ -1466,10 +1498,10 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1466 emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_PGC), 1498 emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_PGC),
1467 xref, lj_ir_kkptr(J, niltvg(J2G(J)))); 1499 xref, lj_ir_kkptr(J, niltvg(J2G(J))));
1468 if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) { 1500 if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {
1469 lua_assert(hasmm); 1501 lj_assertJ(hasmm, "inconsistent metamethod handling");
1470 goto handlemm; 1502 goto handlemm;
1471 } 1503 }
1472 lua_assert(!hasmm); 1504 lj_assertJ(!hasmm, "inconsistent metamethod handling");
1473 if (oldv == niltvg(J2G(J))) { /* Need to insert a new key. */ 1505 if (oldv == niltvg(J2G(J))) { /* Need to insert a new key. */
1474 TRef key = ix->key; 1506 TRef key = ix->key;
1475 if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */ 1507 if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */
@@ -1575,7 +1607,7 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
1575 int needbarrier = 0; 1607 int needbarrier = 0;
1576 if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */ 1608 if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */
1577 TRef tr, kfunc; 1609 TRef tr, kfunc;
1578 lua_assert(val == 0); 1610 lj_assertJ(val == 0, "bad usage");
1579 if (!tref_isk(fn)) { /* Late specialization of current function. */ 1611 if (!tref_isk(fn)) { /* Late specialization of current function. */
1580 if (J->pt->flags >= PROTO_CLC_POLY) 1612 if (J->pt->flags >= PROTO_CLC_POLY)
1581 goto noconstify; 1613 goto noconstify;
@@ -1697,7 +1729,7 @@ static void rec_func_vararg(jit_State *J)
1697{ 1729{
1698 GCproto *pt = J->pt; 1730 GCproto *pt = J->pt;
1699 BCReg s, fixargs, vframe = J->maxslot+1+LJ_FR2; 1731 BCReg s, fixargs, vframe = J->maxslot+1+LJ_FR2;
1700 lua_assert((pt->flags & PROTO_VARARG)); 1732 lj_assertJ((pt->flags & PROTO_VARARG), "FUNCV in non-vararg function");
1701 if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS) 1733 if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS)
1702 lj_trace_err(J, LJ_TRERR_STACKOV); 1734 lj_trace_err(J, LJ_TRERR_STACKOV);
1703 J->base[vframe-1-LJ_FR2] = J->base[-1-LJ_FR2]; /* Copy function up. */ 1735 J->base[vframe-1-LJ_FR2] = J->base[-1-LJ_FR2]; /* Copy function up. */
@@ -1766,7 +1798,7 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
1766{ 1798{
1767 int32_t numparams = J->pt->numparams; 1799 int32_t numparams = J->pt->numparams;
1768 ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1 - LJ_FR2; 1800 ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1 - LJ_FR2;
1769 lua_assert(frame_isvarg(J->L->base-1)); 1801 lj_assertJ(frame_isvarg(J->L->base-1), "VARG in non-vararg frame");
1770 if (LJ_FR2 && dst > J->maxslot) 1802 if (LJ_FR2 && dst > J->maxslot)
1771 J->base[dst-1] = 0; /* Prevent resurrection of unrelated slot. */ 1803 J->base[dst-1] = 0; /* Prevent resurrection of unrelated slot. */
1772 if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */ 1804 if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */
@@ -1889,7 +1921,7 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
1889 TValue savetv[5]; 1921 TValue savetv[5];
1890 BCReg s; 1922 BCReg s;
1891 RecordIndex ix; 1923 RecordIndex ix;
1892 lua_assert(baseslot < topslot); 1924 lj_assertJ(baseslot < topslot, "bad CAT arg");
1893 for (s = baseslot; s <= topslot; s++) 1925 for (s = baseslot; s <= topslot; s++)
1894 (void)getslot(J, s); /* Ensure all arguments have a reference. */ 1926 (void)getslot(J, s); /* Ensure all arguments have a reference. */
1895 if (tref_isnumber_str(top[0]) && tref_isnumber_str(top[-1])) { 1927 if (tref_isnumber_str(top[0]) && tref_isnumber_str(top[-1])) {
@@ -2013,7 +2045,7 @@ void lj_record_ins(jit_State *J)
2013 if (bc_op(*J->pc) >= BC__MAX) 2045 if (bc_op(*J->pc) >= BC__MAX)
2014 return; 2046 return;
2015 break; 2047 break;
2016 default: lua_assert(0); break; 2048 default: lj_assertJ(0, "bad post-processing mode"); break;
2017 } 2049 }
2018 J->postproc = LJ_POST_NONE; 2050 J->postproc = LJ_POST_NONE;
2019 } 2051 }
@@ -2381,7 +2413,8 @@ void lj_record_ins(jit_State *J)
2381 J->loopref = J->cur.nins; 2413 J->loopref = J->cur.nins;
2382 break; 2414 break;
2383 case BC_JFORI: 2415 case BC_JFORI:
2384 lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL); 2416 lj_assertJ(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL,
2417 "JFORI does not point to JFORL");
2385 if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */ 2418 if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */
2386 lj_record_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J])); 2419 lj_record_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J]));
2387 /* Continue tracing if the loop is not entered. */ 2420 /* Continue tracing if the loop is not entered. */
@@ -2434,7 +2467,8 @@ void lj_record_ins(jit_State *J)
2434 rec_func_lua(J); 2467 rec_func_lua(J);
2435 break; 2468 break;
2436 case BC_JFUNCV: 2469 case BC_JFUNCV:
2437 lua_assert(0); /* Cannot happen. No hotcall counting for varag funcs. */ 2470 /* Cannot happen. No hotcall counting for varag funcs. */
2471 lj_assertJ(0, "unsupported vararg hotcall");
2438 break; 2472 break;
2439 2473
2440 case BC_FUNCC: 2474 case BC_FUNCC:
@@ -2494,11 +2528,11 @@ static const BCIns *rec_setup_root(jit_State *J)
2494 J->bc_min = pc; 2528 J->bc_min = pc;
2495 break; 2529 break;
2496 case BC_ITERL: 2530 case BC_ITERL:
2497 lua_assert(bc_op(pc[-1]) == BC_ITERC); 2531 lj_assertJ(bc_op(pc[-1]) == BC_ITERC, "no ITERC before ITERL");
2498 J->maxslot = ra + bc_b(pc[-1]) - 1; 2532 J->maxslot = ra + bc_b(pc[-1]) - 1;
2499 J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns); 2533 J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);
2500 pc += 1+bc_j(ins); 2534 pc += 1+bc_j(ins);
2501 lua_assert(bc_op(pc[-1]) == BC_JMP); 2535 lj_assertJ(bc_op(pc[-1]) == BC_JMP, "ITERL does not point to JMP+1");
2502 J->bc_min = pc; 2536 J->bc_min = pc;
2503 break; 2537 break;
2504 case BC_LOOP: 2538 case BC_LOOP:
@@ -2530,7 +2564,7 @@ static const BCIns *rec_setup_root(jit_State *J)
2530 pc++; 2564 pc++;
2531 break; 2565 break;
2532 default: 2566 default:
2533 lua_assert(0); 2567 lj_assertJ(0, "bad root trace start bytecode %d", bc_op(ins));
2534 break; 2568 break;
2535 } 2569 }
2536 return pc; 2570 return pc;