I see test/Analysis/retain-release.m failing, could you check it out ? -Argiris
On Jul 15, 2011, at 3:17 PM, Jordy Rose wrote: > Author: jrose > Date: Fri Jul 15 17:17:54 2011 > New Revision: 135310 > > URL: http://llvm.org/viewvc/llvm-project?rev=135310&view=rev > Log: > Add tests for CFRefReport's path notes, and fix a few typos and non-standard > terminology ('+0 retain counts') caught by the tests. > > Added: > cfe/trunk/test/Analysis/retain-release-path-notes-gc.m > cfe/trunk/test/Analysis/retain-release-path-notes.m > Modified: > cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp > > Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=135310&r1=135309&r2=135310&view=diff > ============================================================================== > --- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original) > +++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Fri Jul 15 17:17:54 2011 > @@ -1925,7 +1925,7 @@ > CFRefBug(tf, "Method should return an owned object") {} > > const char *getDescription() const { > - return "Object with +0 retain counts returned to caller where a +1 " > + return "Object with a +0 retain count returned to caller where a +1 " > "(owning) retain count is expected"; > } > }; > @@ -2112,7 +2112,7 @@ > > if (static_cast<CFRefBug&>(getBugType()).getTF().isGCEnabled()) { > assert(CurrV.getObjKind() == RetEffect::CF); > - os << " " > + os << ". " > "Core Foundation objects are not automatically garbage collected."; > } > } > @@ -2434,14 +2434,14 @@ > > if (RV->getKind() == RefVal::ErrorLeakReturned) { > // FIXME: Per comments in rdar://6320065, "create" only applies to CF > - // ojbects. Only "copy", "alloc", "retain" and "new" transfer ownership > + // objects. Only "copy", "alloc", "retain" and "new" transfer ownership > // to the caller for NS objects. > const Decl *D = &EndN->getCodeDecl(); > if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { > os << " is returned from a method whose name ('" > << MD->getSelector().getAsString() > << "') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'." > - " This violates the naming convention rules " > + " This violates the naming convention rules" > " given in the Memory Management Guide for Cocoa"; > } > else { > @@ -2449,7 +2449,7 @@ > os << " is return from a function whose name ('" > << FD->getNameAsString() > << "') does not contain 'Copy' or 'Create'. This violates the > naming" > - " convention rules given the Memory Management Guide for Core " > + " convention rules given the Memory Management Guide for Core" > " Foundation"; > } > } > @@ -3306,15 +3306,10 @@ > > std::string sbuf; > llvm::raw_string_ostream os(sbuf); > - os << "Object over-autoreleased: object was sent -autorelease"; > + os << "Object over-autoreleased: object was sent -autorelease "; > if (V.getAutoreleaseCount() > 1) > - os << V.getAutoreleaseCount() << " times"; > - os << " but the object has "; > - if (V.getCount() == 0) > - os << "zero (locally visible)"; > - else > - os << "+" << V.getCount(); > - os << " retain counts"; > + os << V.getAutoreleaseCount() << " times "; > + os << "but the object has a +" << V.getCount() << " retain count"; > > CFRefReport *report = > new CFRefReport(*static_cast<CFRefBug*>(overAutorelease), > > Added: cfe/trunk/test/Analysis/retain-release-path-notes-gc.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-path-notes-gc.m?rev=135310&view=auto > ============================================================================== > --- cfe/trunk/test/Analysis/retain-release-path-notes-gc.m (added) > +++ cfe/trunk/test/Analysis/retain-release-path-notes-gc.m Fri Jul 15 > 17:17:54 2011 > @@ -0,0 +1,74 @@ > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze > -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease > -analyzer-store=basic -analyzer-output=text -fobjc-gc-only -verify %s > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze > -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease > -analyzer-store=region -analyzer-output=text -fobjc-gc-only -verify %s > + > +/*** > +This file is for testing the path-sensitive notes for retain/release errors. > +Its goal is to have simple branch coverage of any path-based diagnostics, > +not to actually check all possible retain/release errors. > + > +This file is for notes that only appear in a GC-enabled analysis. > +Non-specific and ref-count-only notes should go in > retain-release-path-notes.m. > +***/ > + > +@interface NSObject > ++ (id)alloc; > +- (id)init; > +- (void)dealloc; > + > +- (Class)class; > + > +- (id)retain; > +- (void)release; > +- (void)autorelease; > +@end > + > +@interface Foo : NSObject > +- (id)methodWithValue; > +@property(retain) id propertyValue; > +@end > + > +typedef struct CFType *CFTypeRef; > +CFTypeRef CFRetain(CFTypeRef); > +void CFRelease(CFTypeRef); > + > +id NSMakeCollectable(CFTypeRef); > +CFTypeRef CFMakeCollectable(CFTypeRef); > + > +CFTypeRef CFCreateSomething(); > +CFTypeRef CFGetSomething(); > + > + > +void creationViaCFCreate () { > + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count. Core Foundation objects are not automatically > garbage collected}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void makeCollectable () { > + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count. Core Foundation objects are not automatically > garbage collected}} > + CFRetain(leaked); // expected-note{{Reference count incremented. The > object now has a +2 retain count}} > + CFMakeCollectable(leaked); // expected-note{{In GC mode a call to > 'CFMakeCollectable' decrements an object's retain count and registers the > object with the garbage collector. An object must have a 0 retain count to be > garbage collected. After this call its retain count is +1.}} > + NSMakeCollectable(leaked); // expected-note{{In GC mode a call to > 'NSMakeCollectable' decrements an object's retain count and registers the > object with the garbage collector. Since it now has a 0 retain count the > object can be automatically collected by the garbage collector}} > + CFRetain(leaked); // expected-note{{Reference count incremented. The > object now has a +1 retain count. The object is not eligible for garbage > collection until the retain count reaches 0 again.}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void retainReleaseIgnored () { > + id object = [[NSObject alloc] init]; // expected-note{{Method returns an > Objective-C object with a +0 retain count}} > + [object retain]; // expected-note{{In GC mode the 'retain' message has no > effect}} > + [object release]; // expected-note{{In GC mode the 'release' message has > no effect}} > + [object autorelease]; // expected-note{{In GC mode an 'autorelease' has no > effect}} > + CFRelease((CFTypeRef)object); // expected-warning{{Incorrect decrement of > the reference count of an object that is not owned at this point by the > caller}} expected-note{{Incorrect decrement of the reference count of an > object that is not owned at this point by the caller}} > +} > + > +@implementation Foo (FundamentalRuleUnderGC) > +- (id)getViolation { > + id object = (id) CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count. Core Foundation objects are not automatically > garbage collected.}} > + return object; // expected-note{{Object returned to caller as an owning > reference (single retain count transferred to caller)}} expected-note{{Object > leaked: object allocated and stored into 'object' and returned from method > 'getViolation' is potentially leaked when using garbage collection. Callers > of this method do not expect a returned object with a +1 retain count since > they expect the object to be managed by the garbage collector}} > +} > + > +- (id)copyViolation { > + id object = (id) CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count. Core Foundation objects are not automatically > garbage collected.}} > + return object; // expected-note{{Object returned to caller as an owning > reference (single retain count transferred to caller)}} expected-note{{Object > leaked: object allocated and stored into 'object' and returned from method > 'copyViolation' is potentially leaked when using garbage collection. Callers > of this method do not expect a returned object with a +1 retain count since > they expect the object to be managed by the garbage collector}} > +} > +@end > + > > Added: cfe/trunk/test/Analysis/retain-release-path-notes.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-path-notes.m?rev=135310&view=auto > ============================================================================== > --- cfe/trunk/test/Analysis/retain-release-path-notes.m (added) > +++ cfe/trunk/test/Analysis/retain-release-path-notes.m Fri Jul 15 17:17:54 > 2011 > @@ -0,0 +1,123 @@ > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze > -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease > -analyzer-store=basic -analyzer-output=text -verify %s > +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze > -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease > -analyzer-store=region -analyzer-output=text -verify %s > + > +/*** > +This file is for testing the path-sensitive notes for retain/release errors. > +Its goal is to have simple branch coverage of any path-based diagnostics, > +not to actually check all possible retain/release errors. > + > +This file includes notes that only appear in a ref-counted analysis. > +GC-specific notes should go in retain-release-path-notes-gc.m. > +***/ > + > +@interface NSObject > ++ (id)alloc; > +- (id)init; > +- (void)dealloc; > + > +- (Class)class; > + > +- (id)retain; > +- (void)release; > +- (void)autorelease; > +@end > + > +@interface Foo : NSObject > +- (id)methodWithValue; > +@property(retain) id propertyValue; > +@end > + > +typedef struct CFType *CFTypeRef; > +CFTypeRef CFRetain(CFTypeRef); > +void CFRelease(CFTypeRef); > + > +id NSMakeCollectable(CFTypeRef); > +CFTypeRef CFMakeCollectable(CFTypeRef); > + > +CFTypeRef CFCreateSomething(); > +CFTypeRef CFGetSomething(); > + > + > +void creationViaAlloc () { > + id leaked = [[NSObject alloc] init]; // expected-warning{{leak}} > expected-note{{Method returns an Objective-C object with a +1 retain count}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void creationViaCFCreate () { > + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void acquisitionViaMethod (Foo *foo) { > + id leaked = [foo methodWithValue]; // expected-warning{{leak}} > expected-note{{Method returns an Objective-C object with a +0 retain count}} > + [leaked retain]; // expected-note{{Reference count incremented. The object > now has a +1 retain count}} > + [leaked retain]; // expected-note{{Reference count incremented. The object > now has a +2 retain count}} > + [leaked release]; // expected-note{{Reference count decremented. The > object now has a +1 retain count}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void acquisitionViaProperty (Foo *foo) { > + id leaked = foo.propertyValue; // expected-warning{{leak}} > expected-note{{Property returns an Objective-C object with a +0 retain count}} > + [leaked retain]; // expected-note{{Reference count incremented. The object > now has a +1 retain count}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void acquisitionViaCFFunction () { > + CFTypeRef leaked = CFGetSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFGetSomething' returns a Core Foundation > object with a +0 retain count}} > + CFRetain(leaked); // expected-note{{Reference count incremented. The > object now has a +1 retain count}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +void explicitDealloc () { > + id object = [[NSObject alloc] init]; // expected-note{{Method returns an > Objective-C object with a +1 retain count}} > + [object dealloc]; // expected-note{{Object released by directly sending > the '-dealloc' message}} > + [object class]; // expected-warning{{Reference-counted object is used > after it is released}} // expected-note{{Reference-counted object is used > after it is released}} > +} > + > +void implicitDealloc () { > + id object = [[NSObject alloc] init]; // expected-note{{Method returns an > Objective-C object with a +1 retain count}} > + [object release]; // expected-note{{Object released}} > + [object class]; // expected-warning{{Reference-counted object is used > after it is released}} // expected-note{{Reference-counted object is used > after it is released}} > +} > + > +void overAutorelease () { > + id object = [[NSObject alloc] init]; // expected-note{{Method returns an > Objective-C object with a +1 retain count}} > + [object autorelease]; // expected-note{{Object sent -autorelease message}} > + [object autorelease]; // expected-note{{Object sent -autorelease message}} > + return; // expected-warning{{Object sent -autorelease too many times}} > expected-note{{Object over-autoreleased: object was sent -autorelease 2 times > but the object has a +1 retain count}} > +} > + > +void autoreleaseUnowned (Foo *foo) { > + id object = foo.propertyValue; // expected-note{{Property returns an > Objective-C object with a +0 retain count}} > + [object autorelease]; // expected-note{{Object sent -autorelease message}} > + return; // expected-warning{{Object sent -autorelease too many times}} > expected-note{{Object over-autoreleased: object was sent -autorelease but the > object has a +0 retain count}} > +} > + > +void makeCollectableIgnored () { > + CFTypeRef leaked = CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain count}} > + CFMakeCollectable(leaked); // expected-note{{When GC is not enabled a call > to 'CFMakeCollectable' has no effect on its argument}} > + NSMakeCollectable(leaked); // expected-note{{When GC is not enabled a call > to 'NSMakeCollectable' has no effect on its argument}} > + return; // expected-note{{Object leaked: object allocated and stored into > 'leaked' is not referenced later in this execution path and has a retain > count of +1}} > +} > + > +CFTypeRef CFCopyRuleViolation () { > + CFTypeRef object = CFGetSomething(); // expected-note{{Call to function > 'CFGetSomething' returns a Core Foundation object with a +0 retain counte}} > + return object; // expected-warning{{Object with a +0 retain count returned > to caller where a +1 (owning) retain count is expected}} > expected-note{{Object returned to caller with a +0 retain count}} > expected-note{{Object with a +0 retain count returned to caller where a +1 > (owning) retain count is expected}} > +} > + > +CFTypeRef CFGetRuleViolation () { > + CFTypeRef object = CFCreateSomething(); // expected-warning{{leak}} > expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation > object with a +1 retain counte}} > + return object; // expected-note{{Object returned to caller as an owning > reference (single retain count transferred to caller)}} expected-note{{Object > leaked: object allocated and stored into 'object' is return from a function > whose name ('CFGetRuleViolation') does not contain 'Copy' or 'Create'. This > violates the naming convention rules given the Memory Management Guide for > Core Foundation}} > +} > + > +@implementation Foo (FundamentalMemoryManagementRules) > +- (id)copyViolation { > + id result = self.propertyValue; // expected-note{{Property returns an > Objective-C object with a +0 retain count}} > + return result; // expected-warning{{Object with a +0 retain count returned > to caller where a +1 (owning) retain count is expected}} > expected-note{{Object returned to caller with a +0 retain count}} > expected-note{{Object with a +0 retain count returned to caller where a +1 > (owning) retain count is expected}} > +} > + > +- (id)getViolation { > + id result = [[Foo alloc] init]; // expected-warning{{leak}} > expected-note{{Method returns an Objective-C object with a +1 retain count}} > + return result; // expected-note{{Object returned to caller as an owning > reference (single retain count transferred to caller)}} expected-note{{Object > leaked: object allocated and stored into 'result' is returned from a method > whose name ('getViolation') does not start with 'copy', 'mutableCopy', > 'alloc' or 'new'. This violates the naming convention rules given in the > Memory Management Guide for Cocoa}} > +} > +@end > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
