[llvm-branch-commits] [cfe-branch] r71441 - in /cfe/branches/Apple/Dib: lib/Analysis/CFRefCount.cpp test/Analysis/NSString.m
Mike Stump
mrs at apple.com
Mon May 11 10:23:56 PDT 2009
Author: mrs
Date: Mon May 11 12:23:56 2009
New Revision: 71441
URL: http://llvm.org/viewvc/llvm-project?rev=71441&view=rev
Log:
Merge in 71432:
Fix a bug found by Thomas Clement where 'return [[[NSString alloc] init] autorelease]' would emit a false 'too many overreleases' error.
Modified:
cfe/branches/Apple/Dib/lib/Analysis/CFRefCount.cpp
cfe/branches/Apple/Dib/test/Analysis/NSString.m
Modified: cfe/branches/Apple/Dib/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Analysis/CFRefCount.cpp?rev=71441&r1=71440&r2=71441&view=diff
==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/CFRefCount.cpp Mon May 11 12:23:56 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/branches/Apple/Dib/test/Analysis/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Analysis/NSString.m?rev=71441&r1=71440&r2=71441&view=diff
==============================================================================
--- cfe/branches/Apple/Dib/test/Analysis/NSString.m (original)
+++ cfe/branches/Apple/Dib/test/Analysis/NSString.m Mon May 11 12:23:56 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 llvm-branch-commits
mailing list