@@ -291,6 +291,39 @@ TEST_F(ModuleFixture, test_find_modinst)
291291 auto minst2 = odb::dbModInst::create (master1, master2, " minst2" );
292292 EXPECT_EQ (block_->findModInst (" minst1/minst2" ), minst2);
293293}
294+
295+ // makeNewNetName must not hand out a name that already belongs to an
296+ // instance in the scope: a net/port and an instance cannot share a name in
297+ // one Verilog scope. OpenROAD promotes anonymous nets ("_NNNNN_") to
298+ // module boundary ports, and yosys/ABC name anonymous cells "_NNNNN_" too,
299+ // so without an instance-name check the promoted port collides with a leaf
300+ // or hierarchical instance -- illegal Verilog ("Instance has the same name
301+ // as port").
302+ TEST_F (ModuleFixture, makeNewNetName_avoids_instance_collision)
303+ {
304+ auto top = block_->getTopModule ();
305+ ASSERT_NE (top, nullptr );
306+
307+ // Leaf (dbInst) collision: an instance named "_42_" exists in scope.
308+ dbInst::create (block_, lib_->findMaster (" and2" ), " _42_" );
309+ std::string leaf = block_->makeNewNetName (
310+ top, " _42_" , dbNameUniquifyType::IF_NEEDED_WITH_UNDERSCORE );
311+ EXPECT_STRNE (block_->getBaseName (leaf.c_str ()), " _42_" )
312+ << " net name must not collide with leaf instance '_42_'" ;
313+
314+ // Hierarchical (dbModInst) collision: a module instance named "_99_".
315+ auto master = dbModule::create (block_, " anon_master" );
316+ dbModInst::create (top, master, " _99_" );
317+ std::string hier = block_->makeNewNetName (
318+ top, " _99_" , dbNameUniquifyType::IF_NEEDED_WITH_UNDERSCORE );
319+ EXPECT_STRNE (block_->getBaseName (hier.c_str ()), " _99_" )
320+ << " net name must not collide with module instance '_99_'" ;
321+
322+ // No collision: a fresh name is returned unchanged.
323+ std::string fresh = block_->makeNewNetName (
324+ top, " no_collision_here" , dbNameUniquifyType::IF_NEEDED_WITH_UNDERSCORE );
325+ EXPECT_STREQ (block_->getBaseName (fresh.c_str ()), " no_collision_here" );
326+ }
294327class DetailedFixture : public SimpleDbFixture
295328{
296329 protected:
0 commit comments