From fc6b32bcaaf486beeffd35af44932a53f44d1c65 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Jul 2016 14:12:07 -0300 Subject: bug: Lua can generate wrong code in functions with too many constants --- lcode.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index 88a72df9..8bc85408 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp roberto $ +** $Id: lcode.c,v 2.110 2016/06/20 19:12:46 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -1015,11 +1015,14 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) { ** (everything but logical operators 'and'/'or' and comparison ** operators). ** Expression to produce final result will be encoded in 'e1'. +** Because 'luaK_exp2RK' can free registers, its calls must be +** in "stack order" (that is, first on 'e2', which may have more +** recent registers to be released). */ static void codebinexpval (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2, int line) { - int rk1 = luaK_exp2RK(fs, e1); /* both operands are "RK" */ - int rk2 = luaK_exp2RK(fs, e2); + int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */ + int rk1 = luaK_exp2RK(fs, e1); freeexps(fs, e1, e2); e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */ e1->k = VRELOCABLE; /* all those operations are relocatable */ -- cgit v1.2.3-55-g6feb