aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2012-04-11 15:17:11 +0200
committerMike Pall <mike>2012-04-11 15:17:11 +0200
commit39112fd6fb219ba3164bb26ae7b823d6cff5ac20 (patch)
treecc87ae2af874e61364047551ed259054768c13ce
parent44876ec99f3a772e15aa7a8a9b5134356fc6cc16 (diff)
downloadluajit-39112fd6fb219ba3164bb26ae7b823d6cff5ac20.tar.gz
luajit-39112fd6fb219ba3164bb26ae7b823d6cff5ac20.tar.bz2
luajit-39112fd6fb219ba3164bb26ae7b823d6cff5ac20.zip
Fix bytecode JMP slot range after const + and/or optimization.
-rw-r--r--src/lj_parse.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c
index 0f32d121..2835aef0 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -269,20 +269,23 @@ static int jmp_novalue(FuncState *fs, BCPos list)
269/* Patch register of test instructions. */ 269/* Patch register of test instructions. */
270static int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg) 270static int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg)
271{ 271{
272 BCIns *ip = &fs->bcbase[pc >= 1 ? pc-1 : pc].ins; 272 BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc];
273 BCOp op = bc_op(*ip); 273 BCOp op = bc_op(ilp->ins);
274 if (op == BC_ISTC || op == BC_ISFC) { 274 if (op == BC_ISTC || op == BC_ISFC) {
275 if (reg != NO_REG && reg != bc_d(*ip)) { 275 if (reg != NO_REG && reg != bc_d(ilp->ins)) {
276 setbc_a(ip, reg); 276 setbc_a(&ilp->ins, reg);
277 } else { /* Nothing to store or already in the right register. */ 277 } else { /* Nothing to store or already in the right register. */
278 setbc_op(ip, op+(BC_IST-BC_ISTC)); 278 setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC));
279 setbc_a(ip, 0); 279 setbc_a(&ilp->ins, 0);
280 }
281 } else if (bc_a(ilp->ins) == NO_REG) {
282 if (reg == NO_REG) {
283 ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0);
284 } else {
285 setbc_a(&ilp->ins, reg);
286 if (reg >= bc_a(ilp[1].ins))
287 setbc_a(&ilp[1].ins, reg+1);
280 } 288 }
281 } else if (bc_a(*ip) == NO_REG) {
282 if (reg == NO_REG)
283 *ip = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0);
284 else
285 setbc_a(ip, reg);
286 } else { 289 } else {
287 return 0; /* Cannot patch other instructions. */ 290 return 0; /* Cannot patch other instructions. */
288 } 291 }
@@ -325,7 +328,7 @@ static void jmp_append(FuncState *fs, BCPos *l1, BCPos l2)
325 328
326/* Patch jump list and preserve produced values. */ 329/* Patch jump list and preserve produced values. */
327static void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget, 330static void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget,
328 BCReg reg, BCPos dtarget) 331 BCReg reg, BCPos dtarget)
329{ 332{
330 while (list != NO_JMP) { 333 while (list != NO_JMP) {
331 BCPos next = jmp_next(fs, list); 334 BCPos next = jmp_next(fs, list);