Skip to content

Commit 5617fb1

Browse files
committed
[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.
1 parent 2925333 commit 5617fb1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/include/llvm/Analysis/MLInlineAdvisor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MLInlineAdvisor : public InlineAdvisor {
6969
getSkipAdviceIfUnreachableCallsite(CallBase &CB);
7070
void print(raw_ostream &OS) const override;
7171

72-
mutable DenseMap<const Function *, FunctionPropertiesInfo> FPICache;
72+
mutable std::map<const Function *, FunctionPropertiesInfo> FPICache;
7373

7474
LazyCallGraph &CG;
7575

llvm/lib/Analysis/MLInlineAdvisor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
415415
<< " EdgesOfLastSeenNodes: " << EdgesOfLastSeenNodes << "\n";
416416
OS << "[MLInlineAdvisor] FPI:\n";
417417
for (auto I : FPICache) {
418-
OS << I.getFirst()->getName() << ":\n";
419-
I.getSecond().print(OS);
418+
OS << I.first->getName() << ":\n";
419+
I.second.print(OS);
420420
OS << "\n";
421421
}
422422
OS << "\n";

0 commit comments

Comments
 (0)