Fixed memory corruption in "opt_reduce" pass
authorClifford Wolf <clifford@clifford.at>
Fri, 25 Jul 2014 10:49:51 +0000 (12:49 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 25 Jul 2014 10:49:51 +0000 (12:49 +0200)
passes/opt/opt_reduce.cc

index 913855f48daaf032e65633991eda6e1901f4c987..0cc16ee6761dfeb0577549698f64cecc6dfedb8d 100644 (file)
@@ -312,12 +312,14 @@ struct OptReduceWorker
 
                        // merge identical inputs on $mux and $pmux cells
 
-                       for (auto &cell_it : module->cells)
-                       {
-                               RTLIL::Cell *cell = cell_it.second;
-                               if ((cell->type != "$mux" && cell->type != "$pmux" && cell->type != "$safe_pmux") || !design->selected(module, cell))
-                                       continue;
+                       std::vector<RTLIL::Cell*> cells;
 
+                       for (auto &it : module->cells)
+                               if ((it.second->type == "$mux" || it.second->type == "$pmux" || it.second->type == "$safe_pmux") && design->selected(module, it.second))
+                                       cells.push_back(it.second);
+
+                       for (auto cell : cells)
+                       {
                                // this optimization is to aggressive for most coarse-grain applications.
                                // but we always want it for multiplexers driving write enable ports.
                                if (do_fine || mem_wren_sigs.check_any(assign_map(cell->connections.at("\\Y"))))