gpl: change size_t to int#9596
gpl: change size_t to int#9596openroad-ci wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
Conversation
Signed-off-by: LucasYuki <lucasyuki@yahoo.com.br>
There was a problem hiding this comment.
Code Review
This pull request attempts to fix a bug related to destroyCbkGCell's return value. However, changing the return type to int contradicts the established pattern for size_t indices and static_cast<size_t>(-1) as a failure sentinel, as outlined in our rules. This change also introduces potential narrowing conversions. I've provided a comment suggesting adherence to the existing pattern or a more robust refactoring using std::optional.
| std::pair<odb::dbInst*, int> NesterovBaseCommon::destroyCbkGCell( | ||
| odb::dbInst* db_inst) |
There was a problem hiding this comment.
The rule for NesterovBase::destroyCbkGCell states that its return value, which is an index of type size_t, should be checked against static_cast<size_t>(-1) for failure. Therefore, changing the return type's second element to int to handle a -1 sentinel is not aligned with this established pattern and introduces a potential narrowing conversion (lines 3630 and 3632) where a size_t index is converted to an int. For very large designs where the number of g-cells could exceed INT_MAX, this might lead to data loss or undefined behavior.
If the intention is to use -1 as a sentinel, it should be static_cast<size_t>(-1) when returning a size_t.
A more robust long-term solution would be to refactor the return type to avoid using a sentinel value like static_cast<size_t>(-1). For example, using std::optional<std::pair<odb::dbInst*, size_t>> could provide a safer and clearer interface.
References
- The
NesterovBase::destroyCbkGCellmethod returns asize_tindex, and its failure value isstatic_cast<size_t>(-1).
|
clang-tidy review says "All clean, LGTM! 👍" |
Fix bug introduced in PR #9534