Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc6b32b

Browse files
committed
bug: Lua can generate wrong code in functions with too many constants
1 parent de96e26 commit fc6b32b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

bugs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,9 +3652,9 @@ It needs an "interceptor" 'memcmp' function that continues
36523652
reading memory after a difference is found.]],
36533653
patch = [[
36543654
2c2
3655-
< ** $Id: loslib.c,v 1.64 2016/04/18 13:06:55 roberto Exp roberto $
3655+
< ** $Id: bugs,v 1.149 2016/07/15 17:24:09 roberto Exp roberto $
36563656
---
3657-
> ** $Id: loslib.c,v 1.64 2016/04/18 13:06:55 roberto Exp $
3657+
> ** $Id: bugs,v 1.149 2016/07/15 17:24:09 roberto Exp roberto $
36583658
263c263,264
36593659
< for (option = LUA_STRFTIMEOPTIONS; *option != '\0'; option += oplen) {
36603660
---
@@ -3664,6 +3664,30 @@ patch = [[
36643664
}
36653665

36663666

3667+
Bug{
3668+
what = [[Lua can generate wrong code in functions with too many constants]],
3669+
report = [[Marco Schöpl, 2016/07/17]],
3670+
since = [[5.3.3]],
3671+
fix = nil,
3672+
example = [[See http://lua-users.org/lists/lua-l/2016-07/msg00303.html]],
3673+
patch = [[
3674+
--- lcode.c 2016/06/20 19:12:46 2.110
3675+
+++ lcode.c 2016/07/18 15:43:41
3676+
@@ -1018,8 +1018,8 @@
3677+
*/
3678+
static void codebinexpval (FuncState *fs, OpCode op,
3679+
expdesc *e1, expdesc *e2, int line) {
3680+
- int rk1 = luaK_exp2RK(fs, e1); /* both operands are "RK" */
3681+
- int rk2 = luaK_exp2RK(fs, e2);
3682+
+ int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
3683+
+ int rk1 = luaK_exp2RK(fs, e1);
3684+
freeexps(fs, e1, e2);
3685+
e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */
3686+
e1->k = VRELOCABLE; /* all those operations are relocatable */
3687+
]]
3688+
}
3689+
3690+
36673691
--[=[
36683692
Bug{
36693693
what = [[ ]],

lcode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp roberto $
2+
** $Id: lcode.c,v 2.110 2016/06/20 19:12:46 roberto Exp roberto $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -1015,11 +1015,14 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {
10151015
** (everything but logical operators 'and'/'or' and comparison
10161016
** operators).
10171017
** Expression to produce final result will be encoded in 'e1'.
1018+
** Because 'luaK_exp2RK' can free registers, its calls must be
1019+
** in "stack order" (that is, first on 'e2', which may have more
1020+
** recent registers to be released).
10181021
*/
10191022
static void codebinexpval (FuncState *fs, OpCode op,
10201023
expdesc *e1, expdesc *e2, int line) {
1021-
int rk1 = luaK_exp2RK(fs, e1); /* both operands are "RK" */
1022-
int rk2 = luaK_exp2RK(fs, e2);
1024+
int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
1025+
int rk1 = luaK_exp2RK(fs, e1);
10231026
freeexps(fs, e1, e2);
10241027
e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */
10251028
e1->k = VRELOCABLE; /* all those operations are relocatable */

0 commit comments

Comments
 (0)