Skip to content

odb: fix createNewFlatNet flat/modnet name collision with BTerm#9675

Open
openroad-ci wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-fix-insert-buffer-name-collision
Open

odb: fix createNewFlatNet flat/modnet name collision with BTerm#9675
openroad-ci wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-fix-insert-buffer-name-collision

Conversation

@openroad-ci
Copy link
Collaborator

Summary

  • createNewFlatNet() now always names the new net after the BTerm (port name), and renames any colliding flat net or modnet to a unique avoidance name first.
  • Fixes spurious assign statements and multi-driver errors in VerilogWriter output caused by remove_buffers leaving a BTerm on a mismatched net name with a stale modnet.
  • Affected hierarchical designs like bp_fe_top where Kepler LEC rejected multi-driver outputs.

Root Cause

When remove_buffers merges two port-named nets (both having BTerms), the survivor selection defaults to the input net. This causes:

  1. Flat net name mismatch: BTerm ends up on a net with a different port's name.
  2. Stale modnet: remove_buffers merges flat nets but NOT modnets — the modnet retains the old port name.

createNewFlatNet() previously only handled case 1 (and only when names matched). VerilogWriter uses modnet names (via dbNetwork::net()) for submodule instance pin connections, so the stale modnet caused multi-driver even after flat net naming was corrected.

Fix

In createNewFlatNet():

  • Always name the new net after the BTerm (regardless of current net name match).
  • Rename the original flat net if it collides with the port name.
  • Rename the modnet if it collides with the port name.
  • Both renames share a single unique avoidance name generated via makeNewNetName().

Test plan

  • All 37 InsertBuffer unit tests pass (including new Case33)
  • New Case33 test: hierarchical design reproducing remove_buffers + insertBufferBeforeLoad multi-driver scenario
  • Golden updates for Case1, Case3, Case9, Case10, Case12, Case13 (no more spurious assign)
  • DEF golden updates for buffer_ports8, buffer_ports9, buffer_ports10 (BTerm net name now matches port name)

🤖 Generated with Claude Code

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

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

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 addresses a net naming collision issue that occurs during buffer insertion, particularly after remove_buffers has run. The fix ensures that when a new net is created before a BTerm, it is always named after the BTerm, and any existing flat nets or modnets with conflicting names are renamed to avoid collisions. The changes are well-supported by a new test case that reproduces the bug scenario. My review includes a suggestion to refactor a portion of the logic for improved readability and maintainability, which aligns with general best practices.

Note: Security Review did not run due to the size of the PR.

Comment on lines 480 to 495
// Rename the original flat net if it has the same name as the port.
std::string avoidance_name;
if (bterm_name == block_->getBaseName(net_->getConstName())) {
avoidance_name = make_avoidance_name();
net_->rename(avoidance_name.c_str());
}

// Rename the modnet if it has the same name as the port.
dbModNet* load_mnet = bterm->getModNet();
if (load_mnet
&& std::string_view{load_mnet->getConstName()} == bterm_name) {
if (avoidance_name.empty()) {
avoidance_name = make_avoidance_name();
}
load_mnet->rename(avoidance_name.c_str());
}
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 logic for renaming the flat net and modnet to avoid collisions is correct, but it can be refactored for better readability and to make the intent clearer. You can determine if collisions exist for both the flat net and modnet first, and then perform the renames within a single conditional block. This avoids nested checks and separates collision detection from the renaming action.

    // Rename the original flat net and/or modnet if they have the same name as the port.
    const bool flat_net_collides = (bterm_name == block_->getBaseName(net_->getConstName()));
    dbModNet* load_mnet = bterm->getModNet();
    const bool mod_net_collides = (load_mnet
        && std::string_view{load_mnet->getConstName()} == bterm_name);

    if (flat_net_collides || mod_net_collides) {
      const std::string avoidance_name = make_avoidance_name();
      if (flat_net_collides) {
        net_->rename(avoidance_name.c_str());
      }
      if (mod_net_collides) {
        load_mnet->rename(avoidance_name.c_str());
      }
    }

When remove_buffers merges two port-named nets, a BTerm can end up on a
net with a different port's name. Additionally, the modnet retains the
original port name (stale). createNewFlatNet now always names the new
net after the BTerm and renames any colliding flat net or modnet first.

This fixes spurious assign statements and multi-driver errors in
VerilogWriter output that caused Kepler LEC failures in hierarchical
designs (e.g., bp_fe_top).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@openroad-ci openroad-ci force-pushed the secure-fix-insert-buffer-name-collision branch from f9b888f to 54a7105 Compare March 7, 2026 00:03
Refactor the flat net and modnet renaming logic to separate
collision detection from the renaming action. This improves
readability by determining collisions upfront and handling
renames within a single conditional block.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

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

@openroad-ci openroad-ci force-pushed the secure-fix-insert-buffer-name-collision branch from 54a7105 to 03a2d14 Compare March 7, 2026 00:13
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

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

@jhkim-pii jhkim-pii requested a review from maliberty March 7, 2026 04:21
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