Author: leo
Date: Sun Mar 12 09:45:11 2006
New Revision: 11879
Modified:
trunk/compilers/imcc/optimizer.c
Log:
fix invalid mem access in branch_cond_loop_swap
Modified: trunk/compilers/imcc/optimizer.c
==============================================================================
--- trunk/compilers/imcc/optimizer.c (original)
+++ trunk/compilers/imcc/optimizer.c Sun Mar 12 09:45:11 2006
@@ -998,12 +998,12 @@
regs[get_branch_regno(cond)] =
mk_label_address(interp, str_dup(label));
tmp = INS(interp, unit, (char*)neg_op, "", regs, args, 0, 0);
- subst_ins(unit, branch, tmp, 1);
IMCC_debug(interp, DEBUG_OPT1,
"loop %s -> %s converted to post-test, added label %s\n",
branch->r[0]->name, get_branch_reg(cond)->name, label);
+ subst_ins(unit, branch, tmp, 1);
ostat.branch_cond_loop++;
changed = 1;
}
@@ -1032,7 +1032,7 @@
static int
branch_cond_loop(Interp *interpreter, IMC_Unit * unit)
{
- Instruction *ins, *cond, *end, *start;
+ Instruction *ins, *cond, *end, *start, *prev;
SymReg * r;
int changed = 0, found;
@@ -1070,7 +1070,15 @@
char *lbl = get_branch_reg(cond)->name;
r = get_sym(lbl);
if (r && (r->type & VTADDRESS) && r->first_ins == end) {
- changed |= branch_cond_loop_swap(interpreter, unit,
ins, start, cond);
+ /* the current ins is replaced - remember prev
+ * and set ins again after the changes
+ */
+ prev = ins->prev;
+ if (!prev)
+ continue;
+ changed |= branch_cond_loop_swap(interpreter,
+ unit, ins, start, cond);
+ ins = prev->next;
}
}
}