[llvm] 5617fb1 - [MLGO][NFC] Use std::map instead of DenseMap to avoid use after free
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 7 11:08:12 PST 2022
good idea, sending a follow up.
On Mon, Nov 7, 2022 at 11:07 AM David Blaikie <dblaikie at gmail.com> wrote:
> Might be worth a comment ath the FPICache declaration explaining that
> it does need std::map's invalidation (or non-invalidation) semantics?
>
> On Fri, Nov 4, 2022 at 4:07 PM Mircea Trofin via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> >
> >
> > Author: Mircea Trofin
> > Date: 2022-11-04T16:07:24-07:00
> > New Revision: 5617fb1411f765667c016b5b75daa9d1110c36af
> >
> > URL:
> https://github.com/llvm/llvm-project/commit/5617fb1411f765667c016b5b75daa9d1110c36af
> > DIFF:
> https://github.com/llvm/llvm-project/commit/5617fb1411f765667c016b5b75daa9d1110c36af.diff
> >
> > LOG: [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.
> >
> > Added:
> >
> >
> > Modified:
> > llvm/include/llvm/Analysis/MLInlineAdvisor.h
> > llvm/lib/Analysis/MLInlineAdvisor.cpp
> >
> > Removed:
> >
> >
> >
> >
> ################################################################################
> > diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
> b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
> > index 00e8d7d7dd4de..3db948d365c77 100644
> > --- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
> > +++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
> > @@ -69,7 +69,7 @@ class MLInlineAdvisor : public InlineAdvisor {
> > 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;
> >
> >
> > diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp
> b/llvm/lib/Analysis/MLInlineAdvisor.cpp
> > index f55de71ea98ae..a20c05243b773 100644
> > --- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
> > +++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
> > @@ -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";
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221107/a6a60f5d/attachment.html>
More information about the llvm-commits
mailing list