retain/release checker: Always generate an "autorelease" summary for an "autorelease" message, and have the summary processing logic treat it as a no-op in GC mode. This change is motivated to encode more of the semantics in the summaries themselves for eventual better diagnostics.
llvm-svn: 63241
This commit is contained in:
parent
511d5ece2b
commit
c783209605
|
@ -979,13 +979,11 @@ void RetainSummaryManager::InitializeClassMethodSummaries() {
|
|||
getPersistentSummary(RetEffect::MakeNotOwned(RetEffect::ObjC)));
|
||||
|
||||
// Create the [NSAutoreleasePool addObject:] summary.
|
||||
if (!isGCEnabled()) {
|
||||
ScratchArgs.push_back(std::make_pair(0, Autorelease));
|
||||
addClsMethSummary(&Ctx.Idents.get("NSAutoreleasePool"),
|
||||
GetUnarySelector("addObject", Ctx),
|
||||
getPersistentSummary(RetEffect::MakeNoRet(),
|
||||
DoNothing, DoNothing));
|
||||
}
|
||||
ScratchArgs.push_back(std::make_pair(0, Autorelease));
|
||||
addClsMethSummary(&Ctx.Idents.get("NSAutoreleasePool"),
|
||||
GetUnarySelector("addObject", Ctx),
|
||||
getPersistentSummary(RetEffect::MakeNoRet(),
|
||||
DoNothing, DoNothing));
|
||||
}
|
||||
|
||||
void RetainSummaryManager::InitializeMethodSummaries() {
|
||||
|
@ -1023,7 +1021,7 @@ void RetainSummaryManager::InitializeMethodSummaries() {
|
|||
addNSObjectMethSummary(GetNullarySelector("drain", Ctx), Summ);
|
||||
|
||||
// Create the "autorelease" selector.
|
||||
Summ = getPersistentSummary(E, isGCEnabled() ? DoNothing : Autorelease);
|
||||
Summ = getPersistentSummary(E, Autorelease);
|
||||
addNSObjectMethSummary(GetNullarySelector("autorelease", Ctx), Summ);
|
||||
|
||||
// For NSWindow, allocated objects are (initially) self-owned.
|
||||
|
@ -2077,6 +2075,8 @@ RefBindings CFRefCount::Update(RefBindings B, SymbolRef sym,
|
|||
return B;
|
||||
|
||||
case Autorelease:
|
||||
if (isGCEnabled()) return B;
|
||||
// Fall-through.
|
||||
case StopTracking:
|
||||
return RefBFactory.Remove(B, sym);
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
// RUN: clang -analyze -checker-cfref -verify -fobjc-gc-only %s &&
|
||||
// RUN: clang -analyze -checker-cfref -analyzer-store-region -fobjc-gc-only -verify %s
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Header stuff.
|
||||
//===----------------------------------------------------------------------===//
|
||||
typedef unsigned int __darwin_natural_t;
|
||||
typedef unsigned long UInt32;
|
||||
typedef signed long CFIndex;
|
||||
typedef const void * CFTypeRef;
|
||||
typedef const struct __CFString * CFStringRef;
|
||||
typedef const struct __CFAllocator * CFAllocatorRef;
|
||||
extern const CFAllocatorRef kCFAllocatorDefault;
|
||||
extern CFTypeRef CFRetain(CFTypeRef cf);
|
||||
extern void CFRelease(CFTypeRef cf);
|
||||
typedef struct {
|
||||
}
|
||||
CFArrayCallBacks;
|
||||
extern const CFArrayCallBacks kCFTypeArrayCallBacks;
|
||||
typedef const struct __CFArray * CFArrayRef;
|
||||
typedef struct __CFArray * CFMutableArrayRef;
|
||||
extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks);
|
||||
extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
|
||||
typedef const struct __CFDictionary * CFDictionaryRef;
|
||||
typedef UInt32 CFStringEncoding;
|
||||
enum {
|
||||
kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 };
|
||||
extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
|
||||
typedef double CFTimeInterval;
|
||||
typedef CFTimeInterval CFAbsoluteTime;
|
||||
typedef const struct __CFDate * CFDateRef;
|
||||
extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
|
||||
extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
|
||||
typedef __darwin_natural_t natural_t;
|
||||
typedef natural_t mach_port_name_t;
|
||||
typedef mach_port_name_t mach_port_t;
|
||||
typedef signed char BOOL;
|
||||
typedef struct _NSZone NSZone;
|
||||
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
|
||||
@protocol NSObject - (BOOL)isEqual:(id)object;
|
||||
- (id)retain;
|
||||
- (oneway void)release;
|
||||
- (id)autorelease;
|
||||
@end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone;
|
||||
@end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
|
||||
@end @interface NSObject <NSObject> {
|
||||
}
|
||||
@end typedef float CGFloat;
|
||||
typedef double NSTimeInterval;
|
||||
@interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate;
|
||||
@end enum {
|
||||
NSObjCNoType = 0, NSObjCVoidType = 'v', NSObjCCharType = 'c', NSObjCShortType = 's', NSObjCLongType = 'l', NSObjCLonglongType = 'q', NSObjCFloatType = 'f', NSObjCDoubleType = 'd', NSObjCBoolType = 'B', NSObjCSelectorType = ':', NSObjCObjectType = '@', NSObjCStructType = '{', NSObjCPointerType = '^', NSObjCStringType = '*', NSObjCArrayType = '[', NSObjCUnionType = '(', NSObjCBitfield = 'b' }
|
||||
__attribute__((deprecated));
|
||||
typedef int kern_return_t;
|
||||
typedef kern_return_t mach_error_t;
|
||||
typedef mach_port_t io_object_t;
|
||||
typedef io_object_t io_service_t;
|
||||
typedef struct __DASession * DASessionRef;
|
||||
extern DASessionRef DASessionCreate( CFAllocatorRef allocator );
|
||||
typedef struct __DADisk * DADiskRef;
|
||||
extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name );
|
||||
extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media );
|
||||
extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk );
|
||||
extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk );
|
||||
@interface NSAppleEventManager : NSObject {
|
||||
}
|
||||
@end enum {
|
||||
kDAReturnSuccess = 0, kDAReturnError = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x01, kDAReturnBusy = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x02, kDAReturnBadArgument = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x03, kDAReturnExclusiveAccess = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x04, kDAReturnNoResources = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x05, kDAReturnNotFound = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x06, kDAReturnNotMounted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x07, kDAReturnNotPermitted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x08, kDAReturnNotPrivileged = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x09, kDAReturnNotReady = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0A, kDAReturnNotWritable = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0B, kDAReturnUnsupported = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0C };
|
||||
typedef mach_error_t DAReturn;
|
||||
typedef const struct __DADissenter * DADissenterRef;
|
||||
extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Test cases.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void f1() {
|
||||
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
||||
id x = [(id) A autorelease];
|
||||
CFRelease((CFMutableArrayRef) x); // no-warning
|
||||
}
|
Loading…
Reference in New Issue