Skip to content

Fix segmentation fault when selecting instance in debug mode#9557

Open
krrish175-byte wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
krrish175-byte:fix/gpl-debug-select-inst
Open

Fix segmentation fault when selecting instance in debug mode#9557
krrish175-byte wants to merge 1 commit intoThe-OpenROAD-Project:masterfrom
krrish175-byte:fix/gpl-debug-select-inst

Conversation

@krrish175-byte
Copy link
Contributor

Description

Fixes a segmentation fault that occurs when trying to select an instance in GPL debug mode. This regression was introduced after a previous fix that added region-aware instance selection logic.

Fixes #9017

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 fixes a segmentation fault that occurs when selecting an instance in debug mode. The changes involve moving a loop to be guarded by a null check on the instance pointer and adding boundary checks before accessing a vector of NesterovBase objects. The fixes appear correct and address the reported issue. I've noted an opportunity to refactor duplicated code into a helper function to improve maintainability.

Comment on lines +396 to +405
size_t nb_index = 0;
if (nb_selected_index_ != kInvalidIndex) {
nb_index = nb_selected_index_;
} else {
} else if (!nbVec_.empty()) {
logger_->warn(
utl::GPL, 317, "Selected instance not found in any NesterovBase");
}
if (nb_index >= nbVec_.size()) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for determining nb_index is duplicated in reportSelected() at lines 530-539. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a helper function. A free function within an anonymous namespace would be a good approach, following the repository's general rules.

For example:

namespace {
std::optional<size_t> getSelectedNesterovBaseIndex(
    size_t nb_selected_index,
    const std::vector<std::shared_ptr<gpl::NesterovBase>>& nbVec,
    utl::Logger* logger,
    int msg_id)
{
    size_t nb_index = 0;
    if (nb_selected_index != gpl::GraphicsImpl::kInvalidIndex) {
        nb_index = nb_selected_index;
    } else if (!nbVec.empty()) {
        logger->warn(
            utl::GPL, msg_id, "Selected instance not found in any NesterovBase");
    }

    if (nb_index >= nbVec.size()) {
        return std::nullopt;
    }
    return nb_index;
}
} // namespace

This helper could then be called from both drawNesterov and reportSelected.

References
  1. Helper logic should be defined as a free function in a namespace rather than as a local lambda within a function.

Fix three issues that caused segmentation faults in GPL debug mode:

1. In debugForNesterovPlace(), the nbVec_ search for the selected
   instance was outside the 'if (inst)' guard, causing
   cell_handle->contains(nullptr) to be called when no debug instance
   was specified.

2. In drawNesterov(), accessing nbVec_[nb_index] for gradient drawing
   without checking that nb_index is within bounds of nbVec_.

3. In reportSelected(), same missing bounds check on nbVec_[nb_index].

Fixes The-OpenROAD-Project#9017

Signed-off-by: Krrish Biswas <krrish175byte@gmail.com>
Signed-off-by: krrish175-byte <krrishbiswas175@gmail.com>
@krrish175-byte krrish175-byte force-pushed the fix/gpl-debug-select-inst branch from 2eff4b5 to f95968a Compare February 26, 2026 18:52
@maliberty maliberty requested a review from gudeh February 26, 2026 19:44
@gudeh
Copy link
Contributor

gudeh commented Mar 2, 2026

Hi @krrish175-byte, thanks for your contribution! Were you able to reproduce the issue? I don't remember what/when the issue is triggered exactly. I tried but couldn't reproduce the issue with master version on my end.

@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.

gpl: debug select inst bug

2 participants