[FIRRTL][LowerClass] Pre-allocate namespaces before caputring refs (#7102)

There has been a lifetime bug that caused an UAF crash. Heaps allocated by DenseMap could be invalided when DenseMap size grows.
This commit is contained in:
Hideto Ueno 2024-05-29 16:20:36 +09:00 committed by GitHub
parent 00edb48ed5
commit ce012c04a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -289,6 +289,13 @@ PathTracker::run(CircuitOp circuit, InstanceGraph &instanceGraph,
const SymbolTable &symbolTable,
const DenseMap<DistinctAttr, FModuleOp> &owningModules) {
SmallVector<PathTracker> trackers;
// First allocate module namespaces. Don't capture a namespace reference at
// this point since they could be invalidated when DenseMap grows.
for (auto *node : instanceGraph)
if (auto module = node->getModule<FModuleLike>())
(void)namespaces.get(module);
// Prepare workers.
for (auto *node : instanceGraph)
if (auto module = node->getModule<FModuleLike>())