George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 1 | //==--- RetainCountChecker.h - Checks for leaks and other issues -*- C++ -*--// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the methods for RetainCountChecker, which implements |
| 11 | // a reference count checker for Core Foundation and Cocoa on (Mac OS X). |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H |
| 16 | #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H |
| 17 | |
| 18 | #include "../ClangSACheckers.h" |
| 19 | #include "../AllocationDiagnostics.h" |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 20 | #include "RetainCountDiagnostics.h" |
| 21 | #include "clang/AST/Attr.h" |
| 22 | #include "clang/AST/DeclCXX.h" |
| 23 | #include "clang/AST/DeclObjC.h" |
| 24 | #include "clang/AST/ParentMap.h" |
| 25 | #include "clang/Analysis/DomainSpecific/CocoaConventions.h" |
| 26 | #include "clang/Basic/LangOptions.h" |
| 27 | #include "clang/Basic/SourceManager.h" |
George Karpenkov | efef49c | 2018-08-21 03:09:02 +0000 | [diff] [blame] | 28 | #include "clang/Analysis/SelectorExtras.h" |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 29 | #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" |
| 30 | #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" |
| 31 | #include "clang/StaticAnalyzer/Core/Checker.h" |
| 32 | #include "clang/StaticAnalyzer/Core/CheckerManager.h" |
| 33 | #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" |
| 34 | #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" |
| 35 | #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" |
| 36 | #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" |
George Karpenkov | efef49c | 2018-08-21 03:09:02 +0000 | [diff] [blame] | 37 | #include "clang/StaticAnalyzer/Core/RetainSummaryManager.h" |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/DenseMap.h" |
| 39 | #include "llvm/ADT/FoldingSet.h" |
| 40 | #include "llvm/ADT/ImmutableList.h" |
| 41 | #include "llvm/ADT/ImmutableMap.h" |
| 42 | #include "llvm/ADT/STLExtras.h" |
| 43 | #include "llvm/ADT/SmallString.h" |
| 44 | #include "llvm/ADT/StringExtras.h" |
| 45 | #include <cstdarg> |
| 46 | #include <utility> |
| 47 | |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 48 | using llvm::StrInStrNoCase; |
| 49 | |
| 50 | namespace clang { |
| 51 | namespace ento { |
| 52 | namespace retaincountchecker { |
| 53 | |
| 54 | /// Metadata on reference. |
| 55 | class RefVal { |
| 56 | public: |
| 57 | enum Kind { |
| 58 | Owned = 0, // Owning reference. |
| 59 | NotOwned, // Reference is not owned by still valid (not freed). |
| 60 | Released, // Object has been released. |
| 61 | ReturnedOwned, // Returned object passes ownership to caller. |
| 62 | ReturnedNotOwned, // Return object does not pass ownership to caller. |
| 63 | ERROR_START, |
| 64 | ErrorDeallocNotOwned, // -dealloc called on non-owned object. |
| 65 | ErrorUseAfterRelease, // Object used after released. |
| 66 | ErrorReleaseNotOwned, // Release of an object that was not owned. |
| 67 | ERROR_LEAK_START, |
| 68 | ErrorLeak, // A memory leak due to excessive reference counts. |
| 69 | ErrorLeakReturned, // A memory leak due to the returning method not having |
| 70 | // the correct naming conventions. |
| 71 | ErrorOverAutorelease, |
| 72 | ErrorReturnedNotOwned |
| 73 | }; |
| 74 | |
| 75 | /// Tracks how an object referenced by an ivar has been used. |
| 76 | /// |
| 77 | /// This accounts for us not knowing if an arbitrary ivar is supposed to be |
| 78 | /// stored at +0 or +1. |
| 79 | enum class IvarAccessHistory { |
| 80 | None, |
| 81 | AccessedDirectly, |
| 82 | ReleasedAfterDirectAccess |
| 83 | }; |
| 84 | |
| 85 | private: |
| 86 | /// The number of outstanding retains. |
| 87 | unsigned Cnt; |
| 88 | /// The number of outstanding autoreleases. |
| 89 | unsigned ACnt; |
| 90 | /// The (static) type of the object at the time we started tracking it. |
| 91 | QualType T; |
| 92 | |
| 93 | /// The current state of the object. |
| 94 | /// |
| 95 | /// See the RefVal::Kind enum for possible values. |
| 96 | unsigned RawKind : 5; |
| 97 | |
| 98 | /// The kind of object being tracked (CF or ObjC), if known. |
| 99 | /// |
| 100 | /// See the RetEffect::ObjKind enum for possible values. |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 101 | unsigned RawObjectKind : 3; |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 102 | |
| 103 | /// True if the current state and/or retain count may turn out to not be the |
| 104 | /// best possible approximation of the reference counting state. |
| 105 | /// |
| 106 | /// If true, the checker may decide to throw away ("override") this state |
| 107 | /// in favor of something else when it sees the object being used in new ways. |
| 108 | /// |
| 109 | /// This setting should not be propagated to state derived from this state. |
| 110 | /// Once we start deriving new states, it would be inconsistent to override |
| 111 | /// them. |
| 112 | unsigned RawIvarAccessHistory : 2; |
| 113 | |
| 114 | RefVal(Kind k, RetEffect::ObjKind o, unsigned cnt, unsigned acnt, QualType t, |
| 115 | IvarAccessHistory IvarAccess) |
| 116 | : Cnt(cnt), ACnt(acnt), T(t), RawKind(static_cast<unsigned>(k)), |
| 117 | RawObjectKind(static_cast<unsigned>(o)), |
| 118 | RawIvarAccessHistory(static_cast<unsigned>(IvarAccess)) { |
| 119 | assert(getKind() == k && "not enough bits for the kind"); |
| 120 | assert(getObjKind() == o && "not enough bits for the object kind"); |
| 121 | assert(getIvarAccessHistory() == IvarAccess && "not enough bits"); |
| 122 | } |
| 123 | |
| 124 | public: |
| 125 | Kind getKind() const { return static_cast<Kind>(RawKind); } |
| 126 | |
| 127 | RetEffect::ObjKind getObjKind() const { |
| 128 | return static_cast<RetEffect::ObjKind>(RawObjectKind); |
| 129 | } |
| 130 | |
| 131 | unsigned getCount() const { return Cnt; } |
| 132 | unsigned getAutoreleaseCount() const { return ACnt; } |
| 133 | unsigned getCombinedCounts() const { return Cnt + ACnt; } |
| 134 | void clearCounts() { |
| 135 | Cnt = 0; |
| 136 | ACnt = 0; |
| 137 | } |
| 138 | void setCount(unsigned i) { |
| 139 | Cnt = i; |
| 140 | } |
| 141 | void setAutoreleaseCount(unsigned i) { |
| 142 | ACnt = i; |
| 143 | } |
| 144 | |
| 145 | QualType getType() const { return T; } |
| 146 | |
| 147 | /// Returns what the analyzer knows about direct accesses to a particular |
| 148 | /// instance variable. |
| 149 | /// |
| 150 | /// If the object with this refcount wasn't originally from an Objective-C |
| 151 | /// ivar region, this should always return IvarAccessHistory::None. |
| 152 | IvarAccessHistory getIvarAccessHistory() const { |
| 153 | return static_cast<IvarAccessHistory>(RawIvarAccessHistory); |
| 154 | } |
| 155 | |
| 156 | bool isOwned() const { |
| 157 | return getKind() == Owned; |
| 158 | } |
| 159 | |
| 160 | bool isNotOwned() const { |
| 161 | return getKind() == NotOwned; |
| 162 | } |
| 163 | |
| 164 | bool isReturnedOwned() const { |
| 165 | return getKind() == ReturnedOwned; |
| 166 | } |
| 167 | |
| 168 | bool isReturnedNotOwned() const { |
| 169 | return getKind() == ReturnedNotOwned; |
| 170 | } |
| 171 | |
| 172 | /// Create a state for an object whose lifetime is the responsibility of the |
| 173 | /// current function, at least partially. |
| 174 | /// |
| 175 | /// Most commonly, this is an owned object with a retain count of +1. |
| 176 | static RefVal makeOwned(RetEffect::ObjKind o, QualType t) { |
| 177 | return RefVal(Owned, o, /*Count=*/1, 0, t, IvarAccessHistory::None); |
| 178 | } |
| 179 | |
| 180 | /// Create a state for an object whose lifetime is not the responsibility of |
| 181 | /// the current function. |
| 182 | /// |
| 183 | /// Most commonly, this is an unowned object with a retain count of +0. |
| 184 | static RefVal makeNotOwned(RetEffect::ObjKind o, QualType t) { |
| 185 | return RefVal(NotOwned, o, /*Count=*/0, 0, t, IvarAccessHistory::None); |
| 186 | } |
| 187 | |
| 188 | RefVal operator-(size_t i) const { |
| 189 | return RefVal(getKind(), getObjKind(), getCount() - i, |
| 190 | getAutoreleaseCount(), getType(), getIvarAccessHistory()); |
| 191 | } |
| 192 | |
| 193 | RefVal operator+(size_t i) const { |
| 194 | return RefVal(getKind(), getObjKind(), getCount() + i, |
| 195 | getAutoreleaseCount(), getType(), getIvarAccessHistory()); |
| 196 | } |
| 197 | |
| 198 | RefVal operator^(Kind k) const { |
| 199 | return RefVal(k, getObjKind(), getCount(), getAutoreleaseCount(), |
| 200 | getType(), getIvarAccessHistory()); |
| 201 | } |
| 202 | |
| 203 | RefVal autorelease() const { |
| 204 | return RefVal(getKind(), getObjKind(), getCount(), getAutoreleaseCount()+1, |
| 205 | getType(), getIvarAccessHistory()); |
| 206 | } |
| 207 | |
| 208 | RefVal withIvarAccess() const { |
| 209 | assert(getIvarAccessHistory() == IvarAccessHistory::None); |
| 210 | return RefVal(getKind(), getObjKind(), getCount(), getAutoreleaseCount(), |
| 211 | getType(), IvarAccessHistory::AccessedDirectly); |
| 212 | } |
| 213 | |
| 214 | RefVal releaseViaIvar() const { |
| 215 | assert(getIvarAccessHistory() == IvarAccessHistory::AccessedDirectly); |
| 216 | return RefVal(getKind(), getObjKind(), getCount(), getAutoreleaseCount(), |
| 217 | getType(), IvarAccessHistory::ReleasedAfterDirectAccess); |
| 218 | } |
| 219 | |
| 220 | // Comparison, profiling, and pretty-printing. |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 221 | bool hasSameState(const RefVal &X) const { |
| 222 | return getKind() == X.getKind() && Cnt == X.Cnt && ACnt == X.ACnt && |
| 223 | getIvarAccessHistory() == X.getIvarAccessHistory(); |
| 224 | } |
| 225 | |
| 226 | bool operator==(const RefVal& X) const { |
| 227 | return T == X.T && hasSameState(X) && getObjKind() == X.getObjKind(); |
| 228 | } |
| 229 | |
| 230 | void Profile(llvm::FoldingSetNodeID& ID) const { |
| 231 | ID.Add(T); |
| 232 | ID.AddInteger(RawKind); |
| 233 | ID.AddInteger(Cnt); |
| 234 | ID.AddInteger(ACnt); |
| 235 | ID.AddInteger(RawObjectKind); |
| 236 | ID.AddInteger(RawIvarAccessHistory); |
| 237 | } |
| 238 | |
| 239 | void print(raw_ostream &Out) const; |
| 240 | }; |
| 241 | |
| 242 | class RetainCountChecker |
| 243 | : public Checker< check::Bind, |
| 244 | check::DeadSymbols, |
| 245 | check::EndAnalysis, |
| 246 | check::BeginFunction, |
| 247 | check::EndFunction, |
| 248 | check::PostStmt<BlockExpr>, |
| 249 | check::PostStmt<CastExpr>, |
| 250 | check::PostStmt<ObjCArrayLiteral>, |
| 251 | check::PostStmt<ObjCDictionaryLiteral>, |
| 252 | check::PostStmt<ObjCBoxedExpr>, |
| 253 | check::PostStmt<ObjCIvarRefExpr>, |
| 254 | check::PostCall, |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 255 | check::RegionChanges, |
| 256 | eval::Assume, |
| 257 | eval::Call > { |
| 258 | mutable std::unique_ptr<CFRefBug> useAfterRelease, releaseNotOwned; |
| 259 | mutable std::unique_ptr<CFRefBug> deallocNotOwned; |
| 260 | mutable std::unique_ptr<CFRefBug> overAutorelease, returnNotOwnedForOwned; |
| 261 | mutable std::unique_ptr<CFRefBug> leakWithinFunction, leakAtReturn; |
| 262 | |
| 263 | typedef llvm::DenseMap<SymbolRef, const CheckerProgramPointTag *> SymbolTagMap; |
| 264 | |
| 265 | // This map is only used to ensure proper deletion of any allocated tags. |
| 266 | mutable SymbolTagMap DeadSymbolTags; |
| 267 | |
| 268 | mutable std::unique_ptr<RetainSummaryManager> Summaries; |
| 269 | mutable SummaryLogTy SummaryLog; |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 270 | |
| 271 | AnalyzerOptions &Options; |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 272 | mutable bool ShouldResetSummaryLog; |
| 273 | |
| 274 | /// Optional setting to indicate if leak reports should include |
| 275 | /// the allocation line. |
| 276 | mutable bool IncludeAllocationLine; |
| 277 | |
| 278 | public: |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 279 | RetainCountChecker(AnalyzerOptions &Options) |
| 280 | : Options(Options), ShouldResetSummaryLog(false), |
| 281 | IncludeAllocationLine( |
| 282 | shouldIncludeAllocationSiteInLeakDiagnostics(Options)) {} |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 283 | |
| 284 | ~RetainCountChecker() override { DeleteContainerSeconds(DeadSymbolTags); } |
| 285 | |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 286 | bool shouldCheckOSObjectRetainCount() const { |
| 287 | return Options.getBooleanOption("CheckOSObject", false, this); |
| 288 | } |
| 289 | |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 290 | void checkEndAnalysis(ExplodedGraph &G, BugReporter &BR, |
| 291 | ExprEngine &Eng) const { |
| 292 | // FIXME: This is a hack to make sure the summary log gets cleared between |
| 293 | // analyses of different code bodies. |
| 294 | // |
| 295 | // Why is this necessary? Because a checker's lifetime is tied to a |
| 296 | // translation unit, but an ExplodedGraph's lifetime is just a code body. |
| 297 | // Once in a blue moon, a new ExplodedNode will have the same address as an |
| 298 | // old one with an associated summary, and the bug report visitor gets very |
| 299 | // confused. (To make things worse, the summary lifetime is currently also |
| 300 | // tied to a code body, so we get a crash instead of incorrect results.) |
| 301 | // |
| 302 | // Why is this a bad solution? Because if the lifetime of the ExplodedGraph |
| 303 | // changes, things will start going wrong again. Really the lifetime of this |
| 304 | // log needs to be tied to either the specific nodes in it or the entire |
| 305 | // ExplodedGraph, not to a specific part of the code being analyzed. |
| 306 | // |
| 307 | // (Also, having stateful local data means that the same checker can't be |
| 308 | // used from multiple threads, but a lot of checkers have incorrect |
| 309 | // assumptions about that anyway. So that wasn't a priority at the time of |
| 310 | // this fix.) |
| 311 | // |
| 312 | // This happens at the end of analysis, but bug reports are emitted /after/ |
| 313 | // this point. So we can't just clear the summary log now. Instead, we mark |
| 314 | // that the next time we access the summary log, it should be cleared. |
| 315 | |
| 316 | // If we never reset the summary log during /this/ code body analysis, |
| 317 | // there were no new summaries. There might still have been summaries from |
| 318 | // the /last/ analysis, so clear them out to make sure the bug report |
| 319 | // visitors don't get confused. |
| 320 | if (ShouldResetSummaryLog) |
| 321 | SummaryLog.clear(); |
| 322 | |
| 323 | ShouldResetSummaryLog = !SummaryLog.empty(); |
| 324 | } |
| 325 | |
| 326 | CFRefBug *getLeakWithinFunctionBug(const LangOptions &LOpts) const { |
| 327 | if (!leakWithinFunction) |
| 328 | leakWithinFunction.reset(new Leak(this, "Leak")); |
| 329 | return leakWithinFunction.get(); |
| 330 | } |
| 331 | |
| 332 | CFRefBug *getLeakAtReturnBug(const LangOptions &LOpts) const { |
| 333 | if (!leakAtReturn) |
| 334 | leakAtReturn.reset(new Leak(this, "Leak of returned object")); |
| 335 | return leakAtReturn.get(); |
| 336 | } |
| 337 | |
| 338 | RetainSummaryManager &getSummaryManager(ASTContext &Ctx) const { |
| 339 | // FIXME: We don't support ARC being turned on and off during one analysis. |
| 340 | // (nor, for that matter, do we support changing ASTContexts) |
| 341 | bool ARCEnabled = (bool)Ctx.getLangOpts().ObjCAutoRefCount; |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 342 | if (!Summaries) { |
| 343 | Summaries.reset(new RetainSummaryManager( |
| 344 | Ctx, ARCEnabled, shouldCheckOSObjectRetainCount())); |
| 345 | } else { |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 346 | assert(Summaries->isARCEnabled() == ARCEnabled); |
George Karpenkov | ab0011e | 2018-08-23 00:26:59 +0000 | [diff] [blame] | 347 | } |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 348 | return *Summaries; |
| 349 | } |
| 350 | |
| 351 | RetainSummaryManager &getSummaryManager(CheckerContext &C) const { |
| 352 | return getSummaryManager(C.getASTContext()); |
| 353 | } |
| 354 | |
| 355 | void printState(raw_ostream &Out, ProgramStateRef State, |
| 356 | const char *NL, const char *Sep) const override; |
| 357 | |
| 358 | void checkBind(SVal loc, SVal val, const Stmt *S, CheckerContext &C) const; |
| 359 | void checkPostStmt(const BlockExpr *BE, CheckerContext &C) const; |
| 360 | void checkPostStmt(const CastExpr *CE, CheckerContext &C) const; |
| 361 | |
| 362 | void checkPostStmt(const ObjCArrayLiteral *AL, CheckerContext &C) const; |
| 363 | void checkPostStmt(const ObjCDictionaryLiteral *DL, CheckerContext &C) const; |
| 364 | void checkPostStmt(const ObjCBoxedExpr *BE, CheckerContext &C) const; |
| 365 | |
| 366 | void checkPostStmt(const ObjCIvarRefExpr *IRE, CheckerContext &C) const; |
| 367 | |
| 368 | void checkPostCall(const CallEvent &Call, CheckerContext &C) const; |
| 369 | |
| 370 | void checkSummary(const RetainSummary &Summ, const CallEvent &Call, |
| 371 | CheckerContext &C) const; |
| 372 | |
| 373 | void processSummaryOfInlined(const RetainSummary &Summ, |
| 374 | const CallEvent &Call, |
| 375 | CheckerContext &C) const; |
| 376 | |
| 377 | bool evalCall(const CallExpr *CE, CheckerContext &C) const; |
| 378 | |
| 379 | ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond, |
| 380 | bool Assumption) const; |
| 381 | |
| 382 | ProgramStateRef |
| 383 | checkRegionChanges(ProgramStateRef state, |
| 384 | const InvalidatedSymbols *invalidated, |
| 385 | ArrayRef<const MemRegion *> ExplicitRegions, |
| 386 | ArrayRef<const MemRegion *> Regions, |
| 387 | const LocationContext* LCtx, |
| 388 | const CallEvent *Call) const; |
| 389 | |
George Karpenkov | 04553e5 | 2018-09-21 20:37:20 +0000 | [diff] [blame^] | 390 | ExplodedNode* checkReturnWithRetEffect(const ReturnStmt *S, CheckerContext &C, |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 391 | ExplodedNode *Pred, RetEffect RE, RefVal X, |
| 392 | SymbolRef Sym, ProgramStateRef state) const; |
| 393 | |
| 394 | void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const; |
| 395 | void checkBeginFunction(CheckerContext &C) const; |
| 396 | void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const; |
| 397 | |
| 398 | ProgramStateRef updateSymbol(ProgramStateRef state, SymbolRef sym, |
| 399 | RefVal V, ArgEffect E, RefVal::Kind &hasErr, |
| 400 | CheckerContext &C) const; |
| 401 | |
| 402 | void processNonLeakError(ProgramStateRef St, SourceRange ErrorRange, |
| 403 | RefVal::Kind ErrorKind, SymbolRef Sym, |
| 404 | CheckerContext &C) const; |
| 405 | |
| 406 | void processObjCLiterals(CheckerContext &C, const Expr *Ex) const; |
| 407 | |
| 408 | const ProgramPointTag *getDeadSymbolTag(SymbolRef sym) const; |
| 409 | |
| 410 | ProgramStateRef handleSymbolDeath(ProgramStateRef state, |
| 411 | SymbolRef sid, RefVal V, |
| 412 | SmallVectorImpl<SymbolRef> &Leaked) const; |
| 413 | |
| 414 | ProgramStateRef |
| 415 | handleAutoreleaseCounts(ProgramStateRef state, ExplodedNode *Pred, |
| 416 | const ProgramPointTag *Tag, CheckerContext &Ctx, |
George Karpenkov | 04553e5 | 2018-09-21 20:37:20 +0000 | [diff] [blame^] | 417 | SymbolRef Sym, |
| 418 | RefVal V, |
| 419 | const ReturnStmt *S=nullptr) const; |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 420 | |
| 421 | ExplodedNode *processLeaks(ProgramStateRef state, |
| 422 | SmallVectorImpl<SymbolRef> &Leaked, |
| 423 | CheckerContext &Ctx, |
| 424 | ExplodedNode *Pred = nullptr) const; |
George Karpenkov | 04553e5 | 2018-09-21 20:37:20 +0000 | [diff] [blame^] | 425 | |
| 426 | private: |
| 427 | /// Perform the necessary checks and state adjustments at the end of the |
| 428 | /// function. |
| 429 | /// \p S Return statement, may be null. |
| 430 | ExplodedNode * processReturn(const ReturnStmt *S, CheckerContext &C) const; |
George Karpenkov | 70c2ee3 | 2018-08-17 21:41:07 +0000 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | //===----------------------------------------------------------------------===// |
| 434 | // RefBindings - State used to track object reference counts. |
| 435 | //===----------------------------------------------------------------------===// |
| 436 | |
| 437 | const RefVal *getRefBinding(ProgramStateRef State, SymbolRef Sym); |
| 438 | |
| 439 | ProgramStateRef setRefBinding(ProgramStateRef State, SymbolRef Sym, |
| 440 | RefVal Val); |
| 441 | |
| 442 | ProgramStateRef removeRefBinding(ProgramStateRef State, SymbolRef Sym); |
| 443 | |
| 444 | /// Returns true if this stack frame is for an Objective-C method that is a |
| 445 | /// property getter or setter whose body has been synthesized by the analyzer. |
| 446 | inline bool isSynthesizedAccessor(const StackFrameContext *SFC) { |
| 447 | auto Method = dyn_cast_or_null<ObjCMethodDecl>(SFC->getDecl()); |
| 448 | if (!Method || !Method->isPropertyAccessor()) |
| 449 | return false; |
| 450 | |
| 451 | return SFC->getAnalysisDeclContext()->isBodyAutosynthesized(); |
| 452 | } |
| 453 | |
| 454 | } // end namespace retaincountchecker |
| 455 | } // end namespace ento |
| 456 | } // end namespace clang |
| 457 | |
| 458 | #endif |