14#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
15#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
36#include "llvm/ADT/DenseMap.h"
37#include "llvm/ADT/FoldingSet.h"
38#include "llvm/ADT/ImmutableList.h"
39#include "llvm/ADT/STLExtras.h"
40#include "llvm/ADT/SmallString.h"
41#include "llvm/ADT/StringExtras.h"
47namespace retaincountchecker {
96 unsigned RawObjectKind : 3;
107 unsigned RawIvarAccessHistory : 2;
111 : Cnt(cnt), ACnt(acnt),
T(t), RawKind(static_cast<
unsigned>(k)),
112 RawObjectKind(static_cast<
unsigned>(o)),
113 RawIvarAccessHistory(static_cast<
unsigned>(IvarAccess)) {
114 assert(
getKind() == k &&
"not enough bits for the kind");
115 assert(
getObjKind() == o &&
"not enough bits for the object kind");
123 return static_cast<ObjKind>(RawObjectKind);
217 return getKind() ==
X.getKind() && Cnt ==
X.Cnt && ACnt ==
X.ACnt &&
225 void Profile(llvm::FoldingSetNodeID& ID)
const {
227 ID.AddInteger(RawKind);
230 ID.AddInteger(RawObjectKind);
231 ID.AddInteger(RawIvarAccessHistory);
234 void print(raw_ostream &Out)
const;
240 check::BeginFunction,
242 check::PostStmt<BlockExpr>,
243 check::PostStmt<CastExpr>,
244 check::PostStmt<ObjCArrayLiteral>,
245 check::PostStmt<ObjCDictionaryLiteral>,
246 check::PostStmt<ObjCBoxedExpr>,
247 check::PostStmt<ObjCIvarRefExpr>,
249 check::RegionChanges,
263 mutable std::unique_ptr<RetainSummaryManager>
Summaries;
291 const char *NL,
const char *Sep)
const override;
315 bool Assumption)
const;
384 auto Method = dyn_cast_or_null<ObjCMethodDecl>(SFC->
getDecl());
385 if (!Method || !Method->isPropertyAccessor())
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::LangOptions interface.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isBodyAutosynthesized() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
This represents one expression.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const Decl * getDecl() const
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
ObjCBoxedExpr - used for generalized expression boxing.
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
ObjCIvarRefExpr - A reference to an ObjC instance variable.
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
A (possibly-)qualified type.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
A trivial tuple used to represent a source range.
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
An ArgEffect summarizes the retain count behavior on an argument or receiver to a function or method.
Represents an abstract call to a function or method along a particular path.
Tag that can use a checker name as a message provider (see SimpleProgramPointTag).
RetEffect summarizes a call's retain/release behavior with respect to its return value.
Summary for a function with respect to ownership changes.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
A class responsible for cleaning up unused symbols.
bool operator==(const RefVal &X) const
unsigned getCount() const
unsigned getCombinedCounts() const
IvarAccessHistory
Tracks how an object referenced by an ivar has been used.
@ ReleasedAfterDirectAccess
IvarAccessHistory getIvarAccessHistory() const
Returns what the analyzer knows about direct accesses to a particular instance variable.
RefVal operator-(size_t i) const
void setCount(unsigned i)
bool isReturnedNotOwned() const
unsigned getAutoreleaseCount() const
void print(raw_ostream &Out) const
RefVal withIvarAccess() const
bool hasSameState(const RefVal &X) const
RefVal operator^(Kind k) const
void setAutoreleaseCount(unsigned i)
static RefVal makeOwned(ObjKind o, QualType t)
Create a state for an object whose lifetime is the responsibility of the current function,...
ObjKind getObjKind() const
RefVal autorelease() const
void Profile(llvm::FoldingSetNodeID &ID) const
RefVal operator+(size_t i) const
static RefVal makeNotOwned(ObjKind o, QualType t)
Create a state for an object whose lifetime is not the responsibility of the current function.
RefVal releaseViaIvar() const
bool isReturnedOwned() const
std::unique_ptr< RefCountBug > LeakAtReturn
void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const
void checkSummary(const RetainSummary &Summ, const CallEvent &Call, CheckerContext &C) const
ProgramStateRef handleSymbolDeath(ProgramStateRef state, SymbolRef sid, RefVal V, SmallVectorImpl< SymbolRef > &Leaked) const
static std::unique_ptr< CheckerProgramPointTag > CastFailTag
bool TrackObjCAndCFObjects
Track Objective-C and CoreFoundation objects.
ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond, bool Assumption) const
static std::unique_ptr< CheckerProgramPointTag > DeallocSentTag
static const CheckerProgramPointTag & getCastFailTag()
void processNonLeakError(ProgramStateRef St, SourceRange ErrorRange, RefVal::Kind ErrorKind, SymbolRef Sym, CheckerContext &C) const
const RefCountBug & errorKindToBugKind(RefVal::Kind ErrorKind, SymbolRef Sym) const
std::unique_ptr< RefCountBug > ReleaseNotOwned
std::unique_ptr< RefCountBug > DeallocNotOwned
void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const
ExplodedNode * checkReturnWithRetEffect(const ReturnStmt *S, CheckerContext &C, ExplodedNode *Pred, RetEffect RE, RefVal X, SymbolRef Sym, ProgramStateRef state) const
ProgramStateRef handleAutoreleaseCounts(ProgramStateRef state, ExplodedNode *Pred, const ProgramPointTag *Tag, CheckerContext &Ctx, SymbolRef Sym, RefVal V, const ReturnStmt *S=nullptr) const
std::unique_ptr< RefCountBug > OverAutorelease
ExplodedNode * processLeaks(ProgramStateRef state, SmallVectorImpl< SymbolRef > &Leaked, CheckerContext &Ctx, ExplodedNode *Pred=nullptr) const
ProgramStateRef updateSymbol(ProgramStateRef state, SymbolRef sym, RefVal V, ArgEffect E, RefVal::Kind &hasErr, CheckerContext &C) const
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const
static const CheckerProgramPointTag & getDeallocSentTag()
std::unique_ptr< RetainSummaryManager > Summaries
void printState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep) const override
See CheckerManager::runCheckersForPrintState.
bool evalCall(const CallEvent &Call, CheckerContext &C) const
void checkBeginFunction(CheckerContext &C) const
bool TrackOSObjects
Track sublcasses of OSObject.
void checkPostCall(const CallEvent &Call, CheckerContext &C) const
std::unique_ptr< RefCountBug > FreeNotOwned
std::unique_ptr< RefCountBug > LeakWithinFunction
ProgramStateRef checkRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call) const
void processObjCLiterals(CheckerContext &C, const Expr *Ex) const
void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const
RetainSummaryManager & getSummaryManager(CheckerContext &C) const
void processSummaryOfInlined(const RetainSummary &Summ, const CallEvent &Call, CheckerContext &C) const
std::unique_ptr< RefCountBug > ReturnNotOwnedForOwned
RetainSummaryManager & getSummaryManager(ASTContext &Ctx) const
bool TrackNSCFStartParam
Track initial parameters (for the entry point) for NS/CF objects.
std::unique_ptr< RefCountBug > UseAfterRelease
const RefVal * getRefBinding(ProgramStateRef State, SymbolRef Sym)
bool isSynthesizedAccessor(const StackFrameContext *SFC)
Returns true if this stack frame is for an Objective-C method that is a property getter or setter who...
ObjKind
Determines the object kind of a tracked object.
llvm::DenseSet< SymbolRef > InvalidatedSymbols
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T