Go to the documentation of this file.
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"
29 using namespace clang;
133 return K == Other.K && O == Other.O;
185 return K == Other.K && O == Other.O;
218 : II(nullptr), S(
s) {}
227 using namespace ento;
236 ID.AddInteger((
unsigned)
X.getKind());
237 ID.AddInteger((
unsigned)
X.getObjKind());
242 ID.AddInteger((
unsigned)
X.getKind());
243 ID.AddInteger((
unsigned)
X.getObjKind());
249 return ObjCSummaryKey(DenseMapInfo<IdentifierInfo*>::getEmptyKey(),
250 DenseMapInfo<Selector>::getEmptyKey());
254 return ObjCSummaryKey(DenseMapInfo<IdentifierInfo*>::getTombstoneKey(),
255 DenseMapInfo<Selector>::getTombstoneKey());
259 typedef std::pair<IdentifierInfo*, Selector> PairTy;
260 return DenseMapInfo<PairTy>::getHashValue(PairTy(
V.getIdentifier(),
309 : Args(A), DefaultArgEffect(defaultEff), Receiver(ReceiverEff),
315 if (
const ArgEffect *AE = Args.lookup(idx))
318 return DefaultArgEffect;
322 Args = af.add(Args, idx, e);
327 DefaultArgEffect = E;
363 return Args == Other.Args && DefaultArgEffect == Other.DefaultArgEffect &&
364 Receiver == Other.Receiver &&
This == Other.This &&
Ret == Other.Ret;
370 ID.Add(DefaultArgEffect);
378 return Args.isEmpty();
384 ArgEffect getDefaultArgEffect()
const {
return DefaultArgEffect; }
390 typedef llvm::DenseMap<ObjCSummaryKey, const RetainSummary *>
MapTy;
399 MapTy::iterator I = M.find(K);
435 return I == M.end() ? nullptr : I->second;
450 typedef llvm::DenseMap<const FunctionDecl*, const RetainSummary *>
455 typedef llvm::FoldingSetNodeWrapper<RetainSummary> CachedSummaryNode;
461 const bool ARCEnabled;
464 const bool TrackObjCAndCFObjects;
467 const bool TrackOSObjects;
470 FuncSummariesTy FuncSummaries;
481 llvm::BumpPtrAllocator BPAlloc;
484 ArgEffects::Factory AF;
496 llvm::FoldingSet<CachedSummaryNode> SimpleSummaries;
527 RetainSummary Summ(ScratchArgs, RetEff, DefaultEff, ReceiverEff, ThisEff);
528 return getPersistentSummary(Summ);
544 return getPersistentSummary(
549 void InitializeClassMethodSummaries();
550 void InitializeMethodSummaries();
553 ObjCClassMethodSummaries[S] = Summ;
557 ObjCMethodSummaries[S] = Summ;
560 void addClassMethSummary(
const char* Cls,
const char*
name,
568 void addInstMethSummary(
const char* Cls,
const char* nullaryName,
575 template <
typename... Keywords>
582 template <
typename... Keywords>
583 void addInstMethSummary(
const char *Cls,
const RetainSummary *Summ,
585 addMethodSummary(&Ctx.
Idents.
get(Cls), ObjCMethodSummaries, Summ, Kws...);
588 template <
typename... Keywords>
589 void addClsMethSummary(
const char *Cls,
const RetainSummary *Summ,
591 addMethodSummary(&Ctx.
Idents.
get(Cls), ObjCClassMethodSummaries, Summ,
595 template <
typename... Keywords>
598 addMethodSummary(II, ObjCClassMethodSummaries, Summ, Kws...);
602 bool &AllowAnnotations);
614 bool &AllowAnnotations);
619 bool applyParamAnnotationEffect(
const ParmVarDecl *pd,
unsigned parm_idx,
626 : Ctx(ctx), ARCEnabled((
bool)Ctx.getLangOpts().ObjCAutoRefCount),
627 TrackObjCAndCFObjects(trackObjCAndCFObjects),
628 TrackOSObjects(trackOSObjects), AF(BPAlloc),
632 :
RetEffect::MakeOwnedWhenTrackedReceiver()) {
633 InitializeClassMethodSummaries();
634 InitializeMethodSummaries();
652 bool &hasTrustedImplementationAnnotation);
656 static bool isKnownSmartPointer(
QualType QT);
658 bool isTrustedReferenceCountImplementation(
const Decl *FD);
661 bool HasNonZeroCallbackArg=
false,
662 bool IsReceiverUnconsumedSelf=
false,
678 ObjCMethodSummariesTy &CachedSummaries);
692 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
695 void updateSummaryFromAnnotations(
const RetainSummary *&Summ,
713 void updateSummaryForReceiverUnconsumedSelf(
const RetainSummary *&S);
728 template <
class T1,
class T2,
class... Others>
746 : Manager(mgr), RealSummary(real), ScratchSummary(*real), Accessed(
false) {}
750 RealSummary = Manager.getPersistentSummary(ScratchSummary);
755 return ScratchSummary;
760 return &ScratchSummary;
Represents an ObjC class declaration.
YAML serialization mapping.
@ RetainedOutParameter
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
@ CF
Indicates that the tracked object is a CF object.
RetainSummary * operator->()
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
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.
@ NotOwnedSymbol
Indicates that the returned value is an object with retain count semantics but that it is not owned (...
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
This represents a decl that may have a name.
static Selector getKeywordSelector(ASTContext &Ctx, IdentifierInfos *... IIs)
void Profile(llvm::FoldingSetNodeID &ID) const
Profile this summary for inclusion in a FoldingSet.
ArgEffectKind getKind() const
A (possibly-)qualified type.
Represents a parameter to a function.
void setThisEffect(ArgEffect e)
Set the effect of the method on "this".
static RetEffect MakeNoRet()
@ DecRefAndStopTrackingHard
Performs the combined functionality of DecRef and StopTrackingHard.
@ OwnedWhenTrackedReceiver
Indicates that the return value is an owned object when the receiver is also a tracked object.
FunctionType - C99 6.7.5.3 - Function Declarators.
Selector getSelector() const
const RetainSummary * find(const ObjCInterfaceDecl *D, Selector S)
@ Autorelease
The argument is treated as if an -autorelease message had been sent to the referenced object.
static RetEffect MakeNoRetHard()
static void Profile(const ArgEffect X, FoldingSetNodeID &ID)
void addArg(ArgEffects::Factory &af, unsigned idx, ArgEffect e)
static RetEffect MakeOwned(ObjKind o)
An instance of this class corresponds to a call.
ObjKind getObjKind() const
@ DoNothing
There is no effect.
@ MayEscape
The argument is treated as potentially escaping, meaning that even when its reference count hits 0 it...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Selector GetUnarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing an unary selector.
static ObjCSummaryKey getEmptyKey()
RetEffect getRetEffect() const
getRetEffect - Returns the effect on the return value of the call.
RetainSummaryManager(ASTContext &ctx, bool trackObjCAndCFObjects, bool trackOSObjects)
ArgEffect getReceiverEffect() const
getReceiverEffect - Returns the effect on the receiver of the call.
ArgEffect getThisEffect() const
llvm::DenseMap< Stmt *, Stmt * > MapTy
void setDefaultArgEffect(ArgEffect E)
setDefaultArgEffect - Set the default argument effect.
const RetainSummary *& operator[](ObjCSummaryKey K)
bool operator==(const RetainSummary &Other) const
Test if two retain summaries are identical.
static ObjCSummaryKey getTombstoneKey()
@ StopTracking
All typestate tracking of the object ceases.
An expression that sends a message to the given Objective-C object or class.
@ Dealloc
The argument is treated as if the referenced object was deallocated.
ArgEffect getDefaultEffect() const
@ DecRef
The argument has its reference count decreased by 1.
RetainSummaryTemplate(const RetainSummary *&real, RetainSummaryManager &mgr)
void setReceiverEffect(ArgEffect e)
Sets the effect on the receiver of the message.
void setRetEffect(RetEffect E)
setRetEffect - Set the effect of the return value of the call.
@ Generalized
Indicates that the tracked object is a generalized object.
Decl - This represents one declaration (or definition), e.g.
@ AnyObj
Indicates that the tracked object could be a CF or Objective-C object.
bool operator==(const ArgEffect &Other) const
@ ObjC
Indicates that the tracked object is an Objective-C object.
ObjCSummaryKey(Selector s)
ObjCInterfaceDecl * getSuperClass() const
ObjCSummaryKey(IdentifierInfo *ii, Selector s)
@ StopTrackingHard
All typestate tracking of the object ceases.
Summary for a function with respect to ownership changes.
@ RetainedOutParameterOnNonZero
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
One of these records is kept for each identifier that is lexed.
bool isSimple() const
A retain summary is simple if it has no ArgEffects other than the default.
@ UnretainedOutParameter
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +0 v...
ArgEffects getArgEffects() const
ObjCMethodDecl - Represents an instance or class method declaration.
ArgEffect withKind(ArgEffectKind NewK)
bool This(InterpState &S, CodePtr OpPC)
static unsigned getHashValue(const ObjCSummaryKey &V)
@ RetainedOutParameterOnZero
The argument is a pointer to a retain-counted object; on exit, the new value of the pointer is a +1 v...
@ NoRet
Indicates that no retain count information is tracked for the return value.
Smart pointer class that efficiently represents Objective-C method names.
ObjKind getObjKind() const
An ArgEffect summarizes the retain count behavior on an argument or receiver to a function or method.
RetEffect getObjAllocRetEffect() const
Selector GetNullarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing a nullary selector.
static RetEffect MakeOwnedWhenTrackedReceiver()
const RetainSummary * find(IdentifierInfo *II, Selector S)
__device__ __2f16 float bool s
RetEffect summarizes a call's retain/release behavior with respect to its return value.
ObjCSummaryKey(const ObjCInterfaceDecl *d, Selector s)
const RetainSummary *& operator[](Selector S)
ArgEffect getArg(unsigned idx) const
getArg - Return the argument effect on the argument specified by idx (starting from 0).
@ IncRef
The argument has its reference count increased by 1.
@ DecRefBridgedTransferred
The argument has its reference count decreased by 1 to model a transferred bridge cast under ARC.
bool operator==(const RetEffect &Other) const
A key identifying a summary.
IdentifierInfo * getIdentifier() const
static void Profile(const RetEffect &X, FoldingSetNodeID &ID)
RetainSummary(ArgEffects A, RetEffect R, ArgEffect defaultEff, ArgEffect ReceiverEff, ArgEffect ThisEff)
Represents a function declaration or definition.
@ OwnedSymbol
Indicates that the returned value is an owned (+1) symbol.
RetainSummary & operator*()
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
ArgEffect(ArgEffectKind K=DoNothing, ObjKind O=ObjKind::AnyObj)
static bool isEqual(const ObjCSummaryKey &LHS, const ObjCSummaryKey &RHS)
static RetEffect MakeNotOwned(ObjKind o)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
const static RetainSummary * getSummary(RetainSummaryManager &Summaries, const CallEvent &Call, QualType ReceiverType)