[PATCH] D49921: [analyzer] Bugfix for autorelease + main run loop leak checker
George Karpenkov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 30 15:18:37 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC338314: [analyzer] Bugfix for autorelease + main run loop leak checker (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.
Changed prior to commit:
https://reviews.llvm.org/D49921?vs=157708&id=158100#toc
Repository:
rC Clang
https://reviews.llvm.org/D49921
Files:
lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
Index: lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
@@ -45,6 +45,7 @@
const char * RunLoopRunBind = "RunLoopRunM";
const char * OtherMsgBind = "OtherMessageSentM";
const char * AutoreleasePoolBind = "AutoreleasePoolM";
+const char * OtherStmtAutoreleasePoolBind = "OtherAutoreleasePoolM";
class RunLoopAutoreleaseLeakChecker : public Checker<check::ASTCodeBody> {
@@ -111,17 +112,20 @@
const auto *AP =
Match.getNodeAs<ObjCAutoreleasePoolStmt>(AutoreleasePoolBind);
+ const auto *OAP =
+ Match.getNodeAs<ObjCAutoreleasePoolStmt>(OtherStmtAutoreleasePoolBind);
bool HasAutoreleasePool = (AP != nullptr);
const auto *RL = Match.getNodeAs<ObjCMessageExpr>(RunLoopBind);
const auto *RLR = Match.getNodeAs<Stmt>(RunLoopRunBind);
assert(RLR && "Run loop launch not found");
-
assert(ME != RLR);
- if (HasAutoreleasePool && seenBefore(AP, RLR, ME))
+
+ // Launch of run loop occurs before the message-sent expression is seen.
+ if (seenBefore(DeclBody, RLR, ME))
return;
- if (!HasAutoreleasePool && seenBefore(DeclBody, RLR, ME))
+ if (HasAutoreleasePool && (OAP != AP))
return;
PathDiagnosticLocation Location = PathDiagnosticLocation::createBegin(
@@ -170,7 +174,8 @@
checkTempObjectsInSamePool(const Decl *D, AnalysisManager &AM, BugReporter &BR,
const RunLoopAutoreleaseLeakChecker *Chkr) {
StatementMatcher RunLoopRunM = getRunLoopRunM();
- StatementMatcher OtherMessageSentM = getOtherMessageSentM();
+ StatementMatcher OtherMessageSentM = getOtherMessageSentM(
+ hasAncestor(autoreleasePoolStmt().bind(OtherStmtAutoreleasePoolBind)));
StatementMatcher RunLoopInAutorelease =
autoreleasePoolStmt(
Index: test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
===================================================================
--- test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
+++ test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
@@ -29,6 +29,17 @@
}
}
+void runloop_init_before_separate_pool() { // No warning: separate autorelease pool.
+ @autoreleasepool {
+ NSObject *object;
+ @autoreleasepool {
+ object = [[NSObject alloc] init]; // no-warning
+ }
+ (void) object;
+ [[NSRunLoop mainRunLoop] run];
+ }
+}
+
void xpcmain_init_before() { // Warning: object created before the loop.
@autoreleasepool {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49921.158100.patch
Type: text/x-patch
Size: 2820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180730/2ef8e39d/attachment-0001.bin>
More information about the cfe-commits
mailing list