43const char * RunLoopBind =
"NSRunLoopM";
44const char * RunLoopRunBind =
"RunLoopRunM";
45const char * OtherMsgBind =
"OtherMessageSentM";
46const char * AutoreleasePoolBind =
"AutoreleasePoolM";
47const char * OtherStmtAutoreleasePoolBind =
"OtherAutoreleasePoolM";
49class RunLoopAutoreleaseLeakChecker :
public Checker<check::ASTCodeBody> {
52 void checkASTCodeBody(
const Decl *D,
54 BugReporter &BR)
const;
84 const RunLoopAutoreleaseLeakChecker *
Checker) {
97 bool HasAutoreleasePool = (AP !=
nullptr);
100 const auto *RLR =
Match.getNodeAs<
Stmt>(RunLoopRunBind);
101 assert(RLR &&
"Run loop launch not found");
108 if (HasAutoreleasePool && (OAP != AP))
116 "Memory leak inside autorelease pool",
119 (Twine(
"Temporary objects allocated in the") +
120 " autorelease pool " +
121 (HasAutoreleasePool ?
"" :
"of last resort ") +
122 "followed by the launch of " +
123 (RL ?
"main run loop " :
"xpc_main ") +
124 "may never get released; consider moving them to a "
125 "separate autorelease pool")
133 hasReceiverType(asString(
"NSRunLoop")),
138 hasReceiver(MainRunLoopM),
139 Extra).bind(RunLoopRunBind);
143 return anyOf(MainRunLoopRunM, XPCRunM);
148 equalsBoundNode(RunLoopRunBind))),
155 const RunLoopAutoreleaseLeakChecker *Chkr) {
174 const RunLoopAutoreleaseLeakChecker *Chkr) {
194void RunLoopAutoreleaseLeakChecker::checkASTCodeBody(
const Decl *D,
201void ento::registerRunLoopAutoreleaseLeakChecker(CheckerManager &mgr) {
205bool ento::shouldRegisterRunLoopAutoreleaseLeakChecker(
const CheckerManager &mgr) {
static void emitDiagnostics(BoundNodes &Match, const Decl *D, BugReporter &BR, AnalysisManager &AM, const RunLoopAutoreleaseLeakChecker *Checker)
static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B)
static void checkTempObjectsInSamePool(const Decl *D, AnalysisManager &AM, BugReporter &BR, const RunLoopAutoreleaseLeakChecker *Chkr)
static StatementMatcher getRunLoopRunM(StatementMatcher Extra=anything())
static StatementMatcher getOtherMessageSentM(StatementMatcher Extra=anything())
static void checkTempObjectsInNoPool(const Decl *D, AnalysisManager &AM, BugReporter &BR, const RunLoopAutoreleaseLeakChecker *Chkr)
AnalysisDeclContext contains the context data for the function, method or block under analysis.
const Decl * getDecl() const
Decl - This represents one declaration (or definition), e.g.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Represents Objective-C's @autoreleasepool Statement.
An expression that sends a message to the given Objective-C object or class.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Maps string IDs to AST nodes matched by parts of a matcher.
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
BugReporter is a utility class for generating PathDiagnostics for analysis.
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerFrontend *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges={}, ArrayRef< FixItHint > Fixits={})
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
A Range represents the closed range [from, to].
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher.
internal::Matcher< NamedDecl > hasName(StringRef Name)
Matches NamedDecl nodes that have the specified name.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAutoreleasePoolStmt > autoreleasePoolStmt
Matches an Objective-C autorelease pool statement.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
internal::TrueMatcher anything()
Matches any node.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCMessageExpr > objcMessageExpr
Matches ObjectiveC Message invocation expressions.
internal::Matcher< Stmt > StatementMatcher
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> anyOf
Matches if any of the given matchers matches.
const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr > > hasAncestor
Matches AST nodes that have an ancestor that matches the provided matcher.
Top level wrappers for InstallAPI frontend operations.
@ Match
This is not an overload because the signature exactly matches an existing declaration.