diff options
author | Mike Pall <mike> | 2024-07-03 23:45:16 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2024-07-03 23:45:16 +0200 |
commit | f602f0154b644211283cfeea92a570ca38f71947 (patch) | |
tree | d120da26a255e6e7c9dc28b9f42e36e28b6e404f | |
parent | f2a1cd43281361035149b6eedbd267b5e71d64d0 (diff) | |
download | luajit-f602f0154b644211283cfeea92a570ca38f71947.tar.gz luajit-f602f0154b644211283cfeea92a570ca38f71947.tar.bz2 luajit-f602f0154b644211283cfeea92a570ca38f71947.zip |
Fix predict_next() in parser (for real now).
Reported by Sergey Kaplun. #1226 #1054
-rw-r--r-- | src/lj_parse.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c index afdbcc3d..cb200663 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
@@ -2527,11 +2527,9 @@ static void parse_for_num(LexState *ls, GCstr *varname, BCLine line) | |||
2527 | */ | 2527 | */ |
2528 | static int predict_next(LexState *ls, FuncState *fs, BCPos pc) | 2528 | static int predict_next(LexState *ls, FuncState *fs, BCPos pc) |
2529 | { | 2529 | { |
2530 | BCIns ins; | 2530 | BCIns ins = fs->bcbase[pc].ins; |
2531 | GCstr *name; | 2531 | GCstr *name; |
2532 | cTValue *o; | 2532 | cTValue *o; |
2533 | if (pc >= fs->bclim) return 0; | ||
2534 | ins = fs->bcbase[pc].ins; | ||
2535 | switch (bc_op(ins)) { | 2533 | switch (bc_op(ins)) { |
2536 | case BC_MOV: | 2534 | case BC_MOV: |
2537 | if (bc_d(ins) >= fs->nactvar) return 0; | 2535 | if (bc_d(ins) >= fs->nactvar) return 0; |
@@ -2579,7 +2577,7 @@ static void parse_for_iter(LexState *ls, GCstr *indexname) | |||
2579 | line = ls->linenumber; | 2577 | line = ls->linenumber; |
2580 | assign_adjust(ls, 3, expr_list(ls, &e), &e); | 2578 | assign_adjust(ls, 3, expr_list(ls, &e), &e); |
2581 | bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */ | 2579 | bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */ |
2582 | isnext = (nvars <= 5 && predict_next(ls, fs, exprpc)); | 2580 | isnext = (nvars <= 5 && fs->pc > exprpc && predict_next(ls, fs, exprpc)); |
2583 | var_add(ls, 3); /* Hidden control variables. */ | 2581 | var_add(ls, 3); /* Hidden control variables. */ |
2584 | lex_check(ls, TK_do); | 2582 | lex_check(ls, TK_do); |
2585 | loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP); | 2583 | loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP); |