Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL][SpecializeLayers] Fix incorrect CF leading to double free #7200

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,18 @@ struct SpecializeLayers {
for (auto hierPath : llvm::make_early_inc_range(
circuit.getBody().getOps<hw::HierPathOp>())) {
auto namepath = hierPath.getNamepath().getValue();
for (auto ref : namepath.drop_back()) {
if (removedSyms.contains(ref)) {
removedPaths.insert(SymbolTable::getSymbolName(hierPath));
hierPath->erase();
continue;
}
auto shouldDelete = [&](Attribute ref) {
return removedSyms.contains(ref);
};
if (llvm::any_of(namepath.drop_back(), shouldDelete)) {
removedPaths.insert(SymbolTable::getSymbolName(hierPath));
hierPath->erase();
continue;
}
// If we deleted the target of the hierpath, we don't need to add it to
// the list of removedPaths, since no annotation will be left around to
// reference this path.
if (removedSyms.contains(namepath.back()))
if (shouldDelete(namepath.back()))
hierPath->erase();
}

Expand Down
35 changes: 35 additions & 0 deletions test/Dialect/FIRRTL/specialize-layers.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,41 @@ firrtl.circuit "HierPathDelete" attributes {
firrtl.extmodule @Deleted() attributes {layers = [@Layer]}
}

// CHECK-LABEL: firrtl.circuit "HierPathDelete"
firrtl.circuit "HierPathDelete" attributes {
disable_layers = [@Layer]
} {
firrtl.layer @Layer bind { }

// CHECK-NOT: hw.hierpath private @hierpath1 [@HierPathDelete::@middle, @Middle::@leaf, @Leaf]
hw.hierpath private @hierpath1 [@HierPathDelete::@middle, @Middle::@leaf, @Leaf]
// CHECK-NOT: hw.hierpath private @hierpath2 [@HierPathDelete::@middle, @Middle::@leaf]
hw.hierpath private @hierpath2 [@HierPathDelete::@middle, @Middle::@leaf]
// CHECK-NOT: hw.hierpath private @hierpath3 [@Middle::@leaf, @Leaf]
hw.hierpath private @hierpath3 [@Middle::@leaf, @Leaf]
// CHECK-NOT: hw.hierpath private @hierpath4 [@Middle::@leaf]
hw.hierpath private @hierpath4 [@Middle::@leaf]

firrtl.module @HierPathDelete() {
firrtl.layerblock @Layer {
firrtl.instance middle sym @middle @Middle()
}
}

firrtl.module @Middle() {
firrtl.layerblock @Layer {
firrtl.instance leaf sym @leaf @Leaf()
}
}

firrtl.extmodule @Leaf()

// CHECK-NOT: hw.hierpath private @DeletedPath [@Deleted]
hw.hierpath private @DeletedPath [@Deleted]
firrtl.extmodule @Deleted() attributes {layers = [@Layer]}
}


//===----------------------------------------------------------------------===//
// Annotations
//===----------------------------------------------------------------------===//
Expand Down
Loading