Author: chromatic
Date: Fri Nov 28 21:48:20 2008
New Revision: 33322
Modified:
trunk/compilers/imcc/optimizer.c
Log:
[IMCC] Avoided re-using a freed variable in register used_once() optimization
(not that the optimization works entirely, but it didn't entirely work before).
See CID #145 from Coverity Scan.
Modified: trunk/compilers/imcc/optimizer.c
==============================================================================
--- trunk/compilers/imcc/optimizer.c (original)
+++ trunk/compilers/imcc/optimizer.c Fri Nov 28 21:48:20 2008
@@ -1564,7 +1564,13 @@
if (r && (r->use_count == 1 && r->lhs_use_count == 1)) {
IMCC_debug(interp, DEBUG_OPT2, "used once '%I' deleted\n",
ins);
ins = delete_ins(unit, ins);
- ins = ins->prev ? ins->prev : unit->instructions;
+
+ /* find previous instruction or first instruction of this CU
+ * ... but only the latter if it wasn't deleted */
+ ins = ins->prev
+ ? ins->prev
+ : opt ? unit->instructions : NULL;
+
unit->ostat.deleted_ins++;
unit->ostat.used_once++;
opt++;