Skip to content

Commit 7957d4b

Browse files
davidjwooigcbot
authored andcommitted
Fix iterator invalidation bug
The iterator for FuncMD may be invalidated if adding a new entry to the MapVector causes a reallocation. This change fixes this issue by reserving space first(possibly causing a reallocation) and getting the iterator afterwards.
1 parent 173839c commit 7957d4b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

IGC/Compiler/MetaDataApi/IGCMetaDataHelper.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ void IGCMetaDataHelper::copyFunction(
5858
auto loc = FuncMD.find(OldFunc);
5959
if (loc != FuncMD.end())
6060
{
61+
if (FuncMD.find(NewFunc) == FuncMD.end())
62+
{
63+
// Invalidate iterator ahead of time so it doesn't happen during assignment
64+
FuncMD.reserve(FuncMD.size() + 1);
65+
loc = FuncMD.find(OldFunc);
66+
}
6167
FuncMD[NewFunc] = loc->second;
6268
}
6369
}

0 commit comments

Comments
 (0)