Skip to content

Commit

Permalink
[LowerTypes] Fix a race condition (#4582)
Browse files Browse the repository at this point in the history
This PR fixes a race condition in LowerTypes with aggregate preservation mode. In the instance op lowering, linkage of referenced module is checked, however it is not allowed to read attributes from different threads.
  • Loading branch information
uenoku authored Jan 24, 2023
1 parent 1c38d70 commit cd0cae2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,12 @@ TypeLoweringVisitor::getPreservatinoModeForModule(FModuleLike module) {
// We cannot preserve external module ports.
if (!isa<FModuleOp>(module))
return PreserveAggregate::None;

// If `module` is a top-module, we have to lower ports. Don't read attributes
// of `module` since the attributes could be mutated in a different thread.
if (aggregatePreservationMode != PreserveAggregate::None &&
preservePublicTypes && cast<hw::HWModuleLike>(*module).isPublic())
preservePublicTypes &&
module->getParentOfType<CircuitOp>().getMainModule(&symTbl) == module)
return PreserveAggregate::None;
return aggregatePreservationMode;
}
Expand Down

0 comments on commit cd0cae2

Please sign in to comment.