Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/mit/lua/dist/src lua: apply upstream bugfix for "Wr...
details: https://anonhg.NetBSD.org/src/rev/688f67a00f60
branches: trunk
changeset: 374296:688f67a00f60
user: nikita <nikita%NetBSD.org@localhost>
date: Mon Apr 17 19:19:00 2023 +0000
description:
lua: apply upstream bugfix for "Wrong code generation for constants in bitwise operations."
diffstat:
external/mit/lua/dist/src/lcode.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diffs (63 lines):
diff -r 95cd3529b968 -r 688f67a00f60 external/mit/lua/dist/src/lcode.c
--- a/external/mit/lua/dist/src/lcode.c Mon Apr 17 19:17:49 2023 +0000
+++ b/external/mit/lua/dist/src/lcode.c Mon Apr 17 19:19:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lcode.c,v 1.12 2023/04/16 20:46:17 nikita Exp $ */
+/* $NetBSD: lcode.c,v 1.13 2023/04/17 19:19:00 nikita Exp $ */
/*
** Id: lcode.c
@@ -1426,7 +1426,10 @@ static void finishbinexpval (FuncState *
*/
static void codebinexpval (FuncState *fs, OpCode op,
expdesc *e1, expdesc *e2, int line) {
- int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */
+ int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
+ /* 'e1' must be already in a register or it is a constant */
+ lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
+ e1->k == VNONRELOC || e1->k == VRELOC);
lua_assert(OP_ADD <= op && op <= OP_SHR);
finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
cast(TMS, (op - OP_ADD) + TM_ADD));
@@ -1513,7 +1516,7 @@ static void codecommutative (FuncState *
/*
-** Code bitwise operations; they are all associative, so the function
+** Code bitwise operations; they are all commutative, so the function
** tries to put an integer constant as the 2nd operand (a K operand).
*/
static void codebitwise (FuncState *fs, BinOpr opr,
@@ -1521,11 +1524,11 @@ static void codebitwise (FuncState *fs,
int flip = 0;
int v2;
OpCode op;
- if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
+ if (e1->k == VKINT && luaK_exp2K(fs, e1)) {
swapexps(e1, e2); /* 'e2' will be the constant operand */
flip = 1;
}
- else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */
+ else if (!(e2->k == VKINT && luaK_exp2K(fs, e2))) { /* no constants? */
op = cast(OpCode, opr + OP_ADD);
codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */
return;
@@ -1586,7 +1589,7 @@ static void codeeq (FuncState *fs, BinOp
op = OP_EQI;
r2 = im; /* immediate operand */
}
- else if (luaK_exp2RK(fs, e2)) { /* 1st expression is constant? */
+ else if (luaK_exp2RK(fs, e2)) { /* 2nd expression is constant? */
op = OP_EQK;
r2 = e2->u.info; /* constant index */
}
@@ -1651,7 +1654,8 @@ void luaK_infix (FuncState *fs, BinOpr o
case OPR_SHL: case OPR_SHR: {
if (!tonumeral(v, NULL))
luaK_exp2anyreg(fs, v);
- /* else keep numeral, which may be folded with 2nd operand */
+ /* else keep numeral, which may be folded or used as an immediate
+ operand */
break;
}
case OPR_EQ: case OPR_NE: {
Home |
Main Index |
Thread Index |
Old Index