3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-06 22:23:23 +00:00

opt_dff: don't remove cells until all have been visited to prevent UAF

This commit is contained in:
George Rennie 2025-06-04 21:02:21 +01:00
parent 378add3723
commit 19cdbc5a0c

View file

@ -737,6 +737,7 @@ struct OptDffWorker
bool run_constbits() {
ModWalker modwalker(module->design, module);
QuickConeSat qcsat(modwalker);
std::vector<RTLIL::Cell*> cells_to_remove;
// Run as a separate sub-pass, so that we don't mutate (non-FF) cells under ModWalker.
bool did_something = false;
@ -830,7 +831,7 @@ struct OptDffWorker
if (!removed_sigbits.count(i))
keep_bits.push_back(i);
if (keep_bits.empty()) {
module->remove(cell);
cells_to_remove.emplace_back(cell);
did_something = true;
continue;
}
@ -840,6 +841,8 @@ struct OptDffWorker
did_something = true;
}
}
for (auto* cell : cells_to_remove)
module->remove(cell);
return did_something;
}
};