From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Tue, 6 Dec 2011 14:10:56 +0100 Subject: [PATCH] Wrong code generation for some particular boolean expressions. (see also 9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comes from http://www.lua.org/bugs.html#5.1.4-3 reported by Brian Kelley on 15 Apr 2009. Example: -- print(((1 or false) and true) or false) --> 1, but should be 'true' -- Patch: (partial solution; see also 9) Signed-off-by: BenoƮt Burnichon --- src/lcode.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lcode.c b/src/lcode.c index cff626b..84f286b 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -544,15 +544,18 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { pc = NO_JUMP; /* always true; do nothing */ break; } - case VFALSE: { - pc = luaK_jump(fs); /* always jump */ - break; - } case VJMP: { invertjump(fs, e); pc = e->u.s.info; break; } + case VFALSE: { + if (!hasjumps(e)) { + pc = luaK_jump(fs); /* always jump */ + break; + } + /* else go through */ + } default: { pc = jumponcond(fs, e, 0); break; @@ -572,14 +575,17 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) { pc = NO_JUMP; /* always false; do nothing */ break; } - case VTRUE: { - pc = luaK_jump(fs); /* always jump */ - break; - } case VJMP: { pc = e->u.s.info; break; } + case VTRUE: { + if (!hasjumps(e)) { + pc = luaK_jump(fs); /* always jump */ + break; + } + /* else go through */ + } default: { pc = jumponcond(fs, e, 1); break;