Skip to content

Commit 1892650

Browse files
committed
[ESI] Fix memory violation crash in AppID indexes
Bug tickled by a new PyCDE integration test, caught by valgrind.
1 parent 316ee41 commit 1892650

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/Dialect/ESI/AppID.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class AppIDIndex::ModuleAppIDs {
3030
/// bubbling up from an instance and is used to inform the conflicting entry
3131
/// error message.
3232
LogicalResult add(AppIDAttr id, Operation *op, bool inherited) {
33-
if (childAppIDPaths.find(id) != childAppIDPaths.end()) {
33+
auto existingIter = childAppIDPaths.find(id);
34+
if (existingIter != childAppIDPaths.end()) {
3435
return op->emitOpError("Found multiple identical AppIDs in same module")
35-
.attachNote(childAppIDPaths[id]->getLoc())
36+
.attachNote(existingIter->getSecond()->getLoc())
3637
<< "first AppID located here."
3738
<< (inherited ? " Must insert appid to differentiate one instance "
3839
"branch from the other."
@@ -222,10 +223,11 @@ FailureOr<ArrayAttr> AppIDIndex::getAppIDPathAttr(hw::HWModuleLike fromMod,
222223
FailureOr<const AppIDIndex::ModuleAppIDs *>
223224
AppIDIndex::buildIndexFor(hw::HWModuleLike mod) {
224225
// Memoize.
225-
ModuleAppIDs *&appIDs = containerAppIDs[mod];
226-
if (appIDs != nullptr)
227-
return appIDs;
228-
appIDs = new ModuleAppIDs();
226+
auto appidsIter = containerAppIDs.find(mod);
227+
if (appidsIter != containerAppIDs.end())
228+
return appidsIter->getSecond();
229+
ModuleAppIDs *appIDs = new ModuleAppIDs();
230+
containerAppIDs.try_emplace(mod, appIDs);
229231

230232
auto done = mod.walk([&](Operation *op) {
231233
// If an op has an appid attribute, add it to the index and terminate the

0 commit comments

Comments
 (0)