From 9b7987a9d1471ba94764286b28e0998f73deb46a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 11 Feb 2020 11:12:33 -0300 Subject: [PATCH] OP_LOADFALSE broken in two instructions --- lcode.c | 8 ++++---- ljumptab.h | 1 + lopcodes.c | 1 + lopcodes.h | 3 ++- lopnames.h | 1 + lvm.c | 6 +++++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lcode.c b/lcode.c index 332fdd00..35e0527f 100644 --- a/lcode.c +++ b/lcode.c @@ -872,9 +872,9 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { } -static int code_loadbool (FuncState *fs, int A, OpCode op, int jump) { +static int code_loadbool (FuncState *fs, int A, OpCode op) { luaK_getlabel(fs); /* those instructions may be jump targets */ - return luaK_codeABC(fs, op, A, jump, 0); + return luaK_codeABC(fs, op, A, 0, 0); } @@ -908,8 +908,8 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { int p_t = NO_JUMP; /* position of an eventual LOAD true */ if (need_value(fs, e->t) || need_value(fs, e->f)) { int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); - p_f = code_loadbool(fs, reg, OP_LOADFALSE, 1); /* skip next inst. */ - p_t = code_loadbool(fs, reg, OP_LOADTRUE, 0); + p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */ + p_t = code_loadbool(fs, reg, OP_LOADTRUE); /* jump around these booleans if 'e' is not a test */ luaK_patchtohere(fs, fj); } diff --git a/ljumptab.h b/ljumptab.h index 22e9575f..0edd79d5 100644 --- a/ljumptab.h +++ b/ljumptab.h @@ -31,6 +31,7 @@ static void *disptab[NUM_OPCODES] = { &&L_OP_LOADK, &&L_OP_LOADKX, &&L_OP_LOADFALSE, +&&L_OP_LFALSESKIP, &&L_OP_LOADTRUE, &&L_OP_LOADNIL, &&L_OP_GETUPVAL, diff --git a/lopcodes.c b/lopcodes.c index f5347a3c..4e983e08 100644 --- a/lopcodes.c +++ b/lopcodes.c @@ -25,6 +25,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ + ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ diff --git a/lopcodes.h b/lopcodes.h index 8fd52d18..d755870f 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -202,7 +202,8 @@ OP_LOADI,/* A sBx R[A] := sBx */ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ OP_LOADK,/* A Bx R[A] := K[Bx] */ OP_LOADKX,/* A R[A] := K[extra arg] */ -OP_LOADFALSE,/* A B R[A] := false; if (B) pc++ */ +OP_LOADFALSE,/* A R[A] := false */ +OP_LFALSESKIP,/*A R[A] := false; pc++ */ OP_LOADTRUE,/* A R[A] := true */ OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ OP_GETUPVAL,/* A B R[A] := UpValue[B] */ diff --git a/lopnames.h b/lopnames.h index a2097a74..f20147e3 100644 --- a/lopnames.h +++ b/lopnames.h @@ -16,6 +16,7 @@ static const char *const opnames[] = { "LOADK", "LOADKX", "LOADFALSE", + "LFALSESKIP", "LOADTRUE", "LOADNIL", "GETUPVAL", diff --git a/lvm.c b/lvm.c index 9c1ad47e..d802379c 100644 --- a/lvm.c +++ b/lvm.c @@ -1183,7 +1183,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_LOADFALSE) { setbfvalue(s2v(ra)); - if (GETARG_B(i)) pc++; /* if B, skip next instruction */ + vmbreak; + } + vmcase(OP_LFALSESKIP) { + setbfvalue(s2v(ra)); + pc++; /* skip next instruction */ vmbreak; } vmcase(OP_LOADTRUE) {