瀏覽代碼

patch for last bug

Roberto Ierusalimschy 18 年之前
父節點
當前提交
60bc151ed7
共有 1 個文件被更改,包括 39 次插入1 次删除
  1. 39 1
      bugs

+ 39 - 1
bugs

@@ -1252,7 +1252,45 @@ print(2 * v251.k1, v251.k1 * 2);   -- 2 2, OK
 v253=1;
 print(2 * v251.k1, v251.k1 * 2);   -- 1 2, ???
 ]],
-patch = [[no patch yet]],
+patch = [[
+*lcode.c:
+@@ -657,10 +657,16 @@
+   if (constfolding(op, e1, e2))
+     return;
+   else {
+-    int o1 = luaK_exp2RK(fs, e1);
+     int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
+-    freeexp(fs, e2);
+-    freeexp(fs, e1);
++    int o1 = luaK_exp2RK(fs, e1);
++    if (o1 > o2) {
++      freeexp(fs, e1);
++      freeexp(fs, e2);
++    }
++    else {
++      freeexp(fs, e2);
++      freeexp(fs, e1);
++    }
+     e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
+     e1->k = VRELOCABLE;
+   }
+@@ -718,10 +724,15 @@
+       luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */
+       break;
+     }
+-    default: {
++    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
++    case OPR_MOD: case OPR_POW: {
+       if (!isnumeral(v)) luaK_exp2RK(fs, v);
+       break;
+     }
++    default: {
++      luaK_exp2RK(fs, v);
++      break;
++    }
+   }
+ }
+]],
 }
 
 Bug{