Fix discharge order of comparisons in Lua parser.

This commit is contained in:
Mike Pall 2012-04-09 14:48:27 +02:00
parent c3e1d727ca
commit d621a6ccc2

View File

@ -833,13 +833,14 @@ static void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)
} }
} else { } else {
uint32_t op = opr-OPR_LT+BC_ISLT; uint32_t op = opr-OPR_LT+BC_ISLT;
BCReg ra; BCReg ra, rd;
if ((op-BC_ISLT) & 1) { /* GT -> LT, GE -> LE */ if ((op-BC_ISLT) & 1) { /* GT -> LT, GE -> LE */
e1 = e2; e2 = eret; /* Swap operands. */ e1 = e2; e2 = eret; /* Swap operands. */
op = ((op-BC_ISLT)^3)+BC_ISLT; op = ((op-BC_ISLT)^3)+BC_ISLT;
} }
rd = expr_toanyreg(fs, e2);
ra = expr_toanyreg(fs, e1); ra = expr_toanyreg(fs, e1);
ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2)); ins = BCINS_AD(op, ra, rd);
} }
/* Using expr_free might cause asserts if the order is wrong. */ /* Using expr_free might cause asserts if the order is wrong. */
if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--; if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;