15#ifndef LLVM_CLANG_ANALYSIS_RETAINSUMMARYMANAGER_H
16#define LLVM_CLANG_ANALYSIS_RETAINSUMMARYMANAGER_H
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/FoldingSet.h"
20#include "llvm/ADT/ImmutableMap.h"
27#include "llvm/ADT/STLExtras.h"
200 return RetEffect(
NoRet);
237 ID.AddInteger((
unsigned)
X.getKind());
238 ID.AddInteger((
unsigned)
X.getObjKind());
243 ID.AddInteger((
unsigned)
X.getKind());
244 ID.AddInteger((
unsigned)
X.getObjKind());
250 typedef std::pair<IdentifierInfo*, Selector> PairTy;
251 return DenseMapInfo<PairTy>::getHashValue(PairTy(
V.getIdentifier(),
300 : Args(A), DefaultArgEffect(defaultEff), Receiver(ReceiverEff),
301 This(ThisEff), Ret(R) {}
306 if (
const ArgEffect *AE = Args.lookup(idx))
309 return DefaultArgEffect;
313 Args = af.add(Args, idx, e);
318 DefaultArgEffect = E;
354 return Args ==
Other.Args && DefaultArgEffect ==
Other.DefaultArgEffect &&
359 void Profile(llvm::FoldingSetNodeID& ID)
const {
361 ID.Add(DefaultArgEffect);
369 return Args.isEmpty();
375 ArgEffect getDefaultArgEffect()
const {
return DefaultArgEffect; }
381 typedef llvm::DenseMap<ObjCSummaryKey, const RetainSummary *> MapTy;
390 MapTy::iterator I = M.find(K);
426 return I == M.end() ?
nullptr : I->second;
441 typedef llvm::DenseMap<const FunctionDecl*, const RetainSummary *>
446 typedef llvm::FoldingSetNodeWrapper<RetainSummary> CachedSummaryNode;
452 const bool ARCEnabled;
455 const bool TrackObjCAndCFObjects;
458 const bool TrackOSObjects;
461 FuncSummariesTy FuncSummaries;
465 ObjCMethodSummariesTy ObjCClassMethodSummaries;
468 ObjCMethodSummariesTy ObjCMethodSummaries;
472 llvm::BumpPtrAllocator BPAlloc;
475 ArgEffects::Factory AF;
487 llvm::FoldingSet<CachedSummaryNode> SimpleSummaries;
518 RetainSummary Summ(ScratchArgs, RetEff, DefaultEff, ReceiverEff, ThisEff);
519 return getPersistentSummary(Summ);
535 return getPersistentSummary(
540 void InitializeClassMethodSummaries();
541 void InitializeMethodSummaries();
544 ObjCClassMethodSummaries[S] = Summ;
548 ObjCMethodSummaries[S] = Summ;
551 void addClassMethSummary(
const char* Cls,
const char* name,
559 void addInstMethSummary(
const char* Cls,
const char* nullaryName,
566 template <
typename... Keywords>
567 void addMethodSummary(
IdentifierInfo *ClsII, ObjCMethodSummariesTy &Summaries,
573 template <
typename... Keywords>
574 void addInstMethSummary(
const char *Cls,
const RetainSummary *Summ,
576 addMethodSummary(&Ctx.Idents.get(Cls), ObjCMethodSummaries, Summ, Kws...);
579 template <
typename... Keywords>
580 void addClsMethSummary(
const char *Cls,
const RetainSummary *Summ,
582 addMethodSummary(&Ctx.Idents.get(Cls), ObjCClassMethodSummaries, Summ,
586 template <
typename... Keywords>
589 addMethodSummary(II, ObjCClassMethodSummaries, Summ, Kws...);
593 bool &AllowAnnotations);
605 bool &AllowAnnotations);
610 bool applyParamAnnotationEffect(
const ParmVarDecl *pd,
unsigned parm_idx,
617 : Ctx(ctx), ARCEnabled((bool)Ctx.getLangOpts().ObjCAutoRefCount),
618 TrackObjCAndCFObjects(trackObjCAndCFObjects),
619 TrackOSObjects(trackOSObjects), AF(BPAlloc),
623 :
RetEffect::MakeOwnedWhenTrackedReceiver()) {
624 InitializeClassMethodSummaries();
625 InitializeMethodSummaries();
642 std::optional<BehaviorSummary>
644 bool &hasTrustedImplementationAnnotation);
653 bool HasNonZeroCallbackArg=
false,
654 bool IsReceiverUnconsumedSelf=
false,
670 ObjCMethodSummariesTy &CachedSummaries);
681 std::optional<RetEffect> getRetEffectFromAnnotations(
QualType RetTy,
684 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
687 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
705 void updateSummaryForReceiverUnconsumedSelf(
const RetainSummary *&S);
718 std::optional<ObjKind> hasAnyEnabledAttrOf(
const Decl *D,
QualType QT);
720 template <
class T1,
class T2,
class... Others>
721 std::optional<ObjKind> hasAnyEnabledAttrOf(
const Decl *D,
QualType QT);
738 : Manager(mgr), RealSummary(real), ScratchSummary(*real), Accessed(
false) {}
742 RealSummary = Manager.getPersistentSummary(ScratchSummary);
747 return ScratchSummary;
752 return &ScratchSummary;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
An instance of this class corresponds to a call.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Decl - This represents one declaration (or definition), e.g.
Represents a function declaration or definition.
FunctionType - C99 6.7.5.3 - Function Declarators.
One of these records is kept for each identifier that is lexed.
This represents a decl that may have a name.
Represents an ObjC class declaration.
ObjCInterfaceDecl * getSuperClass() const
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a parameter to a function.
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
An ArgEffect summarizes the retain count behavior on an argument or receiver to a function or method.
ArgEffect withKind(ArgEffectKind NewK)
ObjKind getObjKind() const
bool operator==(const ArgEffect &Other) const
ArgEffect(ArgEffectKind K=DoNothing, ObjKind O=ObjKind::AnyObj)
ArgEffectKind getKind() const
const RetainSummary * find(const ObjCInterfaceDecl *D, Selector S)
const RetainSummary *& operator[](Selector S)
const RetainSummary * find(IdentifierInfo *II, Selector S)
const RetainSummary *& operator[](ObjCSummaryKey K)
A key identifying a summary.
ObjCSummaryKey(const ObjCInterfaceDecl *d, Selector s)
IdentifierInfo * getIdentifier() const
Selector getSelector() const
ObjCSummaryKey(IdentifierInfo *ii, Selector s)
ObjCSummaryKey(Selector s)
RetEffect summarizes a call's retain/release behavior with respect to its return value.
static RetEffect MakeNotOwned(ObjKind o)
ObjKind getObjKind() const
static RetEffect MakeOwned(ObjKind o)
@ OwnedSymbol
Indicates that the returned value is an owned (+1) symbol.
@ OwnedWhenTrackedReceiver
Indicates that the return value is an owned object when the receiver is also a tracked object.
@ NoRet
Indicates that no retain count information is tracked for the return value.
@ NotOwnedSymbol
Indicates that the returned value is an object with retain count semantics but that it is not owned (...
static RetEffect MakeNoRet()
static RetEffect MakeOwnedWhenTrackedReceiver()
static RetEffect MakeNoRetHard()
bool operator==(const RetEffect &Other) const
bool isTrustedReferenceCountImplementation(const Decl *FD)
std::optional< BehaviorSummary > canEval(const CallExpr *CE, const FunctionDecl *FD, bool &hasTrustedImplementationAnnotation)
static bool isKnownSmartPointer(QualType QT)
const RetainSummary * getSummary(AnyCall C, bool HasNonZeroCallbackArg=false, bool IsReceiverUnconsumedSelf=false, QualType ReceiverType={})
friend class RetainSummaryTemplate
RetEffect getObjAllocRetEffect() const
RetainSummaryManager(ASTContext &ctx, bool trackObjCAndCFObjects, bool trackOSObjects)
RetainSummaryTemplate(const RetainSummary *&real, RetainSummaryManager &mgr)
RetainSummary * operator->()
RetainSummary & operator*()
Summary for a function with respect to ownership changes.
void setRetEffect(RetEffect E)
setRetEffect - Set the effect of the return value of the call.
ArgEffect getThisEffect() const
void setDefaultArgEffect(ArgEffect E)
setDefaultArgEffect - Set the default argument effect.
RetainSummary(ArgEffects A, RetEffect R, ArgEffect defaultEff, ArgEffect ReceiverEff, ArgEffect ThisEff)
void addArg(ArgEffects::Factory &af, unsigned idx, ArgEffect e)
ArgEffect getReceiverEffect() const
getReceiverEffect - Returns the effect on the receiver of the call.
RetEffect getRetEffect() const
getRetEffect - Returns the effect on the return value of the call.
bool isSimple() const
A retain summary is simple if it has no ArgEffects other than the default.
ArgEffects getArgEffects() const
friend class RetainSummaryManager
ArgEffect getDefaultEffect() const
void setThisEffect(ArgEffect e)
Set the effect of the method on "this".
ArgEffect getArg(unsigned idx) const
getArg - Return the argument effect on the argument specified by idx (starting from 0).
void setReceiverEffect(ArgEffect e)
Sets the effect on the receiver of the message.
bool operator==(const RetainSummary &Other) const
Test if two retain summaries are identical.
void Profile(llvm::FoldingSetNodeID &ID) const
Profile this summary for inclusion in a FoldingSet.
llvm::ImmutableMap< unsigned, ArgEffect > ArgEffects
ArgEffects summarizes the effects of a function/method call on all of its arguments.
ObjKind
Determines the object kind of a tracked object.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
@ Generalized
Indicates that the tracked object is a generalized object.
@ CF
Indicates that the tracked object is a CF object.
@ AnyObj
Indicates that the tracked object could be a CF or Objective-C object.
@ ObjC
Indicates that the tracked object is an Objective-C object.
@ IncRef
The argument has its reference count increased by 1.
@ UnretainedOutParameter
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +0 v...
@ DoNothing
There is no effect.
@ RetainedOutParameter
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
@ RetainedOutParameterOnZero
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
@ MayEscape
The argument is treated as potentially escaping, meaning that even when its reference count hits 0 it...
@ StopTracking
All typestate tracking of the object ceases.
@ Dealloc
The argument is treated as if the referenced object was deallocated.
@ Autorelease
The argument is treated as if an -autorelease message had been sent to the referenced object.
@ RetainedOutParameterOnNonZero
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
@ DecRef
The argument has its reference count decreased by 1.
@ StopTrackingHard
All typestate tracking of the object ceases.
@ DecRefAndStopTrackingHard
Performs the combined functionality of DecRef and StopTrackingHard.
@ DecRefBridgedTransferred
The argument has its reference count decreased by 1 to model a transferred bridge cast under ARC.
The JSON file list parser is used to communicate input to InstallAPI.
static Selector getKeywordSelector(ASTContext &Ctx, const IdentifierInfos *...IIs)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Selector GetUnarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing an unary selector.
@ Template
We are parsing a template declaration.
Selector GetNullarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing a nullary selector.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
static unsigned getHashValue(const ObjCSummaryKey &V)
static bool isEqual(const ObjCSummaryKey &LHS, const ObjCSummaryKey &RHS)
static void Profile(const ArgEffect X, FoldingSetNodeID &ID)
static void Profile(const RetEffect &X, FoldingSetNodeID &ID)