r338314 - [analyzer] Bugfix for autorelease + main run loop leak checker
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 30 15:18:21 PDT 2018
Author: george.karpenkov
Date: Mon Jul 30 15:18:21 2018
New Revision: 338314
URL: http://llvm.org/viewvc/llvm-project?rev=338314&view=rev
Log:
[analyzer] Bugfix for autorelease + main run loop leak checker
Do not warn when the other message-send-expression is correctly wrapped
in a different autorelease pool.
Differential Revision: https://reviews.llvm.org/D49921
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp?rev=338314&r1=338313&r2=338314&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp Mon Jul 30 15:18:21 2018
@@ -45,6 +45,7 @@ const char * RunLoopBind = "NSRunLoopM";
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 @@ static void emitDiagnostics(BoundNodes &
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 @@ static void
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(
Modified: cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m?rev=338314&r1=338313&r2=338314&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m (original)
+++ cfe/trunk/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m Mon Jul 30 15:18:21 2018
@@ -29,6 +29,17 @@ void runloop_init_before() { // Warning:
}
}
+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}}
More information about the cfe-commits
mailing list