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"
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;
239 check::Bind, check::DeadSymbols, check::BeginFunction,
240 check::EndFunction, check::PostStmt<BlockExpr>,
241 check::PostStmt<CastExpr>, check::PostStmt<ObjCArrayLiteral>,
242 check::PostStmt<ObjCDictionaryLiteral>,
243 check::PostStmt<ObjCBoxedExpr>, check::PostStmt<ObjCIvarRefExpr>,
244 check::PostCall, check::RegionChanges, eval::Assume, eval::Call> {
250 mutable std::unique_ptr<RetainSummaryManager>
Summaries;
258 StringRef
getDebugTag()
const override {
return "RetainCountChecker"; }
262 Summaries = std::make_unique<RetainSummaryManager>(
281 const char *NL,
const char *Sep)
const override;
306 bool Assumption)
const;
376 auto Method = dyn_cast_or_null<ObjCMethodDecl>(SF->
getDecl());
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.
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.
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.
Checker families (where a single backend class implements multiple related frontends) should derive f...
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
RefCountFrontend RetainCount
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
ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond, bool Assumption) const
static const SimpleProgramPointTag & getCastFailTag()
void processNonLeakError(ProgramStateRef St, SourceRange ErrorRange, RefVal::Kind ErrorKind, SymbolRef Sym, CheckerContext &C) const
const RefCountBug & errorKindToBugKind(RefVal::Kind ErrorKind, SymbolRef Sym) const
static std::unique_ptr< SimpleProgramPointTag > DeallocSentTag
ExplodedNode * checkReturnWithRetEffect(const ReturnStmt *S, CheckerContext &C, ExplodedNode *Pred, RetEffect RE, RefVal X, SymbolRef Sym, ProgramStateRef state) const
ProgramStateRef handleAutoreleaseCounts(ProgramStateRef state, ExplodedNode *Pred, CheckerContext &Ctx, SymbolRef Sym, RefVal V, const ReturnStmt *S=nullptr) const
bool isReleaseUnownedError(RefVal::Kind ErrorKind) const
const RefCountFrontend & getPreferredFrontend() const
ExplodedNode * processLeaks(ProgramStateRef state, SmallVectorImpl< SymbolRef > &Leaked, CheckerContext &Ctx, ExplodedNode *Pred=nullptr) const
void checkBind(SVal loc, SVal val, const Stmt *S, bool AtDeclInit, CheckerContext &C) const
ProgramStateRef updateSymbol(ProgramStateRef state, SymbolRef sym, RefVal V, ArgEffect E, RefVal::Kind &hasErr, CheckerContext &C) const
RefCountFrontend OSObjectRetainCount
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const
std::unique_ptr< RetainSummaryManager > Summaries
void printState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep) const override
Debug state dump callback, see CheckerManager::runCheckersForPrintState.
bool evalCall(const CallEvent &Call, CheckerContext &C) const
void checkBeginFunction(CheckerContext &C) const
void checkPostCall(const CallEvent &Call, CheckerContext &C) const
static std::unique_ptr< SimpleProgramPointTag > CastFailTag
ProgramStateRef checkRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call) const
static const SimpleProgramPointTag & getDeallocSentTag()
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
RetainSummaryManager & getSummaryManager(ASTContext &Ctx) const
StringRef getDebugTag() const override
The description of this program point which will be dumped for debugging purposes.
bool TrackNSCFStartParam
Track initial parameters (for the entry point) for NS/CF objects.
bool isSynthesizedAccessor(const StackFrame *SF)
Returns true if this stack frame is for an Objective-C method that is a property getter or setter who...
const RefVal * getRefBinding(ProgramStateRef State, SymbolRef Sym)
llvm::DenseSet< SymbolRef > InvalidatedSymbols
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
ObjKind
Determines the object kind of a tracked object.
The JSON file list parser is used to communicate input to InstallAPI.