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"
219 : II(nullptr), S(
s) {}
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 return ObjCSummaryKey(DenseMapInfo<IdentifierInfo*>::getEmptyKey(),
251 DenseMapInfo<Selector>::getEmptyKey());
255 return ObjCSummaryKey(DenseMapInfo<IdentifierInfo*>::getTombstoneKey(),
256 DenseMapInfo<Selector>::getTombstoneKey());
260 typedef std::pair<IdentifierInfo*, Selector> PairTy;
261 return DenseMapInfo<PairTy>::getHashValue(PairTy(
V.getIdentifier(),
310 : Args(A), DefaultArgEffect(defaultEff), Receiver(ReceiverEff),
311 This(ThisEff), Ret(R) {}
316 if (
const ArgEffect *AE = Args.lookup(idx))
319 return DefaultArgEffect;
323 Args = af.add(Args, idx, e);
328 DefaultArgEffect =
E;
364 return Args ==
Other.Args && DefaultArgEffect ==
Other.DefaultArgEffect &&
369 void Profile(llvm::FoldingSetNodeID& ID)
const {
371 ID.Add(DefaultArgEffect);
379 return Args.isEmpty();
385 ArgEffect getDefaultArgEffect()
const {
return DefaultArgEffect; }
391 typedef llvm::DenseMap<ObjCSummaryKey, const RetainSummary *> MapTy;
400 MapTy::iterator I = M.find(K);
436 return I == M.end() ? nullptr : I->second;
451 typedef llvm::DenseMap<const FunctionDecl*, const RetainSummary *>
456 typedef llvm::FoldingSetNodeWrapper<RetainSummary> CachedSummaryNode;
462 const bool ARCEnabled;
465 const bool TrackObjCAndCFObjects;
468 const bool TrackOSObjects;
471 FuncSummariesTy FuncSummaries;
482 llvm::BumpPtrAllocator BPAlloc;
485 ArgEffects::Factory AF;
497 llvm::FoldingSet<CachedSummaryNode> SimpleSummaries;
528 RetainSummary Summ(ScratchArgs, RetEff, DefaultEff, ReceiverEff, ThisEff);
529 return getPersistentSummary(Summ);
545 return getPersistentSummary(
550 void InitializeClassMethodSummaries();
551 void InitializeMethodSummaries();
554 ObjCClassMethodSummaries[S] = Summ;
558 ObjCMethodSummaries[S] = Summ;
561 void addClassMethSummary(
const char* Cls,
const char* name,
569 void addInstMethSummary(
const char* Cls,
const char* nullaryName,
576 template <
typename... Keywords>
583 template <
typename... Keywords>
584 void addInstMethSummary(
const char *Cls,
const RetainSummary *Summ,
586 addMethodSummary(&Ctx.
Idents.
get(Cls), ObjCMethodSummaries, Summ, Kws...);
589 template <
typename... Keywords>
590 void addClsMethSummary(
const char *Cls,
const RetainSummary *Summ,
592 addMethodSummary(&Ctx.
Idents.
get(Cls), ObjCClassMethodSummaries, Summ,
596 template <
typename... Keywords>
599 addMethodSummary(II, ObjCClassMethodSummaries, Summ, Kws...);
603 bool &AllowAnnotations);
615 bool &AllowAnnotations);
620 bool applyParamAnnotationEffect(
const ParmVarDecl *pd,
unsigned parm_idx,
627 : Ctx(ctx), ARCEnabled((
bool)Ctx.getLangOpts().ObjCAutoRefCount),
628 TrackObjCAndCFObjects(trackObjCAndCFObjects),
629 TrackOSObjects(trackOSObjects), AF(BPAlloc),
633 :
RetEffect::MakeOwnedWhenTrackedReceiver()) {
634 InitializeClassMethodSummaries();
635 InitializeMethodSummaries();
652 std::optional<BehaviorSummary>
654 bool &hasTrustedImplementationAnnotation);
663 bool HasNonZeroCallbackArg=
false,
664 bool IsReceiverUnconsumedSelf=
false,
680 ObjCMethodSummariesTy &CachedSummaries);
691 std::optional<RetEffect> getRetEffectFromAnnotations(
QualType RetTy,
694 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
697 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
715 void updateSummaryForReceiverUnconsumedSelf(
const RetainSummary *&S);
728 std::optional<ObjKind> hasAnyEnabledAttrOf(
const Decl *
D,
QualType QT);
730 template <
class T1,
class T2,
class... Others>
731 std::optional<ObjKind> hasAnyEnabledAttrOf(
const Decl *
D,
QualType QT);
748 : Manager(mgr), RealSummary(real), ScratchSummary(*real), Accessed(
false) {}
752 RealSummary = Manager.getPersistentSummary(ScratchSummary);
757 return ScratchSummary;
762 return &ScratchSummary;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
__device__ __2f16 float __ockl_bool s
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.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
This represents a decl that may have a name.
Represents an ObjC class declaration.
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={})
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
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)
Selector GetUnarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing an unary selector.
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 ObjCSummaryKey getEmptyKey()
static bool isEqual(const ObjCSummaryKey &LHS, const ObjCSummaryKey &RHS)
static ObjCSummaryKey getTombstoneKey()
static void Profile(const ArgEffect X, FoldingSetNodeID &ID)
static void Profile(const RetEffect &X, FoldingSetNodeID &ID)