clang: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H

15#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H

16

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"

42#include

43#include

44

46namespace ento {

47namespace retaincountchecker {

48

49

51public:

53 Owned = 0,

54 NotOwned,

55 Released,

56 ReturnedOwned,

63 ErrorLeak,

64 ErrorLeakReturned,

65

69

70

71

72

73

78 };

79

80private:

81

82 unsigned Cnt;

83

84 unsigned ACnt;

85

87

88

89

90

91 unsigned RawKind : 5;

92

93

94

95

96 unsigned RawObjectKind : 3;

97

98

99

100

101

102

103

104

105

106

107 unsigned RawIvarAccessHistory : 2;

108

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");

117 }

118

119public:

121

123 return static_cast<ObjKind>(RawObjectKind);

124 }

125

126 unsigned getCount() const { return Cnt; }

130 Cnt = 0;

131 ACnt = 0;

132 }

134 Cnt = i;

135 }

137 ACnt = i;

138 }

139

141

142

143

144

145

146

149 }

150

153 }

154

157 }

158

161 }

162

165 }

166

167

168

169

170

173 }

174

175

176

177

178

181 }

182

186 }

187

191 }

192

196 }

197

201 }

202

207 }

208

213 }

214

215

217 return getKind() == X.getKind() && Cnt == X.Cnt && ACnt == X.ACnt &&

219 }

220

223 }

224

225 void Profile(llvm::FoldingSetNodeID& ID) const {

226 ID.Add(T);

227 ID.AddInteger(RawKind);

228 ID.AddInteger(Cnt);

229 ID.AddInteger(ACnt);

230 ID.AddInteger(RawObjectKind);

231 ID.AddInteger(RawIvarAccessHistory);

232 }

233

234 void print(raw_ostream &Out) const;

235};

236

238 : public Checker< check::Bind,

239 check::DeadSymbols,

240 check::BeginFunction,

241 check::EndFunction,

242 check::PostStmt,

243 check::PostStmt,

244 check::PostStmt,

245 check::PostStmt,

246 check::PostStmt,

247 check::PostStmt,

248 check::PostCall,

249 check::RegionChanges,

250 eval::Assume,

251 eval::Call > {

252

253public:

262

263 mutable std::unique_ptr Summaries;

264

266 static std::unique_ptr CastFailTag;

267

268

270

271

273

274

276

278

284 }

285

288 }

289

291 const char *NL, const char *Sep) const override;

292

296

300

302

304

307

311

313

315 bool Assumption) const;

316

324

328

332

336

339

343

345

349

356

361

364 }

365

367

368private:

369

370

371

373};

374

375

376

377

378

380

381

382

384 auto Method = dyn_cast_or_null(SFC->getDecl());

385 if (!Method || !Method->isPropertyAccessor())

386 return false;

387

389}

390

391}

392}

393}

394

395#endif

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