Skip to content

Commit ab811ec

Browse files
committed
odb: correctly update insts/modinsts/groups on dbGroup::destroy
Fixes #8040 Signed-off-by: Matt Liberty <[email protected]>
1 parent 6ff4ea2 commit ab811ec

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/odb/src/db/dbGroup.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,17 @@ void dbGroup::destroy(dbGroup* group)
489489
{
490490
_dbGroup* _group = (_dbGroup*) group;
491491
_dbBlock* block = (_dbBlock*) _group->getOwner();
492-
for (auto inst : group->getInsts()) {
493-
group->removeInst(inst);
492+
while (!group->getInsts().empty()) {
493+
group->removeInst(*group->getInsts().begin());
494494
}
495495
if (_group->region_.isValid()) {
496496
group->getRegion()->removeGroup(group);
497497
}
498-
for (auto modinst : group->getModInsts()) {
499-
group->removeModInst(modinst);
498+
while (!group->getModInsts().empty()) {
499+
group->removeModInst(*group->getModInsts().begin());
500500
}
501-
for (auto child : group->getGroups()) {
502-
group->removeGroup(child);
501+
while (!group->getGroups().empty()) {
502+
group->removeGroup(*group->getGroups().begin());
503503
}
504504
if (_group->_parent_group.isValid()) {
505505
group->getParentGroup()->removeGroup(group);

src/odb/test/test_group.tcl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ proc test_default { } {
5757
tearDown $db
5858
}
5959

60+
proc test_destroy { } {
61+
# Setup
62+
lassign [createSimpleDB] db lib
63+
set block [create1LevelBlock $db $lib [$db getChip]]
64+
set and2 [$lib findMaster "and2"]
65+
66+
set inst1 [odb::dbInst_create $block $and2 "inst1"]
67+
set inst2 [odb::dbInst_create $block $and2 "inst2"]
68+
69+
set group [odb::dbGroup_create $block "group"]
70+
$group addInst $inst1
71+
$group addInst $inst2
72+
73+
# Test action
74+
odb::dbGroup_destroy $group
75+
76+
# Verification
77+
assertStringEq [$inst1 getGroup] "NULL"
78+
assertStringEq [$inst2 getGroup] "NULL"
79+
tearDown $db
80+
}
81+
6082
test_default
83+
test_destroy
6184
puts "pass"
6285
exit 0

0 commit comments

Comments
 (0)