mbff: Use getLibertyCell (now testCell) instead of libertyCell.#10665
mbff: Use getLibertyCell (now testCell) instead of libertyCell.#10665Logikable wants to merge 2 commits into
Conversation
dbNetwork::getLibertyCell (now testCell) returns the TestCell if available. After 89f47ff, certain parts of the MBFF code began to compare the TestCell against the base cell. This causes a crash in GetPinMapping() in certain PDKs. Signed-off-by: Sean Luchen <seanluchen@google.com>
There was a problem hiding this comment.
Code Review
This pull request replaces the private getLibertyCell method with a public testCell method in dbNetwork and updates its usages, including replacing libertyCell calls in src/gpl/src/mbff.cpp. Feedback focuses on several instances in mbff.cpp where the returned lib_cell pointer from testCell is dereferenced or used without a null check, which could lead to potential crashes or undefined behavior if the cell does not have a corresponding liberty cell.
|
|
||
| const sta::Cell* cell = network_->dbToSta(inst->getMaster()); | ||
| const sta::LibertyCell* lib_cell = network_->libertyCell(cell); | ||
| const sta::LibertyCell* lib_cell = network_->testCell(cell); |
There was a problem hiding this comment.
The network_->testCell(cell) call can return nullptr if the cell does not have a corresponding liberty cell (e.g., for physical-only cells). Dereferencing lib_cell directly on the following line without a null check will cause a crash. We should add a defensive null check and return a fallback value.
const sta::LibertyCell* lib_cell = network_->testCell(cell);
if (lib_cell == nullptr) {
return d;
}| const sta::LibertyCell* lib_cell = network_->testCell(cell); | ||
| const auto& seqs = lib_cell->sequentials(); | ||
| if (!seqs.empty()) { | ||
| ret.func_idx = GetMatchingFunc(seqs.front().data(), inst, isTray); |
There was a problem hiding this comment.
The network_->testCell(cell) call can return nullptr. Dereferencing lib_cell directly on the following line to access sequentials() will cause a crash. We should wrap the access in a null check.
const sta::LibertyCell* lib_cell = network_->testCell(cell);
if (lib_cell != nullptr) {
const auto& seqs = lib_cell->sequentials();
if (!seqs.empty()) {
ret.func_idx = GetMatchingFunc(seqs.front().data(), inst, isTray);
}
}| const sta::LibertyCell* lib_cell = network_->testCell(cell); | ||
| sta::LibertyCellPortIterator port_itr(lib_cell); |
There was a problem hiding this comment.
The network_->testCell(cell) call can return nullptr. Passing a null pointer to sta::LibertyCellPortIterator will cause undefined behavior or a crash. We should add a null check and return an empty map if lib_cell is null.
const sta::LibertyCell* lib_cell = network_->testCell(cell);
if (lib_cell == nullptr) {
return {};
}
sta::LibertyCellPortIterator port_itr(lib_cell);|
Please add a unit test that would fail without this fix. |
Signed-off-by: Sean Luchen <seanluchen@google.com>
|
Done, PTAL. |
dbNetwork::getLibertyCell (now testCell) returns the TestCell if available. After 89f47ff, certain parts of the MBFF code began to compare the TestCell against the base cell. This causes a crash in GetPinMapping() in certain PDKs.