[cfe-commits] r71432 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/NSString.m
Ted Kremenek
kremenek at apple.com
Mon May 11 08:26:12 PDT 2009
Author: kremenek
Date: Mon May 11 10:26:06 2009
New Revision: 71432
URL: http://llvm.org/viewvc/llvm-project?rev=71432&view=rev
Log:
Fix a bug found by Thomas Clement where 'return [[[NSString alloc] init] autorelease]' would emit a false 'too many overreleases' error.
Modified:
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/test/Analysis/NSString.m
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=71432&r1=71431&r2=71432&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon May 11 10:26:06 2009
@@ -3314,12 +3314,20 @@
assert(!isGCEnabled() && "Autorelease counts in GC mode?");
unsigned Cnt = V.getCount();
+ // FIXME: Handle sending 'autorelease' to already released object.
+
+ if (V.getKind() == RefVal::ReturnedOwned)
+ ++Cnt;
+
if (ACnt <= Cnt) {
if (ACnt == Cnt) {
V.clearCounts();
- V = V ^ RefVal::NotOwned;
+ if (V.getKind() == RefVal::ReturnedOwned)
+ V = V ^ RefVal::ReturnedNotOwned;
+ else
+ V = V ^ RefVal::NotOwned;
}
- else {
+ else {
V.setCount(Cnt - ACnt);
V.setAutoreleaseCount(0);
}
Modified: cfe/trunk/test/Analysis/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NSString.m?rev=71432&r1=71431&r2=71432&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/NSString.m (original)
+++ cfe/trunk/test/Analysis/NSString.m Mon May 11 10:26:06 2009
@@ -36,6 +36,7 @@
- (BOOL)isEqual:(id)object;
- (oneway void)release;
- (id)retain;
+- (id)autorelease;
@end
@protocol NSCopying
- (id)copyWithZone:(NSZone *)zone;
@@ -173,6 +174,17 @@
CFRelease(ref); // expected-warning{{Reference-counted object is used after it is released}}
}
+// Test regular use of -autorelease
+ at interface TestAutorelease
+-(NSString*) getString;
+ at end
+ at implementation TestAutorelease
+-(NSString*) getString {
+ NSString *str = [[NSString alloc] init];
+ return [str autorelease]; // no-warning
+}
+ at end
+
@interface C1 : NSObject {}
- (NSString*) getShared;
+ (C1*) sharedInstance;
More information about the cfe-commits
mailing list