Skip to content

gpl: change size_t to int#9596

Open
openroad-ci wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:gpl_fix
Open

gpl: change size_t to int#9596
openroad-ci wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:gpl_fix

Conversation

@openroad-ci
Copy link
Collaborator

Fix bug introduced in PR #9534

Signed-off-by: LucasYuki <lucasyuki@yahoo.com.br>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +3602 to 3603
std::pair<odb::dbInst*, int> NesterovBaseCommon::destroyCbkGCell(
odb::dbInst* db_inst)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. The NesterovBase::destroyCbkGCell method returns a size_t index, and its failure value is static_cast<size_t>(-1).

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

clang-tidy review says "All clean, LGTM! 👍"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants