[MLGO][NFC] Use std::map instead of DenseMap to avoid use after free

In `MLInlineAdvisor::getAdviceImpl`, we call `getCachedFPI` twice, once
for the caller, once for the callee, so the second may invalidate the
reference obtained by the first because the underlying implementation of
the cache is a `DenseMap`. `std::map` doesn't have that problem.
This commit is contained in:
Mircea Trofin 2022-11-04 16:05:10 -07:00
parent 292533324c
commit 5617fb1411
2 changed files with 3 additions and 3 deletions

View File

@ -69,7 +69,7 @@ private:
getSkipAdviceIfUnreachableCallsite(CallBase &CB);
void print(raw_ostream &OS) const override;
mutable DenseMap<const Function *, FunctionPropertiesInfo> FPICache;
mutable std::map<const Function *, FunctionPropertiesInfo> FPICache;
LazyCallGraph &CG;

View File

@ -415,8 +415,8 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
<< " EdgesOfLastSeenNodes: " << EdgesOfLastSeenNodes << "\n";
OS << "[MLInlineAdvisor] FPI:\n";
for (auto I : FPICache) {
OS << I.getFirst()->getName() << ":\n";
I.getSecond().print(OS);
OS << I.first->getName() << ":\n";
I.second.print(OS);
OS << "\n";
}
OS << "\n";