38 using namespace clang;
44 const char * RunLoopBind =
"NSRunLoopM";
45 const char * RunLoopRunBind =
"RunLoopRunM";
46 const char * OtherMsgBind =
"OtherMessageSentM";
47 const char * AutoreleasePoolBind =
"AutoreleasePoolM";
48 const char * OtherStmtAutoreleasePoolBind =
"OtherAutoreleasePoolM";
50 class RunLoopAutoreleaseLeakChecker :
public Checker<check::ASTCodeBody> {
53 void checkASTCodeBody(
const Decl *D,
81 if (Cached->hasValue())
82 return Cached->getValue();
96 return Val.getValue();
103 const RunLoopAutoreleaseLeakChecker *
Checker) {
117 bool HasAutoreleasePool = (AP !=
nullptr);
120 const auto *RLR = Match.getNodeAs<
Stmt>(RunLoopRunBind);
121 assert(RLR &&
"Run loop launch not found");
125 if (seenBefore(DeclBody, RLR, ME))
128 if (HasAutoreleasePool && (OAP != AP))
136 "Memory leak inside autorelease pool",
139 (Twine(
"Temporary objects allocated in the") +
140 " autorelease pool " +
141 (HasAutoreleasePool ?
"" :
"of last resort ") +
142 "followed by the launch of " +
143 (RL ?
"main run loop " :
"xpc_main ") +
144 "may never get released; consider moving them to a " 145 "separate autorelease pool")
153 hasReceiverType(asString(
"NSRunLoop")),
158 hasReceiver(MainRunLoopM),
159 Extra).bind(RunLoopRunBind);
163 return anyOf(MainRunLoopRunM, XPCRunM);
168 equalsBoundNode(RunLoopRunBind))),
175 const RunLoopAutoreleaseLeakChecker *Chkr) {
194 const RunLoopAutoreleaseLeakChecker *Chkr) {
214 void RunLoopAutoreleaseLeakChecker::checkASTCodeBody(
const Decl *D,
217 checkTempObjectsInSamePool(D, AM, BR,
this);
218 checkTempObjectsInNoPool(D, AM, BR,
this);
221 void ento::registerRunLoopAutoreleaseLeakChecker(
CheckerManager &mgr) {
internal::TrueMatcher anything()
Matches any node.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Stmt - This represents one statement.
internal::Matcher< Stmt > StatementMatcher
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> anyOf
Matches if any of the given matchers matches.
Decl - This represents one declaration (or definition), e.g.
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher. ...
A Range represents the closed range [from, to].
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
AnalysisDeclContext contains the context data for the function or method under analysis.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAutoreleasePoolStmt > autoreleasePoolStmt
Matches an Objective-C autorelease pool statement.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
An expression that sends a message to the given Objective-C object or class.
llvm::DenseMap< const Stmt *, Optional< TriBoolTy > > MemoizationMapTy
const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc > > hasAncestor
Matches AST nodes that have an ancestor that matches the provided matcher.
CHECKER * registerChecker(AT... Args)
Used to register checkers.
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
BugReporter is a utility class for generating PathDiagnostics for analysis.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
static TriBoolTy seenBeforeRec(const Stmt *Parent, const Stmt *A, const Stmt *B, MemoizationMapTy &Memoization)
const Decl * getDecl() const
static void emitDiagnostics(BoundNodes &Match, const Decl *D, BugReporter &BR, AnalysisManager &AM, const ObjCAutoreleaseWriteChecker *Checker)
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
BoundNodesTreeBuilder BoundNodes
Dataflow Directional Tag Classes.
SourceManager & getSourceManager()
internal::Matcher< NamedDecl > hasName(const std::string &Name)
Matches NamedDecl nodes that have the specified name.
A trivial tuple used to represent a source range.
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCMessageExpr > objcMessageExpr
Matches ObjectiveC Message invocation expressions.
Represents Objective-C's @autoreleasepool Statement.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.