[cfe-commits] r69992 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/pr_2542_rdar_6793404.m
Ted Kremenek
kremenek at apple.com
Fri Apr 24 14:56:17 PDT 2009
Author: kremenek
Date: Fri Apr 24 16:56:17 2009
New Revision: 69992
URL: http://llvm.org/viewvc/llvm-project?rev=69992&view=rev
Log:
Fix the same false positive reported in PR 2542 and <rdar://problem/6793409>
involving an NSAnimation object delegating its release to a delegate method.
Added:
cfe/trunk/test/Analysis/pr_2542_rdar_6793404.m
Modified:
cfe/trunk/lib/Analysis/CFRefCount.cpp
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=69992&r1=69991&r2=69992&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Apr 24 16:56:17 2009
@@ -1074,8 +1074,8 @@
RetainSummary*
-RetainSummaryManager::getCommonMethodSummary(ObjCMessageExpr* ME, Selector S)
-{
+RetainSummaryManager::getCommonMethodSummary(ObjCMessageExpr* ME, Selector S) {
+
if (ObjCMethodDecl *MD = ME->getMethodDecl()) {
// Scan the method decl for 'void*' arguments. These should be treated
// as 'StopTracking' because they are often used with delegates.
@@ -1091,12 +1091,26 @@
}
}
+ // Any special effect for the receiver?
+ ArgEffect ReceiverEff = DoNothing;
+
+ // If one of the arguments in the selector has the keyword 'delegate' we
+ // should stop tracking the reference count for the receiver. This is
+ // because the reference count is quite possibly handled by a delegate
+ // method.
+ if (S.isKeywordSelector()) {
+ const std::string &str = S.getAsString();
+ assert(!str.empty());
+ if (CStrInCStrNoCase(&str[0], "delegate:")) ReceiverEff = StopTracking;
+ }
+
// Look for methods that return an owned object.
if (!isTrackedObjectType(ME->getType())) {
- if (ScratchArgs.empty())
+ if (ScratchArgs.empty() && ReceiverEff == DoNothing)
return 0;
- return getPersistentSummary(RetEffect::MakeNoRet());
+ return getPersistentSummary(RetEffect::MakeNoRet(), ReceiverEff,
+ MayEscape);
}
// EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
@@ -1108,7 +1122,7 @@
: RetEffect::MakeOwned(RetEffect::ObjC, true))
: RetEffect::MakeNotOwned(RetEffect::ObjC);
- return getPersistentSummary(E);
+ return getPersistentSummary(E, ReceiverEff, MayEscape);
}
RetainSummary*
Added: cfe/trunk/test/Analysis/pr_2542_rdar_6793404.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/pr_2542_rdar_6793404.m?rev=69992&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/pr_2542_rdar_6793404.m (added)
+++ cfe/trunk/test/Analysis/pr_2542_rdar_6793404.m Fri Apr 24 16:56:17 2009
@@ -0,0 +1,68 @@
+// RUN: clang-cc -analyze -checker-cfref -pedantic -analyzer-store=basic -verify %s &&
+// RUN: clang-cc -analyze -checker-cfref -pedantic -analyzer-store=region -verify %s
+
+// BEGIN delta-debugging reduced header stuff
+
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+ at class NSCoder;
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+- (id)retain;
+- (oneway void)release;
+ at end
+ at protocol NSCopying
+- (id)copyWithZone:(NSZone *)zone;
+ at end
+ at protocol NSCoding
+- (void)encodeWithCoder:(NSCoder *)aCoder;
+ at end
+ at interface NSObject <NSObject> {}
+- (id)init;
++ (id)alloc;
+ at end
+typedef double NSTimeInterval;
+enum { NSAnimationEaseInOut, NSAnimationEaseIn, NSAnimationEaseOut, NSAnimationLinear };
+typedef NSUInteger NSAnimationCurve;
+ at interface NSAnimation : NSObject <NSCopying, NSCoding> {}
+- (id)initWithDuration:(NSTimeInterval)duration animationCurve:(NSAnimationCurve)animationCurve;
+- (void)startAnimation;
+- (void)setDelegate:(id)delegate;
+ at end
+
+// END delta-debugging reduced header stuff
+
+// From NSAnimation Class Reference
+// -(void)startAnimation
+// The receiver retains itself and is then autoreleased at the end
+// of the animation or when it receives stopAnimation.
+
+ at interface MyClass { }
+- (void)animationDidEnd:(NSAnimation *)animation;
+ at end
+
+ at implementation MyClass
+- (void)f1 {
+ // NOTE: The analyzer doesn't really handle this; it just stops tracking
+ // 'animation' when it is sent the message 'setDelegate:'.
+ NSAnimation *animation = [[NSAnimation alloc] // no-warning
+ initWithDuration:1.0
+ animationCurve:NSAnimationEaseInOut];
+
+ [animation setDelegate:self];
+ [animation startAnimation];
+}
+
+- (void)f2 {
+ NSAnimation *animation = [[NSAnimation alloc] // expected-warning{{leak}}
+ initWithDuration:1.0
+ animationCurve:NSAnimationEaseInOut];
+
+ [animation startAnimation];
+}
+
+- (void)animationDidEnd:(NSAnimation *)animation {
+ [animation release];
+}
+ at end
More information about the cfe-commits
mailing list