From: Ted Kremenek Date: Thu, 23 Apr 2009 19:11:35 +0000 (+0000) Subject: Per discussions with Ken Ferry and Paul Marks () greatly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e87450e5a398543b85205b3255d4c36204c00182;p=clang Per discussions with Ken Ferry and Paul Marks () greatly extend the number of objects tracked by the retain/release checker by assuming that all class and instance methods should follow Cocoa object "getter" and "alloc/new" conventions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69908 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 0e8d67ca29..2dfacfd42e 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1074,15 +1074,18 @@ RetainSummaryManager::getMethodSummary(ObjCMessageExpr* ME, if (!isTrackedObjectType(Ctx.getCanonicalType(ME->getType()))) return 0; - if (followsFundamentalRule(s)) { - RetEffect E = isGCEnabled() ? RetEffect::MakeNoRet() - : RetEffect::MakeOwned(RetEffect::ObjC, true); - RetainSummary* Summ = getPersistentSummary(E); - ObjCMethodSummaries[ME] = Summ; - return Summ; - } + // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned + // by instance methods. + + RetEffect E = + followsFundamentalRule(s) + ? (isGCEnabled() ? RetEffect::MakeNotOwned(RetEffect::ObjC) + : RetEffect::MakeOwned(RetEffect::ObjC, true)) + : RetEffect::MakeNotOwned(RetEffect::ObjC); - return 0; + RetainSummary* Summ = getPersistentSummary(E); + ObjCMethodSummaries[ME] = Summ; + return Summ; } RetainSummary* @@ -1099,7 +1102,17 @@ RetainSummaryManager::getClassMethodSummary(IdentifierInfo* ClsName, if (I != ObjCClassMethodSummaries.end()) return I->second; - return 0; + // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned + // by class methods. + const char* s = S.getIdentifierInfoForSlot(0)->getName(); + RetEffect E = followsFundamentalRule(s) + ? (isGCEnabled() ? RetEffect::MakeNotOwned(RetEffect::ObjC) + : RetEffect::MakeOwned(RetEffect::ObjC, true)) + : RetEffect::MakeNotOwned(RetEffect::ObjC); + + RetainSummary* Summ = getPersistentSummary(E); + ObjCClassMethodSummaries[ObjCSummaryKey(ClsName, S)] = Summ; + return Summ; } void RetainSummaryManager::InitializeClassMethodSummaries() { @@ -2351,9 +2364,8 @@ namespace { BadRelease(CFRefCount* tf) : CFRefBug(tf, "bad release") {} const char* getDescription() const { - return "Incorrect decrement of the reference count of a " - "Core Foundation object (" - "the object is not owned at this point by the caller)"; + return "Incorrect decrement of the reference count of an " + "object is not owned at this point by the caller"; } }; diff --git a/test/Analysis/NSString.m b/test/Analysis/NSString.m index 6e644d5fbc..a95e8868c3 100644 --- a/test/Analysis/NSString.m +++ b/test/Analysis/NSString.m @@ -73,6 +73,7 @@ typedef NSUInteger NSStringCompareOptions; - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange locale:(id)locale; - (NSComparisonResult)caseInsensitiveCompare:(NSString *)string; - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator; ++ (id)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); @end @interface NSSimpleCString : NSString {} @end @interface NSConstantString : NSSimpleCString @end @@ -243,3 +244,10 @@ void test_objc_atomicCompareAndSwap() { [old release]; } +// Test stringWithFormat () +void test_stringWithFormat() { + NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain]; + [string release]; + [string release]; // expected-warning{{Incorrect decrement of the reference count}} +} + diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 5a0471ae88..012e340f56 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -335,7 +335,7 @@ static void rdar_6659160(char *inkind, char *inname) return; [kind release]; - [name release]; + [name release]; // expected-warning{{Incorrect decrement of the reference count}} } // PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming