2012-09-12 09:11:05 +08:00
|
|
|
// RUN: rm -f %t.objc.plist %t.objcpp.plist
|
2018-12-21 08:18:58 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
|
|
|
|
// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
|
|
|
|
// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
|
Emit !callback metadata and introduce the callback attribute
With commit r351627, LLVM gained the ability to apply (existing) IPO
optimizations on indirections through callbacks, or transitive calls.
The general idea is that we use an abstraction to hide the middle man
and represent the callback call in the context of the initial caller.
It is described in more detail in the commit message of the LLVM patch
r351627, the llvm::AbstractCallSite class description, and the
language reference section on callback-metadata.
This commit enables clang to emit !callback metadata that is
understood by LLVM. It does so in three different cases:
1) For known broker functions declarations that are directly
generated, e.g., __kmpc_fork_call for the OpenMP pragma parallel.
2) For known broker functions that are identified by their name and
source location through the builtin detection, e.g.,
pthread_create from the POSIX thread API.
3) For user annotated functions that carry the "callback(callee, ...)"
attribute. The attribute has to include the name, or index, of
the callback callee and how the passed arguments can be
identified (as many as the callback callee has). See the callback
attribute documentation for detailed information.
Differential Revision: https://reviews.llvm.org/D55483
llvm-svn: 351629
2019-01-19 13:36:54 +08:00
|
|
|
// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify=expected,C %s\
|
2019-01-12 02:12:49 +08:00
|
|
|
// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objc.plist
|
2018-12-21 08:18:58 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
|
|
|
|
// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
|
|
|
|
// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
|
|
|
|
// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
|
|
|
|
// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist\
|
|
|
|
// RUN: -x objective-c++ -std=gnu++98
|
2019-01-30 03:29:59 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
|
|
|
|
// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
|
|
|
|
// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
|
|
|
|
// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
|
|
|
|
// RUN: -Wno-objc-root-class -x objective-c++ -std=gnu++98\
|
|
|
|
// RUN: -analyzer-config osx.cocoa.RetainCount:TrackNSCFStartParam=true\
|
|
|
|
// RUN: -DTRACK_START_PARAM
|
2019-01-12 02:12:49 +08:00
|
|
|
// RUN: cat %t.objcpp.plist | %diff_plist %S/Inputs/expected-plists/retain-release.m.objcpp.plist -
|
|
|
|
// RUN: cat %t.objc.plist | %diff_plist %S/Inputs/expected-plists/retain-release.m.objc.plist -
|
2009-01-21 14:57:53 +08:00
|
|
|
|
2018-12-21 08:18:58 +08:00
|
|
|
void clang_analyzer_eval(int);
|
|
|
|
|
2009-07-17 08:19:33 +08:00
|
|
|
#if __has_feature(attribute_ns_returns_retained)
|
|
|
|
#define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
|
|
|
|
#endif
|
|
|
|
#if __has_feature(attribute_cf_returns_retained)
|
|
|
|
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
|
|
|
|
#endif
|
2010-02-18 08:06:12 +08:00
|
|
|
#if __has_feature(attribute_ns_returns_not_retained)
|
|
|
|
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
|
|
|
|
#endif
|
|
|
|
#if __has_feature(attribute_cf_returns_not_retained)
|
|
|
|
#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
|
|
|
|
#endif
|
2011-01-27 14:54:14 +08:00
|
|
|
#if __has_feature(attribute_ns_consumes_self)
|
|
|
|
#define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
|
|
|
|
#endif
|
2011-01-28 02:43:03 +08:00
|
|
|
#if __has_feature(attribute_ns_consumed)
|
|
|
|
#define NS_CONSUMED __attribute__((ns_consumed))
|
|
|
|
#endif
|
|
|
|
#if __has_feature(attribute_cf_consumed)
|
|
|
|
#define CF_CONSUMED __attribute__((cf_consumed))
|
|
|
|
#endif
|
2012-12-21 03:36:22 +08:00
|
|
|
#if __has_attribute(ns_returns_autoreleased)
|
|
|
|
#define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
|
|
|
|
#endif
|
2009-07-17 08:19:33 +08:00
|
|
|
|
2009-01-13 05:45:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-05-21 06:39:57 +08:00
|
|
|
// The following code is reduced using delta-debugging from Mac OS X headers:
|
|
|
|
//
|
|
|
|
// #include <Cocoa/Cocoa.h>
|
|
|
|
// #include <CoreFoundation/CoreFoundation.h>
|
|
|
|
// #include <DiskArbitration/DiskArbitration.h>
|
|
|
|
// #include <QuartzCore/QuartzCore.h>
|
|
|
|
// #include <Quartz/Quartz.h>
|
2009-06-17 04:44:39 +08:00
|
|
|
// #include <IOKit/IOKitLib.h>
|
2009-01-13 05:45:02 +08:00
|
|
|
//
|
|
|
|
// It includes the basic definitions for the test cases below.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef unsigned int __darwin_natural_t;
|
2009-06-17 04:44:39 +08:00
|
|
|
typedef unsigned long uintptr_t;
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
typedef unsigned long long uint64_t;
|
2009-04-29 08:41:31 +08:00
|
|
|
typedef unsigned int UInt32;
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef signed long CFIndex;
|
2012-01-04 08:35:48 +08:00
|
|
|
typedef CFIndex CFByteOrder;
|
2009-08-20 08:57:22 +08:00
|
|
|
typedef struct {
|
|
|
|
CFIndex location;
|
|
|
|
CFIndex length;
|
|
|
|
} CFRange;
|
|
|
|
static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
|
|
|
|
CFRange range;
|
|
|
|
range.location = loc;
|
|
|
|
range.length = len;
|
|
|
|
return range;
|
|
|
|
}
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef const void * CFTypeRef;
|
|
|
|
typedef const struct __CFString * CFStringRef;
|
|
|
|
typedef const struct __CFAllocator * CFAllocatorRef;
|
2009-06-17 04:44:39 +08:00
|
|
|
extern const CFAllocatorRef kCFAllocatorDefault;
|
2013-10-08 01:16:52 +08:00
|
|
|
|
2009-01-13 05:45:02 +08:00
|
|
|
extern CFTypeRef CFRetain(CFTypeRef cf);
|
|
|
|
extern void CFRelease(CFTypeRef cf);
|
2012-11-08 01:12:37 +08:00
|
|
|
extern CFTypeRef CFMakeCollectable(CFTypeRef cf);
|
2013-10-08 01:16:52 +08:00
|
|
|
extern CFTypeRef CFAutorelease(CFTypeRef CF_CONSUMED cf);
|
|
|
|
|
2009-01-13 05:45:02 +08:00
|
|
|
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);
|
2009-03-10 06:28:18 +08:00
|
|
|
extern void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value);
|
2009-08-20 08:57:22 +08:00
|
|
|
typedef struct {
|
|
|
|
}
|
|
|
|
CFDictionaryKeyCallBacks;
|
|
|
|
extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
|
|
|
|
typedef struct {
|
|
|
|
}
|
|
|
|
CFDictionaryValueCallBacks;
|
|
|
|
extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks;
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef const struct __CFDictionary * CFDictionaryRef;
|
2009-06-17 04:44:39 +08:00
|
|
|
typedef struct __CFDictionary * CFMutableDictionaryRef;
|
2009-08-20 08:57:22 +08:00
|
|
|
extern CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
|
2009-01-13 05:45:02 +08:00
|
|
|
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;
|
2009-03-10 06:28:18 +08:00
|
|
|
extern CFAbsoluteTime CFAbsoluteTimeGetCurrent(void);
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef const struct __CFDate * CFDateRef;
|
|
|
|
extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
|
2009-06-17 04:44:39 +08:00
|
|
|
extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef __darwin_natural_t natural_t;
|
|
|
|
typedef natural_t mach_port_name_t;
|
|
|
|
typedef mach_port_name_t mach_port_t;
|
2009-04-29 08:41:31 +08:00
|
|
|
typedef int kern_return_t;
|
|
|
|
typedef kern_return_t mach_error_t;
|
2009-08-20 08:57:22 +08:00
|
|
|
enum {
|
|
|
|
kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 };
|
|
|
|
typedef CFIndex CFNumberType;
|
|
|
|
typedef const struct __CFNumber * CFNumberRef;
|
|
|
|
extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
|
|
|
|
typedef const struct __CFAttributedString *CFAttributedStringRef;
|
|
|
|
typedef struct __CFAttributedString *CFMutableAttributedStringRef;
|
|
|
|
extern CFAttributedStringRef CFAttributedStringCreate(CFAllocatorRef alloc, CFStringRef str, CFDictionaryRef attributes) ;
|
|
|
|
extern CFMutableAttributedStringRef CFAttributedStringCreateMutableCopy(CFAllocatorRef alloc, CFIndex maxLength, CFAttributedStringRef aStr) ;
|
|
|
|
extern void CFAttributedStringSetAttribute(CFMutableAttributedStringRef aStr, CFRange range, CFStringRef attrName, CFTypeRef value) ;
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef signed char BOOL;
|
2009-04-29 08:41:31 +08:00
|
|
|
typedef unsigned long NSUInteger;
|
2009-06-17 04:44:39 +08:00
|
|
|
@class NSString, Protocol;
|
|
|
|
extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef struct _NSZone NSZone;
|
|
|
|
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
|
2009-08-20 13:13:36 +08:00
|
|
|
@protocol NSObject
|
|
|
|
- (BOOL)isEqual:(id)object;
|
2009-01-13 05:45:02 +08:00
|
|
|
- (id)retain;
|
|
|
|
- (oneway void)release;
|
2009-01-29 05:20:48 +08:00
|
|
|
- (id)autorelease;
|
2012-03-07 04:06:12 +08:00
|
|
|
- (NSString *)description;
|
2011-06-14 00:42:53 +08:00
|
|
|
- (id)init;
|
2012-03-07 04:06:12 +08:00
|
|
|
@end
|
|
|
|
@protocol NSCopying
|
|
|
|
- (id)copyWithZone:(NSZone *)zone;
|
|
|
|
@end
|
|
|
|
@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone;
|
|
|
|
@end
|
|
|
|
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
|
2009-08-20 13:13:36 +08:00
|
|
|
@end
|
|
|
|
@interface NSObject <NSObject> {}
|
2009-03-14 04:27:06 +08:00
|
|
|
+ (id)allocWithZone:(NSZone *)zone;
|
2009-04-29 08:41:31 +08:00
|
|
|
+ (id)alloc;
|
2013-02-01 06:06:02 +08:00
|
|
|
+ (id)new;
|
2009-04-29 08:41:31 +08:00
|
|
|
- (void)dealloc;
|
2009-08-20 13:13:36 +08:00
|
|
|
@end
|
|
|
|
@interface NSObject (NSCoderMethods)
|
|
|
|
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
|
|
|
|
@end
|
|
|
|
extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
|
2009-04-29 08:41:31 +08:00
|
|
|
typedef struct {
|
|
|
|
}
|
|
|
|
NSFastEnumerationState;
|
2012-03-07 04:06:12 +08:00
|
|
|
@protocol NSFastEnumeration
|
|
|
|
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
|
|
|
|
@end
|
|
|
|
@class NSString, NSDictionary;
|
2009-08-20 08:57:22 +08:00
|
|
|
@interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value;
|
2012-05-12 13:10:43 +08:00
|
|
|
@end
|
|
|
|
@interface NSNumber : NSValue
|
|
|
|
- (char)charValue;
|
2009-08-20 08:57:22 +08:00
|
|
|
- (id)initWithInt:(int)value;
|
2012-05-12 13:10:43 +08:00
|
|
|
+ (NSNumber *)numberWithInt:(int)value;
|
|
|
|
@end
|
|
|
|
@class NSString;
|
2012-03-07 04:06:12 +08:00
|
|
|
@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
|
|
|
|
- (NSUInteger)count;
|
|
|
|
- (id)initWithObjects:(const id [])objects count:(NSUInteger)cnt;
|
|
|
|
+ (id)arrayWithObject:(id)anObject;
|
|
|
|
+ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
|
|
|
|
+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
|
|
|
|
- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
|
|
|
|
- (id)initWithArray:(NSArray *)array;
|
2009-05-21 06:39:57 +08:00
|
|
|
@end @interface NSArray (NSArrayCreation) + (id)array;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end @interface NSAutoreleasePool : NSObject {
|
2009-05-21 06:39:57 +08:00
|
|
|
}
|
|
|
|
- (void)drain;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end extern NSString * const NSBundleDidLoadNotification;
|
|
|
|
typedef double NSTimeInterval;
|
2009-04-29 08:41:31 +08:00
|
|
|
@interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end typedef unsigned short unichar;
|
2011-10-06 07:54:29 +08:00
|
|
|
@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
|
|
|
|
- (NSUInteger)length;
|
|
|
|
- (NSString *)stringByAppendingString:(NSString *)aString;
|
2009-04-29 08:41:31 +08:00
|
|
|
- ( const char *)UTF8String;
|
2009-03-10 06:28:18 +08:00
|
|
|
- (id)initWithUTF8String:(const char *)nullTerminatedCString;
|
|
|
|
+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end @class NSString, NSURL, NSError;
|
2009-06-17 04:44:39 +08:00
|
|
|
@interface NSData : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length;
|
2009-05-21 06:39:57 +08:00
|
|
|
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
|
|
|
|
+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary;
|
2012-03-07 04:06:12 +08:00
|
|
|
@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
|
|
|
|
- (NSUInteger)count;
|
|
|
|
+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
|
|
|
|
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
|
|
|
|
@end
|
|
|
|
@interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey;
|
2009-04-29 08:41:31 +08:00
|
|
|
- (void)setObject:(id)anObject forKey:(id)aKey;
|
2014-01-03 09:19:28 +08:00
|
|
|
@end
|
|
|
|
@interface NSMutableDictionary (NSMutableDictionaryCreation) + (id)dictionaryWithCapacity:(NSUInteger)numItems;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSNull : NSObject
|
|
|
|
+ (NSNull*) null;
|
|
|
|
@end
|
|
|
|
|
|
|
|
typedef double CGFloat;
|
2009-06-17 04:44:39 +08:00
|
|
|
struct CGSize {
|
|
|
|
};
|
|
|
|
typedef struct CGSize CGSize;
|
2009-05-21 06:39:57 +08:00
|
|
|
struct CGRect {
|
|
|
|
};
|
|
|
|
typedef struct CGRect CGRect;
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef mach_port_t io_object_t;
|
2009-06-17 04:44:39 +08:00
|
|
|
typedef char io_name_t[128];
|
|
|
|
typedef io_object_t io_iterator_t;
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef io_object_t io_service_t;
|
2009-06-17 04:44:39 +08:00
|
|
|
typedef struct IONotificationPort * IONotificationPortRef;
|
|
|
|
typedef void (*IOServiceMatchingCallback)( void * refcon, io_iterator_t iterator );
|
|
|
|
io_service_t IOServiceGetMatchingService( mach_port_t masterPort, CFDictionaryRef matching );
|
|
|
|
kern_return_t IOServiceGetMatchingServices( mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t * existing );
|
2013-12-19 07:30:06 +08:00
|
|
|
kern_return_t IOServiceAddNotification( mach_port_t masterPort, const io_name_t notificationType, CFDictionaryRef matching, mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) __attribute__((deprecated)); // expected-note {{'IOServiceAddNotification' has been explicitly marked deprecated here}}
|
2009-06-17 04:44:39 +08:00
|
|
|
kern_return_t IOServiceAddMatchingNotification( IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification );
|
|
|
|
CFMutableDictionaryRef IOServiceMatching( const char * name );
|
|
|
|
CFMutableDictionaryRef IOServiceNameMatching( const char * name );
|
|
|
|
CFMutableDictionaryRef IOBSDNameMatching( mach_port_t masterPort, uint32_t options, const char * bsdName );
|
|
|
|
CFMutableDictionaryRef IOOpenFirmwarePathMatching( mach_port_t masterPort, uint32_t options, const char * path );
|
|
|
|
CFMutableDictionaryRef IORegistryEntryIDMatching( uint64_t entryID );
|
2009-01-13 05:45:02 +08:00
|
|
|
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 );
|
2009-08-20 08:57:22 +08:00
|
|
|
@interface NSTask : NSObject - (id)init;
|
|
|
|
@end typedef struct CGColorSpace *CGColorSpaceRef;
|
2009-05-21 06:39:57 +08:00
|
|
|
typedef struct CGImage *CGImageRef;
|
2009-08-20 08:57:22 +08:00
|
|
|
typedef struct CGLayer *CGLayerRef;
|
2009-03-10 06:28:18 +08:00
|
|
|
@interface NSResponder : NSObject <NSCoding> {
|
2009-04-29 08:41:31 +08:00
|
|
|
}
|
|
|
|
@end @protocol NSAnimatablePropertyContainer - (id)animator;
|
|
|
|
@end extern NSString *NSAnimationTriggerOrderIn ;
|
|
|
|
@interface NSView : NSResponder <NSAnimatablePropertyContainer> {
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
@end @protocol NSValidatedUserInterfaceItem - (SEL)action;
|
2009-04-29 08:41:31 +08:00
|
|
|
@end @protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end @class NSDate, NSDictionary, NSError, NSException, NSNotification;
|
2012-05-10 01:23:11 +08:00
|
|
|
@class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError;
|
2009-04-29 08:41:31 +08:00
|
|
|
@interface NSApplication : NSResponder <NSUserInterfaceValidations> {
|
2009-03-10 06:28:18 +08:00
|
|
|
}
|
2012-05-10 01:23:11 +08:00
|
|
|
- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo;
|
2009-04-29 08:41:31 +08:00
|
|
|
@end enum {
|
|
|
|
NSTerminateCancel = 0, NSTerminateNow = 1, NSTerminateLater = 2 };
|
|
|
|
typedef NSUInteger NSApplicationTerminateReply;
|
|
|
|
@protocol NSApplicationDelegate <NSObject> @optional - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView, NSTextView;
|
|
|
|
@interface NSCell : NSObject <NSCopying, NSCoding> {
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
2012-05-10 01:23:11 +08:00
|
|
|
@end
|
2009-08-20 08:57:22 +08:00
|
|
|
typedef struct {
|
|
|
|
}
|
|
|
|
CVTimeStamp;
|
2009-05-21 06:39:57 +08:00
|
|
|
@interface CIImage : NSObject <NSCoding, NSCopying> {
|
|
|
|
}
|
|
|
|
typedef int CIFormat;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end enum {
|
2011-02-24 07:34:11 +08:00
|
|
|
kDAReturnSuccess = 0, kDAReturnError = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x01, kDAReturnBusy = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x02, kDAReturnBadArgument = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x03, kDAReturnExclusiveAccess = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x04, kDAReturnNoResources = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x05, kDAReturnNotFound = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x06, kDAReturnNotMounted = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x07, kDAReturnNotPermitted = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x08, kDAReturnNotPrivileged = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x09, kDAReturnNotReady = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0A, kDAReturnNotWritable = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0B, kDAReturnUnsupported = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0C };
|
2009-01-13 05:45:02 +08:00
|
|
|
typedef mach_error_t DAReturn;
|
|
|
|
typedef const struct __DADissenter * DADissenterRef;
|
|
|
|
extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
|
2009-05-21 06:39:57 +08:00
|
|
|
@interface CIContext: NSObject {
|
|
|
|
}
|
|
|
|
- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r;
|
|
|
|
- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs;
|
2009-06-17 04:44:39 +08:00
|
|
|
- (CGLayerRef)createCGLayerWithSize:(CGSize)size info:(CFDictionaryRef)d;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end extern NSString* const QCRendererEventKey;
|
2009-06-17 04:44:39 +08:00
|
|
|
@protocol QCCompositionRenderer - (NSDictionary*) attributes;
|
|
|
|
@end @interface QCRenderer : NSObject <QCCompositionRenderer> {
|
2009-05-21 06:39:57 +08:00
|
|
|
}
|
|
|
|
- (id) createSnapshotImageOfType:(NSString*)type;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end extern NSString* const QCViewDidStartRenderingNotification;
|
|
|
|
@interface QCView : NSView <QCCompositionRenderer> {
|
2009-05-21 06:39:57 +08:00
|
|
|
}
|
|
|
|
- (id) createSnapshotImageOfType:(NSString*)type;
|
2009-06-17 04:44:39 +08:00
|
|
|
@end enum {
|
|
|
|
ICEXIFOrientation1 = 1, ICEXIFOrientation2 = 2, ICEXIFOrientation3 = 3, ICEXIFOrientation4 = 4, ICEXIFOrientation5 = 5, ICEXIFOrientation6 = 6, ICEXIFOrientation7 = 7, ICEXIFOrientation8 = 8, };
|
|
|
|
@class ICDevice;
|
|
|
|
@protocol ICDeviceDelegate <NSObject> @required - (void)didRemoveDevice:(ICDevice*)device;
|
2009-08-20 08:57:22 +08:00
|
|
|
@end extern NSString *const ICScannerStatusWarmingUp;
|
2009-06-17 04:44:39 +08:00
|
|
|
@class ICScannerDevice;
|
|
|
|
@protocol ICScannerDeviceDelegate <ICDeviceDelegate> @optional - (void)scannerDeviceDidBecomeAvailable:(ICScannerDevice*)scanner;
|
2009-05-15 05:29:16 +08:00
|
|
|
@end
|
2009-08-20 08:57:22 +08:00
|
|
|
|
2009-09-02 02:33:16 +08:00
|
|
|
typedef long unsigned int __darwin_size_t;
|
|
|
|
typedef __darwin_size_t size_t;
|
|
|
|
typedef unsigned long CFTypeID;
|
|
|
|
struct CGPoint {
|
|
|
|
CGFloat x;
|
|
|
|
CGFloat y;
|
|
|
|
};
|
|
|
|
typedef struct CGPoint CGPoint;
|
|
|
|
typedef struct CGGradient *CGGradientRef;
|
|
|
|
typedef uint32_t CGGradientDrawingOptions;
|
|
|
|
extern CFTypeID CGGradientGetTypeID(void);
|
|
|
|
extern CGGradientRef CGGradientCreateWithColorComponents(CGColorSpaceRef
|
|
|
|
space, const CGFloat components[], const CGFloat locations[], size_t count);
|
|
|
|
extern CGGradientRef CGGradientCreateWithColors(CGColorSpaceRef space,
|
|
|
|
CFArrayRef colors, const CGFloat locations[]);
|
|
|
|
extern CGGradientRef CGGradientRetain(CGGradientRef gradient);
|
|
|
|
extern void CGGradientRelease(CGGradientRef gradient);
|
|
|
|
typedef struct CGContext *CGContextRef;
|
|
|
|
extern void CGContextDrawLinearGradient(CGContextRef context,
|
|
|
|
CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,
|
|
|
|
CGGradientDrawingOptions options);
|
|
|
|
extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void);
|
|
|
|
|
2011-10-06 07:54:29 +08:00
|
|
|
@interface NSMutableArray : NSObject
|
|
|
|
- (void)addObject:(id)object;
|
|
|
|
+ (id)array;
|
|
|
|
@end
|
|
|
|
|
2018-08-18 05:42:59 +08:00
|
|
|
// This is how NSMakeCollectable is declared in the OS X 10.8 headers.
|
|
|
|
id NSMakeCollectable(CFTypeRef __attribute__((cf_consumed))) __attribute__((ns_returns_retained));
|
|
|
|
|
2012-09-07 07:47:02 +08:00
|
|
|
typedef const struct __CFUUID * CFUUIDRef;
|
|
|
|
|
|
|
|
extern
|
|
|
|
void *CFPlugInInstanceCreate(CFAllocatorRef allocator, CFUUIDRef factoryUUID, CFUUIDRef typeUUID);
|
2017-07-26 01:17:09 +08:00
|
|
|
typedef struct {
|
|
|
|
int ref;
|
|
|
|
} isl_basic_map;
|
2011-10-06 07:54:29 +08:00
|
|
|
|
2009-01-13 05:45:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test cases.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CFAbsoluteTime f1() {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
|
|
|
CFDateRef date = CFDateCreate(0, t);
|
|
|
|
CFRetain(date);
|
|
|
|
CFRelease(date);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateGetAbsoluteTime(date); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
CFRelease(date);
|
2012-09-07 15:40:40 +08:00
|
|
|
t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released}}
|
2009-01-13 05:45:02 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFAbsoluteTime f2() {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
|
|
|
CFDateRef date = CFDateCreate(0, t);
|
|
|
|
[((NSDate*) date) retain];
|
|
|
|
CFRelease(date);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateGetAbsoluteTime(date); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
[((NSDate*) date) release];
|
2012-09-07 15:40:40 +08:00
|
|
|
t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released}}
|
2009-01-13 05:45:02 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSDate* global_x;
|
|
|
|
|
2013-12-06 00:25:25 +08:00
|
|
|
// Test to see if we suppress an error when we store the pointer
|
2009-01-13 05:45:02 +08:00
|
|
|
// to a global.
|
|
|
|
|
|
|
|
CFAbsoluteTime f3() {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
|
|
|
CFDateRef date = CFDateCreate(0, t);
|
|
|
|
[((NSDate*) date) retain];
|
|
|
|
CFRelease(date);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateGetAbsoluteTime(date); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
global_x = (NSDate*) date;
|
|
|
|
[((NSDate*) date) release];
|
2012-09-07 15:40:40 +08:00
|
|
|
t = CFDateGetAbsoluteTime(date); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-01-21 14:57:53 +08:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Test case 'f4' differs for region store and basic store. See
|
|
|
|
// retain-release-region-store.m and retain-release-basic-store.m.
|
|
|
|
//---------------------------------------------------------------------------
|
2009-01-13 05:45:02 +08:00
|
|
|
|
|
|
|
// Test a leak.
|
|
|
|
|
|
|
|
CFAbsoluteTime f5(int x) {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateRef date = CFDateCreate(0, t); // expected-warning{{leak}}
|
2009-01-13 05:45:02 +08:00
|
|
|
|
|
|
|
if (x)
|
|
|
|
CFRelease(date);
|
|
|
|
|
2009-02-05 07:49:09 +08:00
|
|
|
return t;
|
2009-01-13 05:45:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a leak involving the return.
|
|
|
|
|
|
|
|
CFDateRef f6(int x) {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // expected-warning{{leak}}
|
2009-01-13 05:45:02 +08:00
|
|
|
CFRetain(date);
|
2009-02-05 07:49:09 +08:00
|
|
|
return date;
|
2009-01-13 05:45:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a leak involving an overwrite.
|
|
|
|
|
|
|
|
CFDateRef f7() {
|
2009-02-05 07:49:09 +08:00
|
|
|
CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); //expected-warning{{leak}}
|
2009-01-24 08:55:43 +08:00
|
|
|
CFRetain(date);
|
2012-09-07 15:40:40 +08:00
|
|
|
date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // expected-warning {{leak}}
|
2009-01-13 05:45:02 +08:00
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generalization of Create rule. MyDateCreate returns a CFXXXTypeRef, and
|
|
|
|
// has the word create.
|
|
|
|
CFDateRef MyDateCreate();
|
|
|
|
|
|
|
|
CFDateRef f8() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateRef date = MyDateCreate(); // expected-warning{{leak}}
|
2009-01-13 05:45:02 +08:00
|
|
|
CFRetain(date);
|
2009-02-05 07:49:09 +08:00
|
|
|
return date;
|
2009-01-13 05:45:02 +08:00
|
|
|
}
|
|
|
|
|
2011-05-25 14:19:45 +08:00
|
|
|
__attribute__((cf_returns_retained)) CFDateRef f9() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
int *p = 0;
|
2009-03-10 06:46:49 +08:00
|
|
|
// When allocations fail, CFDateCreate can return null.
|
2012-09-07 15:40:40 +08:00
|
|
|
if (!date) *p = 1; // expected-warning{{null}}
|
2009-01-13 05:45:02 +08:00
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle DiskArbitration API:
|
|
|
|
//
|
|
|
|
// http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/DiscArbitrationFramework/
|
|
|
|
//
|
|
|
|
void f10(io_service_t media, DADiskRef d, CFStringRef s) {
|
2012-09-07 15:40:40 +08:00
|
|
|
DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, 0, "hello"); // expected-warning{{leak}}
|
2009-02-05 07:49:09 +08:00
|
|
|
if (disk) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media); // expected-warning{{leak}}
|
2009-02-05 07:49:09 +08:00
|
|
|
if (disk) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDictionaryRef dict = DADiskCopyDescription(d); // expected-warning{{leak}}
|
2009-02-05 07:49:09 +08:00
|
|
|
if (dict) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
disk = DADiskCopyWholeDisk(d); // expected-warning{{leak}}
|
2009-02-05 07:49:09 +08:00
|
|
|
if (disk) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, // expected-warning{{leak}}
|
2009-01-13 05:45:02 +08:00
|
|
|
kDAReturnSuccess, s);
|
2009-02-05 07:49:09 +08:00
|
|
|
if (dissenter) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
DASessionRef session = DASessionCreate(kCFAllocatorDefault); // expected-warning{{leak}}
|
2009-02-05 07:49:09 +08:00
|
|
|
if (session) NSLog(@"ok");
|
2009-01-13 05:45:02 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 22:57:42 +08:00
|
|
|
|
|
|
|
// Handle CoreMedia API
|
|
|
|
|
|
|
|
struct CMFoo;
|
|
|
|
typedef struct CMFoo *CMFooRef;
|
|
|
|
|
|
|
|
CMFooRef CMCreateFooRef();
|
|
|
|
CMFooRef CMGetFooRef();
|
|
|
|
|
|
|
|
typedef signed long SInt32;
|
|
|
|
typedef SInt32 OSStatus;
|
|
|
|
OSStatus CMCreateFooAndReturnViaOutParameter(CMFooRef * CF_RETURNS_RETAINED fooOut);
|
|
|
|
|
|
|
|
void testLeakCoreMediaReferenceType() {
|
|
|
|
CMFooRef f = CMCreateFooRef(); // expected-warning{{leak}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testOverReleaseMediaReferenceType() {
|
|
|
|
CMFooRef f = CMGetFooRef();
|
|
|
|
CFRelease(f); // expected-warning{{Incorrect decrement of the reference count}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testOkToReleaseReturnsRetainedOutParameter() {
|
|
|
|
CMFooRef foo = 0;
|
|
|
|
OSStatus status = CMCreateFooAndReturnViaOutParameter(&foo);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CFRelease(foo); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void testLeakWithReturnsRetainedOutParameter() {
|
|
|
|
CMFooRef foo = 0;
|
|
|
|
OSStatus status = CMCreateFooAndReturnViaOutParameter(&foo);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME: Ideally we would report a leak here since it is the caller's
|
|
|
|
// responsibility to release 'foo'. However, we don't currently have
|
|
|
|
// a mechanism in this checker to only require a release when a successful
|
|
|
|
// status is returned.
|
|
|
|
}
|
|
|
|
|
2018-12-21 08:18:58 +08:00
|
|
|
typedef CFTypeRef CMBufferRef;
|
|
|
|
|
|
|
|
typedef CFTypeRef *CMBufferQueueRef;
|
|
|
|
|
|
|
|
CMBufferRef CMBufferQueueDequeueAndRetain(CMBufferQueueRef);
|
|
|
|
|
|
|
|
void testCMBufferQueueDequeueAndRetain(CMBufferQueueRef queue) {
|
|
|
|
CMBufferRef buffer = CMBufferQueueDequeueAndRetain(queue); // expected-warning{{Potential leak of an object stored into 'buffer'}}
|
|
|
|
// There's a state split due to the eagerly-assume behavior.
|
|
|
|
// The point here is that we don't treat CMBufferQueueDequeueAndRetain
|
|
|
|
// as some sort of CFRetain() that returns its argument.
|
|
|
|
clang_analyzer_eval((CMFooRef)buffer == (CMFooRef)queue); // expected-warning{{TRUE}}
|
|
|
|
// expected-warning@-1{{FALSE}}
|
|
|
|
}
|
|
|
|
|
2009-01-13 05:45:02 +08:00
|
|
|
// Test retain/release checker with CFString and CFMutableArray.
|
|
|
|
void f11() {
|
|
|
|
// Create the array.
|
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
|
|
|
|
// Create a string.
|
|
|
|
CFStringRef s1 = CFStringCreateWithCString(0, "hello world",
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
// Add the string to the array.
|
|
|
|
CFArrayAppendValue(A, s1);
|
|
|
|
|
|
|
|
// Decrement the reference count.
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(s1); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
|
|
|
|
// Get the string. We don't own it.
|
|
|
|
s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
|
|
|
|
|
|
|
|
// Release the array.
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(A); // no-warning
|
2009-01-13 05:45:02 +08:00
|
|
|
|
|
|
|
// Release the string. This is a bug.
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}}
|
2009-01-13 05:45:02 +08:00
|
|
|
}
|
|
|
|
|
2009-01-17 02:40:33 +08:00
|
|
|
// PR 3337: Handle functions declared using typedefs.
|
|
|
|
typedef CFTypeRef CREATEFUN();
|
|
|
|
CREATEFUN MyCreateFun;
|
|
|
|
|
|
|
|
void f12() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFTypeRef o = MyCreateFun(); // expected-warning {{leak}}
|
2009-01-17 02:40:33 +08:00
|
|
|
}
|
2009-01-29 05:20:48 +08:00
|
|
|
|
|
|
|
void f13_autorelease() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
|
|
|
[(id) A autorelease]; // no-warning
|
2009-01-29 05:20:48 +08:00
|
|
|
}
|
2009-02-20 02:20:28 +08:00
|
|
|
|
2009-05-09 09:50:57 +08:00
|
|
|
void f13_autorelease_b() {
|
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
[(id) A autorelease];
|
2012-11-16 03:11:43 +08:00
|
|
|
[(id) A autorelease];
|
2013-04-23 09:42:25 +08:00
|
|
|
} // expected-warning{{Object autoreleased too many times}}
|
2009-05-09 09:50:57 +08:00
|
|
|
|
|
|
|
CFMutableArrayRef f13_autorelease_c() {
|
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
[(id) A autorelease];
|
|
|
|
[(id) A autorelease];
|
2013-04-23 09:42:25 +08:00
|
|
|
return A; // expected-warning{{Object autoreleased too many times}}
|
2009-05-09 09:50:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFMutableArrayRef f13_autorelease_d() {
|
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
[(id) A autorelease];
|
|
|
|
[(id) A autorelease];
|
2013-04-23 09:42:25 +08:00
|
|
|
CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Object autoreleased too many times}}
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(B); // no-warning
|
2009-07-22 02:58:15 +08:00
|
|
|
while (1) {}
|
2009-05-09 09:50:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 02:20:28 +08:00
|
|
|
// This case exercises the logic where the leak site is the same as the allocation site.
|
|
|
|
void f14_leakimmediately() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}}
|
2009-02-20 02:20:28 +08:00
|
|
|
}
|
2009-03-06 02:15:02 +08:00
|
|
|
|
2009-04-07 13:33:18 +08:00
|
|
|
// Test that we track an allocated object beyond the point where the *name*
|
|
|
|
// of the variable storing the reference is no longer live.
|
|
|
|
void f15() {
|
|
|
|
// Create the array.
|
|
|
|
CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
CFMutableArrayRef *B = &A;
|
|
|
|
// At this point, the name 'A' is no longer live.
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(*B); // no-warning
|
2009-04-07 13:33:18 +08:00
|
|
|
}
|
|
|
|
|
2014-06-22 07:50:40 +08:00
|
|
|
// Test when we pass NULL to CFRetain/CFRelease/CFMakeCollectable/CFAutorelease.
|
2009-07-14 08:43:42 +08:00
|
|
|
void f16(int x, CFTypeRef p) {
|
|
|
|
if (p)
|
|
|
|
return;
|
|
|
|
|
2014-06-22 07:50:40 +08:00
|
|
|
switch (x) {
|
|
|
|
case 0:
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(p); // expected-warning{{Null pointer argument in call to CFRelease}}
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRetain(p); // expected-warning{{Null pointer argument in call to CFRetain}}
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-08 01:12:37 +08:00
|
|
|
CFMakeCollectable(p); // expected-warning{{Null pointer argument in call to CFMakeCollectable}}
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
CFAutorelease(p); // expected-warning{{Null pointer argument in call to CFAutorelease}}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-11-08 01:12:37 +08:00
|
|
|
}
|
2009-07-14 08:43:42 +08:00
|
|
|
}
|
2009-04-07 13:33:18 +08:00
|
|
|
|
2019-01-30 10:11:04 +08:00
|
|
|
#ifdef TRACK_START_PARAM
|
|
|
|
@interface TestParam : NSObject
|
|
|
|
- (void) f:(id) object;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestParam
|
|
|
|
- (void) f:(id) object { // expected-warning{{Potential leak of an object of type 'id'}}
|
|
|
|
[object retain];
|
|
|
|
[object retain];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|
|
|
|
|
2014-06-22 07:50:40 +08:00
|
|
|
// Test that an object is non-null after CFRetain/CFRelease/CFMakeCollectable/CFAutorelease.
|
2010-07-06 10:34:42 +08:00
|
|
|
void f17(int x, CFTypeRef p) {
|
2019-01-30 03:29:59 +08:00
|
|
|
#ifdef TRACK_START_PARAM
|
|
|
|
// expected-warning@-2{{Potential leak of an object of type 'CFTypeRef'}}
|
|
|
|
#endif
|
2014-06-22 07:50:40 +08:00
|
|
|
switch (x) {
|
|
|
|
case 0:
|
2010-07-06 10:42:09 +08:00
|
|
|
CFRelease(p);
|
2019-01-30 03:29:59 +08:00
|
|
|
#ifdef TRACK_START_PARAM
|
|
|
|
// expected-warning@-2{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
|
|
|
#endif
|
2010-07-06 10:42:09 +08:00
|
|
|
if (!p)
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(0); // no-warning
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-07-06 10:42:09 +08:00
|
|
|
CFRetain(p);
|
|
|
|
if (!p)
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRetain(0); // no-warning
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-08 01:12:37 +08:00
|
|
|
CFMakeCollectable(p);
|
|
|
|
if (!p)
|
|
|
|
CFMakeCollectable(0); // no-warning
|
2014-06-22 07:50:40 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
CFAutorelease(p);
|
|
|
|
if (!p)
|
|
|
|
CFAutorelease(0); // no-warning
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-11-08 01:12:37 +08:00
|
|
|
}
|
2010-07-06 10:34:42 +08:00
|
|
|
}
|
2019-01-30 03:29:59 +08:00
|
|
|
#ifdef TRACK_START_PARAM
|
|
|
|
// expected-warning@-2{{Object autoreleased too many times}}
|
|
|
|
#endif
|
2010-07-06 10:34:42 +08:00
|
|
|
|
2017-07-26 01:17:09 +08:00
|
|
|
__attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_cow(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap);
|
|
|
|
|
|
|
|
// Test custom diagnostics for generalized objects.
|
|
|
|
void f18(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
|
|
|
|
// After this call, 'bmap' has a +1 reference count.
|
|
|
|
bmap = isl_basic_map_cow(bmap); // expected-warning {{Potential leak of an object}}
|
|
|
|
}
|
|
|
|
|
2009-03-06 02:15:02 +08:00
|
|
|
// Test basic tracking of ivars associated with 'self'. For the retain/release
|
|
|
|
// checker we currently do not want to flag leaks associated with stores
|
|
|
|
// of tracked objects to ivars.
|
|
|
|
@interface SelfIvarTest : NSObject {
|
|
|
|
id myObj;
|
|
|
|
}
|
|
|
|
- (void)test_self_tracking;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SelfIvarTest
|
|
|
|
- (void)test_self_tracking {
|
2012-09-07 15:40:40 +08:00
|
|
|
myObj = (id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2009-03-06 02:15:02 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-05-10 14:25:57 +08:00
|
|
|
// Test return of non-owned objects in contexts where an owned object
|
|
|
|
// is expected.
|
|
|
|
@interface TestReturnNotOwnedWhenExpectedOwned
|
|
|
|
- (NSString*)newString;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestReturnNotOwnedWhenExpectedOwned
|
|
|
|
- (NSString*)newString {
|
|
|
|
NSString *s = [NSString stringWithUTF8String:"hello"];
|
2012-09-07 15:40:40 +08:00
|
|
|
return s; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}
|
2009-05-10 14:25:57 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-03-10 06:28:18 +08:00
|
|
|
// <rdar://problem/6659160>
|
|
|
|
int isFoo(char c);
|
|
|
|
|
|
|
|
static void rdar_6659160(char *inkind, char *inname)
|
|
|
|
{
|
|
|
|
// We currently expect that [NSObject alloc] cannot fail. This
|
|
|
|
// will be a toggled flag in the future. It can indeed return null, but
|
|
|
|
// Cocoa programmers generally aren't expected to reason about out-of-memory
|
|
|
|
// conditions.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *kind = [[NSString alloc] initWithUTF8String:inkind]; // expected-warning{{leak}}
|
2009-03-10 06:28:18 +08:00
|
|
|
|
|
|
|
// We do allow stringWithUTF8String to fail. This isn't really correct, as
|
2009-03-24 01:10:25 +08:00
|
|
|
// far as returning 0. In most error conditions it will throw an exception.
|
|
|
|
// If allocation fails it could return 0, but again this
|
2009-03-10 06:28:18 +08:00
|
|
|
// isn't expected.
|
|
|
|
NSString *name = [NSString stringWithUTF8String:inname];
|
|
|
|
if(!name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *kindC = 0;
|
|
|
|
const char *nameC = 0;
|
|
|
|
|
|
|
|
// In both cases, we cannot reach a point down below where we
|
|
|
|
// dereference kindC or nameC with either being null. This is because
|
|
|
|
// we assume that [NSObject alloc] doesn't fail and that we have the guard
|
|
|
|
// up above.
|
|
|
|
|
|
|
|
if(kind)
|
|
|
|
kindC = [kind UTF8String];
|
|
|
|
if(name)
|
|
|
|
nameC = [name UTF8String];
|
2012-09-07 15:40:40 +08:00
|
|
|
if(!isFoo(kindC[0])) // expected-warning{{null}}
|
2009-03-10 06:28:18 +08:00
|
|
|
return;
|
2012-09-07 15:40:40 +08:00
|
|
|
if(!isFoo(nameC[0])) // no-warning
|
2009-03-10 06:28:18 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
[kind release];
|
2012-09-07 15:40:40 +08:00
|
|
|
[name release]; // expected-warning{{Incorrect decrement of the reference count}}
|
2009-03-10 06:28:18 +08:00
|
|
|
}
|
2009-03-06 02:15:02 +08:00
|
|
|
|
2009-03-14 04:27:06 +08:00
|
|
|
// PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming
|
|
|
|
// conventions with respect to 'return'ing ownership.
|
|
|
|
@interface PR3677: NSObject @end
|
|
|
|
@implementation PR3677
|
|
|
|
+ (id)allocWithZone:(NSZone *)inZone {
|
2012-09-07 15:40:40 +08:00
|
|
|
return [super allocWithZone:inZone]; // no-warning
|
2009-03-14 04:27:06 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-03-20 03:50:58 +08:00
|
|
|
// PR 3820 - Reason about calls to -dealloc
|
|
|
|
void pr3820_DeallocInsteadOfRelease(void)
|
|
|
|
{
|
2012-09-07 15:40:40 +08:00
|
|
|
id foo = [[NSString alloc] init]; // no-warning
|
2009-03-20 03:50:58 +08:00
|
|
|
[foo dealloc];
|
|
|
|
// foo is not leaked, since it has been deallocated.
|
|
|
|
}
|
|
|
|
|
|
|
|
void pr3820_ReleaseAfterDealloc(void)
|
|
|
|
{
|
|
|
|
id foo = [[NSString alloc] init];
|
|
|
|
[foo dealloc];
|
2012-09-07 15:40:40 +08:00
|
|
|
[foo release]; // expected-warning{{used after it is release}}
|
2009-03-20 03:50:58 +08:00
|
|
|
// NSInternalInconsistencyException: message sent to deallocated object
|
|
|
|
}
|
|
|
|
|
|
|
|
void pr3820_DeallocAfterRelease(void)
|
|
|
|
{
|
|
|
|
NSLog(@"\n\n[%s]", __FUNCTION__);
|
|
|
|
id foo = [[NSString alloc] init];
|
|
|
|
[foo release];
|
2012-09-07 15:40:40 +08:00
|
|
|
[foo dealloc]; // expected-warning{{used after it is released}}
|
2009-03-20 03:50:58 +08:00
|
|
|
// message sent to released object
|
|
|
|
}
|
2009-03-24 01:10:25 +08:00
|
|
|
|
|
|
|
// From <rdar://problem/6704930>. The problem here is that 'length' binds to
|
|
|
|
// '($0 - 1)' after '--length', but SimpleConstraintManager doesn't know how to
|
|
|
|
// reason about '($0 - 1) > constant'. As a temporary hack, we drop the value
|
|
|
|
// of '($0 - 1)' and conjure a new symbol.
|
|
|
|
void rdar6704930(unsigned char *s, unsigned int length) {
|
|
|
|
NSString* name = 0;
|
|
|
|
if (s != 0) {
|
|
|
|
if (length > 0) {
|
|
|
|
while (length > 0) {
|
|
|
|
if (*s == ':') {
|
|
|
|
++s;
|
|
|
|
--length;
|
2012-09-07 15:40:40 +08:00
|
|
|
name = [[NSString alloc] init]; // no-warning
|
2009-03-24 01:10:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++s;
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
if ((length == 0) && (name != 0)) {
|
|
|
|
[name release];
|
|
|
|
name = 0;
|
|
|
|
}
|
|
|
|
if (length == 0) { // no ':' found -> use it all as name
|
2012-09-07 15:40:40 +08:00
|
|
|
name = [[NSString alloc] init]; // no-warning
|
2009-03-24 01:10:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != 0) {
|
|
|
|
[name release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-29 08:41:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6833332>
|
|
|
|
// One build of the analyzer accidentally stopped tracking the allocated
|
|
|
|
// object after the 'retain'.
|
2009-05-12 02:30:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-04-29 08:41:31 +08:00
|
|
|
|
|
|
|
@interface rdar_6833332 : NSObject <NSApplicationDelegate> {
|
|
|
|
NSWindow *window;
|
|
|
|
}
|
|
|
|
@property (nonatomic, retain) NSWindow *window;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation rdar_6833332
|
|
|
|
@synthesize window;
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; // expected-warning{{leak}}
|
2009-04-29 08:41:31 +08:00
|
|
|
|
|
|
|
[dict setObject:@"foo" forKey:@"bar"];
|
|
|
|
|
|
|
|
NSLog(@"%@", dict);
|
|
|
|
}
|
|
|
|
- (void)dealloc {
|
|
|
|
[window release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2011-09-21 08:35:58 +08:00
|
|
|
|
|
|
|
- (void)radar10102244 {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; // expected-warning{{leak}}
|
2011-09-21 08:35:58 +08:00
|
|
|
if (window)
|
|
|
|
NSLog(@"%@", window);
|
|
|
|
}
|
2009-04-29 08:41:31 +08:00
|
|
|
@end
|
|
|
|
|
2009-05-12 01:45:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6257780> clang checker fails to catch use-after-release
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-02-19 05:37:48 +08:00
|
|
|
|
2009-05-12 02:30:24 +08:00
|
|
|
int rdar_6257780_Case1() {
|
2009-05-12 01:45:06 +08:00
|
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSArray *array = [NSArray array];
|
2012-09-07 15:40:40 +08:00
|
|
|
[array release]; // expected-warning{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
2009-05-12 01:45:06 +08:00
|
|
|
[pool drain];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-19 05:37:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/10640253> Analyzer is confused about NSAutoreleasePool -allocWithZone:.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar_10640253_autorelease_allocWithZone() {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:(NSZone*)0] init];
|
|
|
|
(void) pool;
|
|
|
|
}
|
|
|
|
|
2009-05-12 02:30:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6866843> Checker should understand new/setObject:/release constructs
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar_6866843() {
|
|
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
|
|
|
|
NSArray* array = [[NSArray alloc] init];
|
|
|
|
[dictionary setObject:array forKey:@"key"];
|
|
|
|
[array release];
|
|
|
|
// Using 'array' here should be fine
|
2012-09-07 15:40:40 +08:00
|
|
|
NSLog(@"array = %@\n", array); // no-warning
|
2009-05-12 02:30:24 +08:00
|
|
|
// Now the array is released
|
|
|
|
[dictionary release];
|
|
|
|
[pool drain];
|
|
|
|
}
|
|
|
|
|
2009-05-12 12:53:03 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same treatment as CF objects
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef CFTypeRef OtherRef;
|
|
|
|
|
|
|
|
@interface RDar6877235 : NSObject {}
|
|
|
|
- (CFTypeRef)_copyCFTypeRef;
|
|
|
|
- (OtherRef)_copyOtherRef;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar6877235
|
|
|
|
- (CFTypeRef)_copyCFTypeRef {
|
2012-09-07 15:40:40 +08:00
|
|
|
return [[NSString alloc] init]; // no-warning
|
2009-05-12 12:53:03 +08:00
|
|
|
}
|
|
|
|
- (OtherRef)_copyOtherRef {
|
2012-09-07 15:40:40 +08:00
|
|
|
return [[NSString alloc] init]; // no-warning
|
2009-05-12 12:53:03 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-05-13 04:06:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-06-23 00:02:55 +08:00
|
|
|
// <rdar://problem/6320065> false positive - init method returns an object
|
2009-08-20 13:13:36 +08:00
|
|
|
// owned by caller
|
2009-05-13 04:06:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar6320065 : NSObject {
|
|
|
|
NSString *_foo;
|
|
|
|
}
|
|
|
|
- (id)initReturningNewClass;
|
2011-01-12 03:45:25 +08:00
|
|
|
- (id)_initReturningNewClassBad;
|
2009-05-13 04:06:54 +08:00
|
|
|
- (id)initReturningNewClassBad2;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface RDar6320065Subclass : RDar6320065
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar6320065
|
|
|
|
- (id)initReturningNewClass {
|
|
|
|
[self release];
|
2012-09-07 15:40:40 +08:00
|
|
|
self = [[RDar6320065Subclass alloc] init]; // no-warning
|
2009-05-13 04:06:54 +08:00
|
|
|
return self;
|
|
|
|
}
|
2011-01-12 03:45:25 +08:00
|
|
|
- (id)_initReturningNewClassBad {
|
2009-05-13 04:06:54 +08:00
|
|
|
[self release];
|
2012-09-07 15:40:40 +08:00
|
|
|
[[RDar6320065Subclass alloc] init]; // expected-warning {{leak}}
|
2009-05-13 04:06:54 +08:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (id)initReturningNewClassBad2 {
|
|
|
|
[self release];
|
|
|
|
self = [[RDar6320065Subclass alloc] init];
|
2012-09-07 15:40:40 +08:00
|
|
|
return [self autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}
|
2009-05-13 04:06:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar6320065Subclass
|
|
|
|
@end
|
|
|
|
|
|
|
|
int RDar6320065_test() {
|
2012-09-07 15:40:40 +08:00
|
|
|
RDar6320065 *test = [[RDar6320065 alloc] init]; // no-warning
|
2009-05-13 04:06:54 +08:00
|
|
|
[test release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-15 05:29:16 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-08-20 13:13:36 +08:00
|
|
|
// <rdar://problem/7129086> -awakeAfterUsingCoder: returns an owned object
|
|
|
|
// and claims the receiver
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar7129086 : NSObject {} @end
|
|
|
|
@implementation RDar7129086
|
|
|
|
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder {
|
2012-09-07 15:40:40 +08:00
|
|
|
[self release]; // no-warning
|
|
|
|
return [NSString alloc]; // no-warning
|
2009-08-20 13:13:36 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a
|
|
|
|
// retained object
|
2009-05-15 05:29:16 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar6859457 : NSObject {}
|
|
|
|
- (NSString*) NoCopyString;
|
|
|
|
- (NSString*) noCopyString;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar6859457
|
2012-09-07 15:40:40 +08:00
|
|
|
- (NSString*) NoCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}}
|
|
|
|
- (NSString*) noCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}}
|
2009-05-15 05:29:16 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) {
|
2012-09-07 15:40:40 +08:00
|
|
|
[x NoCopyString]; // expected-warning{{leak}}
|
|
|
|
[x noCopyString]; // expected-warning{{leak}}
|
|
|
|
[NSData dataWithBytesNoCopy:bytes length:dataLength]; // no-warning
|
|
|
|
[NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; // no-warning
|
2009-05-15 05:29:16 +08:00
|
|
|
}
|
|
|
|
|
2009-05-19 07:14:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PR 4230 - an autorelease pool is not necessarily leaked during a premature
|
|
|
|
// return
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static void PR4230(void)
|
|
|
|
{
|
2012-09-07 15:40:40 +08:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // no-warning
|
|
|
|
NSString *object = [[[NSString alloc] init] autorelease]; // no-warning
|
2009-05-19 07:14:34 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 06:06:02 +08:00
|
|
|
static void PR4230_new(void)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [NSAutoreleasePool new]; // no-warning
|
|
|
|
NSString *object = [[[NSString alloc] init] autorelease]; // no-warning
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-15 23:49:00 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Method name that has a null IdentifierInfo* for its first selector slot.
|
|
|
|
// This test just makes sure that we handle it.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface TestNullIdentifier
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestNullIdentifier
|
|
|
|
+ (id):(int)x, ... {
|
2012-09-07 15:40:40 +08:00
|
|
|
return [[NSString alloc] init]; // expected-warning{{leak}}
|
2009-05-15 23:49:00 +08:00
|
|
|
}
|
2009-05-21 06:39:57 +08:00
|
|
|
@end
|
2009-05-15 23:49:00 +08:00
|
|
|
|
2009-05-16 09:38:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6893565> don't flag leaks for return types that cannot be
|
|
|
|
// determined to be CF types
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// We don't know if 'struct s6893565' represents a Core Foundation type, so
|
|
|
|
// we shouldn't emit an error here.
|
|
|
|
typedef struct s6893565* TD6893565;
|
|
|
|
|
|
|
|
@interface RDar6893565 {}
|
|
|
|
-(TD6893565)newThing;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar6893565
|
|
|
|
-(TD6893565)newThing {
|
2012-09-07 15:40:40 +08:00
|
|
|
return (TD6893565) [[NSString alloc] init]; // no-warning
|
2009-05-16 09:38:01 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-05-21 06:39:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6902710> clang: false positives w/QC and CoreImage methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar6902710(QCView *view, QCRenderer *renderer, CIContext *context,
|
|
|
|
NSString *str, CIImage *img, CGRect rect,
|
|
|
|
CIFormat form, CGColorSpaceRef cs) {
|
2012-09-07 15:40:40 +08:00
|
|
|
[view createSnapshotImageOfType:str]; // expected-warning{{leak}}
|
|
|
|
[renderer createSnapshotImageOfType:str]; // expected-warning{{leak}}
|
|
|
|
[context createCGImage:img fromRect:rect]; // expected-warning{{leak}}
|
|
|
|
[context createCGImage:img fromRect:rect format:form colorSpace:cs]; // expected-warning{{leak}}
|
2009-05-21 06:39:57 +08:00
|
|
|
}
|
|
|
|
|
2009-06-17 04:44:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6945561> -[CIContext createCGLayerWithSize:info:]
|
|
|
|
// misinterpreted by clang scan-build
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar6945561(CIContext *context, CGSize size, CFDictionaryRef d) {
|
2012-09-07 15:40:40 +08:00
|
|
|
[context createCGLayerWithSize:size info:d]; // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/6961230> add knowledge of IOKit functions to retain/release
|
|
|
|
// checker
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void IOBSDNameMatching_wrapper(mach_port_t masterPort, uint32_t options, const char * bsdName) {
|
2012-09-07 15:40:40 +08:00
|
|
|
IOBSDNameMatching(masterPort, options, bsdName); // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOServiceMatching_wrapper(const char * name) {
|
2012-09-07 15:40:40 +08:00
|
|
|
IOServiceMatching(name); // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOServiceNameMatching_wrapper(const char * name) {
|
2012-09-07 15:40:40 +08:00
|
|
|
IOServiceNameMatching(name); // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
2009-07-17 08:19:33 +08:00
|
|
|
CF_RETURNS_RETAINED CFDictionaryRef CreateDict();
|
2009-06-17 04:44:39 +08:00
|
|
|
|
|
|
|
void IOServiceAddNotification_wrapper(mach_port_t masterPort, const io_name_t notificationType,
|
|
|
|
mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) {
|
|
|
|
|
|
|
|
CFDictionaryRef matching = CreateDict();
|
|
|
|
CFRelease(matching);
|
2012-09-07 15:40:40 +08:00
|
|
|
IOServiceAddNotification(masterPort, notificationType, matching, // expected-warning{{used after it is released}} expected-warning{{deprecated}}
|
2009-06-17 04:44:39 +08:00
|
|
|
wakePort, reference, notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IORegistryEntryIDMatching_wrapper(uint64_t entryID ) {
|
2012-09-07 15:40:40 +08:00
|
|
|
IORegistryEntryIDMatching(entryID); // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOOpenFirmwarePathMatching_wrapper(mach_port_t masterPort, uint32_t options,
|
|
|
|
const char * path) {
|
2012-09-07 15:40:40 +08:00
|
|
|
IOOpenFirmwarePathMatching(masterPort, options, path); // expected-warning{{leak}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOServiceGetMatchingService_wrapper(mach_port_t masterPort) {
|
|
|
|
CFDictionaryRef matching = CreateDict();
|
|
|
|
IOServiceGetMatchingService(masterPort, matching);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(matching); // expected-warning{{used after it is released}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOServiceGetMatchingServices_wrapper(mach_port_t masterPort, io_iterator_t *existing) {
|
|
|
|
CFDictionaryRef matching = CreateDict();
|
|
|
|
IOServiceGetMatchingServices(masterPort, matching, existing);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(matching); // expected-warning{{used after it is released}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOServiceAddMatchingNotification_wrapper(IONotificationPortRef notifyPort, const io_name_t notificationType,
|
|
|
|
IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification) {
|
|
|
|
|
|
|
|
CFDictionaryRef matching = CreateDict();
|
|
|
|
IOServiceAddMatchingNotification(notifyPort, notificationType, matching, callback, refCon, notification);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(matching); // expected-warning{{used after it is released}}
|
2009-06-17 04:44:39 +08:00
|
|
|
}
|
|
|
|
|
2009-08-20 08:57:22 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test of handling objects whose references "escape" to containers.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-04-30 07:15:53 +08:00
|
|
|
void CFDictionaryAddValue(CFMutableDictionaryRef, void *, void *);
|
2010-01-10 04:43:19 +08:00
|
|
|
|
2009-08-20 08:57:22 +08:00
|
|
|
// <rdar://problem/6539791>
|
|
|
|
void rdar_6539791(CFMutableDictionaryRef y, void* key, void* val_key) {
|
|
|
|
CFMutableDictionaryRef x = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
|
|
CFDictionaryAddValue(y, key, x);
|
|
|
|
CFRelease(x); // the dictionary keeps a reference, so the object isn't deallocated yet
|
|
|
|
signed z = 1;
|
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
|
|
|
|
if (value) {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDictionaryAddValue(x, val_key, (void*)value); // no-warning
|
2009-08-20 08:57:22 +08:00
|
|
|
CFRelease(value);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFDictionaryAddValue(y, val_key, (void*)value); // no-warning
|
2009-08-20 08:57:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <rdar://problem/6560661>
|
|
|
|
// Same issue, except with "AppendValue" functions.
|
|
|
|
void rdar_6560661(CFMutableArrayRef x) {
|
|
|
|
signed z = 1;
|
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
|
|
|
|
// CFArrayAppendValue keeps a reference to value.
|
|
|
|
CFArrayAppendValue(x, value);
|
|
|
|
CFRelease(value);
|
|
|
|
CFRetain(value);
|
2012-09-07 15:40:40 +08:00
|
|
|
CFRelease(value); // no-warning
|
2009-08-20 08:57:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// <rdar://problem/7152619>
|
|
|
|
// Same issue, excwept with "CFAttributeStringSetAttribute".
|
|
|
|
void rdar_7152619(CFStringRef str) {
|
|
|
|
CFAttributedStringRef string = CFAttributedStringCreate(kCFAllocatorDefault, str, 0);
|
|
|
|
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutableCopy(kCFAllocatorDefault, 100, string);
|
|
|
|
CFRelease(string);
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}}
|
2009-08-20 08:57:22 +08:00
|
|
|
CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 1), str, number);
|
|
|
|
[number release];
|
|
|
|
[number retain];
|
|
|
|
CFRelease(attrString);
|
|
|
|
}
|
|
|
|
|
2009-09-02 02:33:16 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test of handling CGGradientXXX functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar_7184450(CGContextRef myContext, CGFloat x, CGPoint myStartPoint,
|
|
|
|
CGPoint myEndPoint) {
|
|
|
|
size_t num_locations = 6;
|
|
|
|
CGFloat locations[6] = { 0.0, 0.265, 0.28, 0.31, 0.36, 1.0 };
|
|
|
|
CGFloat components[28] = { 239.0/256.0, 167.0/256.0, 170.0/256.0,
|
|
|
|
x, // Start color
|
|
|
|
207.0/255.0, 39.0/255.0, 39.0/255.0, x,
|
|
|
|
147.0/255.0, 21.0/255.0, 22.0/255.0, x,
|
|
|
|
175.0/255.0, 175.0/255.0, 175.0/255.0, x,
|
|
|
|
255.0/255.0,255.0/255.0, 255.0/255.0, x,
|
|
|
|
255.0/255.0,255.0/255.0, 255.0/255.0, x
|
|
|
|
}; // End color
|
|
|
|
|
|
|
|
CGGradientRef myGradient =
|
2012-09-07 15:40:40 +08:00
|
|
|
CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), // expected-warning{{leak}}
|
2009-09-02 02:33:16 +08:00
|
|
|
components, locations, num_locations);
|
|
|
|
|
|
|
|
CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint,
|
|
|
|
0);
|
|
|
|
CGGradientRelease(myGradient);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint,
|
|
|
|
CGPoint myEndPoint) {
|
|
|
|
size_t num_locations = 6;
|
|
|
|
CGFloat locations[6] = { 0.0, 0.265, 0.28, 0.31, 0.36, 1.0 };
|
|
|
|
CGFloat components[28] = { 239.0/256.0, 167.0/256.0, 170.0/256.0,
|
|
|
|
x, // Start color
|
|
|
|
207.0/255.0, 39.0/255.0, 39.0/255.0, x,
|
|
|
|
147.0/255.0, 21.0/255.0, 22.0/255.0, x,
|
|
|
|
175.0/255.0, 175.0/255.0, 175.0/255.0, x,
|
|
|
|
255.0/255.0,255.0/255.0, 255.0/255.0, x,
|
|
|
|
255.0/255.0,255.0/255.0, 255.0/255.0, x
|
|
|
|
}; // End color
|
|
|
|
|
|
|
|
CGGradientRef myGradient =
|
2012-09-07 15:40:40 +08:00
|
|
|
CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations); // expected-warning 2 {{leak}}
|
2009-09-02 02:33:16 +08:00
|
|
|
|
|
|
|
CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2009-05-09 11:10:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-14 06:55:33 +08:00
|
|
|
// <rdar://problem/7299394> clang false positive: retained instance passed to
|
|
|
|
// thread in pthread_create marked as leak
|
|
|
|
//
|
|
|
|
// Until we have full IPA, the analyzer should stop tracking the reference
|
|
|
|
// count of objects passed to pthread_create.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct _opaque_pthread_t {};
|
|
|
|
struct _opaque_pthread_attr_t {};
|
|
|
|
typedef struct _opaque_pthread_t *__darwin_pthread_t;
|
|
|
|
typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t;
|
|
|
|
typedef __darwin_pthread_t pthread_t;
|
|
|
|
typedef __darwin_pthread_attr_t pthread_attr_t;
|
2012-04-26 12:32:23 +08:00
|
|
|
typedef unsigned long __darwin_pthread_key_t;
|
|
|
|
typedef __darwin_pthread_key_t pthread_key_t;
|
2009-10-14 06:55:33 +08:00
|
|
|
|
Emit !callback metadata and introduce the callback attribute
With commit r351627, LLVM gained the ability to apply (existing) IPO
optimizations on indirections through callbacks, or transitive calls.
The general idea is that we use an abstraction to hide the middle man
and represent the callback call in the context of the initial caller.
It is described in more detail in the commit message of the LLVM patch
r351627, the llvm::AbstractCallSite class description, and the
language reference section on callback-metadata.
This commit enables clang to emit !callback metadata that is
understood by LLVM. It does so in three different cases:
1) For known broker functions declarations that are directly
generated, e.g., __kmpc_fork_call for the OpenMP pragma parallel.
2) For known broker functions that are identified by their name and
source location through the builtin detection, e.g.,
pthread_create from the POSIX thread API.
3) For user annotated functions that carry the "callback(callee, ...)"
attribute. The attribute has to include the name, or index, of
the callback callee and how the passed arguments can be
identified (as many as the callback callee has). See the callback
attribute documentation for detailed information.
Differential Revision: https://reviews.llvm.org/D55483
llvm-svn: 351629
2019-01-19 13:36:54 +08:00
|
|
|
int pthread_create(pthread_t *, const pthread_attr_t *, // C-warning{{declaration of built-in function 'pthread_create' requires inclusion of the header <pthread.h>}}
|
2011-04-30 07:15:53 +08:00
|
|
|
void *(*)(void *), void *);
|
2009-10-14 06:55:33 +08:00
|
|
|
|
2012-04-26 12:32:23 +08:00
|
|
|
int pthread_setspecific(pthread_key_t key, const void *value);
|
|
|
|
|
2009-10-14 06:55:33 +08:00
|
|
|
void *rdar_7299394_start_routine(void *p) {
|
|
|
|
[((id) p) release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
void rdar_7299394(pthread_attr_t *attr, pthread_t *thread, void *args) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-10-14 06:55:33 +08:00
|
|
|
pthread_create(thread, attr, rdar_7299394_start_routine, number);
|
|
|
|
}
|
|
|
|
void rdar_7299394_positive(pthread_attr_t *attr, pthread_t *thread) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}}
|
2009-10-14 06:55:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-26 12:32:23 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/11282706> false positive with not understanding thread
|
|
|
|
// local storage
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void rdar11282706(pthread_key_t key) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2012-04-26 12:32:23 +08:00
|
|
|
pthread_setspecific(key, (void*) number);
|
|
|
|
}
|
|
|
|
|
2009-10-14 06:55:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-14 08:27:24 +08:00
|
|
|
// <rdar://problem/7283567> False leak associated with call to
|
|
|
|
// CVPixelBufferCreateWithBytes ()
|
|
|
|
//
|
|
|
|
// According to the Core Video Reference (ADC), CVPixelBufferCreateWithBytes and
|
|
|
|
// CVPixelBufferCreateWithPlanarBytes can release (via a callback) the
|
|
|
|
// pixel buffer object. These test cases show how the analyzer stops tracking
|
|
|
|
// the reference count for the objects passed for this argument. This
|
|
|
|
// could be made smarter.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef int int32_t;
|
|
|
|
typedef UInt32 FourCharCode;
|
|
|
|
typedef FourCharCode OSType;
|
|
|
|
typedef uint64_t CVOptionFlags;
|
|
|
|
typedef int32_t CVReturn;
|
|
|
|
typedef struct __CVBuffer *CVBufferRef;
|
|
|
|
typedef CVBufferRef CVImageBufferRef;
|
|
|
|
typedef CVImageBufferRef CVPixelBufferRef;
|
|
|
|
typedef void (*CVPixelBufferReleaseBytesCallback)( void *releaseRefCon, const void *baseAddress );
|
|
|
|
|
|
|
|
extern CVReturn CVPixelBufferCreateWithBytes(CFAllocatorRef allocator,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
OSType pixelFormatType,
|
|
|
|
void *baseAddress,
|
|
|
|
size_t bytesPerRow,
|
|
|
|
CVPixelBufferReleaseBytesCallback releaseCallback,
|
|
|
|
void *releaseRefCon,
|
|
|
|
CFDictionaryRef pixelBufferAttributes,
|
|
|
|
CVPixelBufferRef *pixelBufferOut) ;
|
|
|
|
|
|
|
|
typedef void (*CVPixelBufferReleasePlanarBytesCallback)( void *releaseRefCon, const void *dataPtr, size_t dataSize, size_t numberOfPlanes, const void *planeAddresses[] );
|
|
|
|
|
|
|
|
extern CVReturn CVPixelBufferCreateWithPlanarBytes(CFAllocatorRef allocator,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
OSType pixelFormatType,
|
|
|
|
void *dataPtr,
|
|
|
|
size_t dataSize,
|
|
|
|
size_t numberOfPlanes,
|
|
|
|
void *planeBaseAddress[],
|
|
|
|
size_t planeWidth[],
|
|
|
|
size_t planeHeight[],
|
|
|
|
size_t planeBytesPerRow[],
|
|
|
|
CVPixelBufferReleasePlanarBytesCallback releaseCallback,
|
|
|
|
void *releaseRefCon,
|
|
|
|
CFDictionaryRef pixelBufferAttributes,
|
|
|
|
CVPixelBufferRef *pixelBufferOut) ;
|
|
|
|
|
|
|
|
extern CVReturn CVPixelBufferCreateWithBytes(CFAllocatorRef allocator,
|
|
|
|
size_t width,
|
|
|
|
size_t height,
|
|
|
|
OSType pixelFormatType,
|
|
|
|
void *baseAddress,
|
|
|
|
size_t bytesPerRow,
|
|
|
|
CVPixelBufferReleaseBytesCallback releaseCallback,
|
|
|
|
void *releaseRefCon,
|
|
|
|
CFDictionaryRef pixelBufferAttributes,
|
|
|
|
CVPixelBufferRef *pixelBufferOut) ;
|
|
|
|
|
|
|
|
CVReturn rdar_7283567(CFAllocatorRef allocator, size_t width, size_t height,
|
|
|
|
OSType pixelFormatType, void *baseAddress,
|
|
|
|
size_t bytesPerRow,
|
|
|
|
CVPixelBufferReleaseBytesCallback releaseCallback,
|
|
|
|
CFDictionaryRef pixelBufferAttributes,
|
|
|
|
CVPixelBufferRef *pixelBufferOut) {
|
|
|
|
|
|
|
|
// For the allocated object, it doesn't really matter what type it is
|
|
|
|
// for the purpose of this test. All we want to show is that
|
|
|
|
// this is freed later by the callback.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-10-14 08:27:24 +08:00
|
|
|
|
|
|
|
return CVPixelBufferCreateWithBytes(allocator, width, height, pixelFormatType,
|
|
|
|
baseAddress, bytesPerRow, releaseCallback,
|
|
|
|
number, // potentially released by callback
|
|
|
|
pixelBufferAttributes, pixelBufferOut) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height,
|
|
|
|
OSType pixelFormatType, void *dataPtr, size_t dataSize,
|
|
|
|
size_t numberOfPlanes, void *planeBaseAddress[],
|
|
|
|
size_t planeWidth[], size_t planeHeight[], size_t planeBytesPerRow[],
|
|
|
|
CVPixelBufferReleasePlanarBytesCallback releaseCallback,
|
|
|
|
CFDictionaryRef pixelBufferAttributes,
|
|
|
|
CVPixelBufferRef *pixelBufferOut) {
|
|
|
|
|
|
|
|
// For the allocated object, it doesn't really matter what type it is
|
|
|
|
// for the purpose of this test. All we want to show is that
|
|
|
|
// this is freed later by the callback.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-10-14 08:27:24 +08:00
|
|
|
|
|
|
|
return CVPixelBufferCreateWithPlanarBytes(allocator,
|
|
|
|
width, height, pixelFormatType, dataPtr, dataSize,
|
|
|
|
numberOfPlanes, planeBaseAddress, planeWidth,
|
|
|
|
planeHeight, planeBytesPerRow, releaseCallback,
|
|
|
|
number, // potentially released by callback
|
|
|
|
pixelBufferAttributes, pixelBufferOut) ;
|
|
|
|
}
|
|
|
|
|
2016-08-12 02:41:29 +08:00
|
|
|
#pragma clang arc_cf_code_audited begin
|
|
|
|
typedef struct SomeOpaqueStruct *CMSampleBufferRef;
|
|
|
|
CVImageBufferRef _Nonnull CMSampleBufferGetImageBuffer(CMSampleBufferRef _Nonnull sbuf);
|
|
|
|
#pragma clang arc_cf_code_audited end
|
|
|
|
|
|
|
|
CVBufferRef _Nullable CVBufferRetain(CVBufferRef _Nullable buffer);
|
|
|
|
void CVBufferRelease(CF_CONSUMED CVBufferRef _Nullable buffer);
|
|
|
|
|
|
|
|
void testCVPrefixRetain(CMSampleBufferRef sbuf) {
|
|
|
|
// Make sure RetainCountChecker treats CVFooRetain() as a CF-style retain.
|
|
|
|
CVPixelBufferRef pixelBuf = CMSampleBufferGetImageBuffer(sbuf);
|
|
|
|
CVBufferRetain(pixelBuf);
|
|
|
|
CVBufferRelease(pixelBuf); // no-warning
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure result of CVFooRetain() is the same as its argument.
|
|
|
|
CVPixelBufferRef pixelBufAlias = CVBufferRetain(pixelBuf);
|
|
|
|
CVBufferRelease(pixelBufAlias); // no-warning
|
|
|
|
}
|
|
|
|
|
2016-11-12 05:31:38 +08:00
|
|
|
typedef signed long SInt32;
|
|
|
|
typedef SInt32 OSStatus;
|
|
|
|
typedef FourCharCode CMVideoCodecType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef UInt32 VTEncodeInfoFlags; enum {
|
|
|
|
kVTEncodeInfo_Asynchronous = 1UL << 0,
|
|
|
|
kVTEncodeInfo_FrameDropped = 1UL << 1,
|
|
|
|
};
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int ignore;
|
|
|
|
} CMTime;
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*VTCompressionOutputCallback)(
|
|
|
|
void * _Nullable outputCallbackRefCon,
|
|
|
|
void * _Nullable sourceFrameRefCon,
|
|
|
|
OSStatus status,
|
|
|
|
VTEncodeInfoFlags infoFlags,
|
|
|
|
_Nullable CMSampleBufferRef sampleBuffer );
|
|
|
|
|
|
|
|
typedef struct OpaqueVTCompressionSession* VTCompressionSessionRef;
|
|
|
|
|
|
|
|
extern OSStatus
|
|
|
|
VTCompressionSessionCreate(_Nullable CFAllocatorRef allocator,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
CMVideoCodecType codecType,
|
|
|
|
_Nullable CFDictionaryRef encoderSpecification,
|
|
|
|
_Nullable CFDictionaryRef sourceImageBufferAttributes,
|
|
|
|
_Nullable CFAllocatorRef compressedDataAllocator,
|
|
|
|
_Nullable VTCompressionOutputCallback outputCallback,
|
|
|
|
void * _Nullable outputCallbackRefCon,
|
|
|
|
CF_RETURNS_RETAINED _Nullable VTCompressionSessionRef * _Nonnull compressionSessionOut);
|
|
|
|
|
|
|
|
extern OSStatus
|
|
|
|
VTCompressionSessionEncodeFrame(
|
|
|
|
_Nonnull VTCompressionSessionRef session,
|
|
|
|
_Nonnull CVImageBufferRef imageBuffer,
|
|
|
|
CMTime presentationTimeStamp,
|
|
|
|
CMTime duration,
|
|
|
|
_Nullable CFDictionaryRef frameProperties,
|
|
|
|
void * _Nullable sourceFrameRefCon,
|
|
|
|
VTEncodeInfoFlags * _Nullable infoFlagsOut);
|
|
|
|
|
|
|
|
OSStatus test_VTCompressionSessionCreateAndEncode_CallbackReleases(
|
|
|
|
_Nullable CFAllocatorRef allocator,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
CMVideoCodecType codecType,
|
|
|
|
_Nullable CFDictionaryRef encoderSpecification,
|
|
|
|
_Nullable CFDictionaryRef sourceImageBufferAttributes,
|
|
|
|
_Nullable CFAllocatorRef compressedDataAllocator,
|
|
|
|
_Nullable VTCompressionOutputCallback outputCallback,
|
|
|
|
|
|
|
|
_Nonnull CVImageBufferRef imageBuffer,
|
|
|
|
CMTime presentationTimeStamp,
|
|
|
|
CMTime duration,
|
|
|
|
_Nullable CFDictionaryRef frameProperties
|
|
|
|
) {
|
|
|
|
|
|
|
|
// The outputCallback is passed both contexts and so can release either.
|
|
|
|
NSNumber *contextForCreate = [[NSNumber alloc] initWithInt:5]; // no-warning
|
|
|
|
NSNumber *contextForEncode = [[NSNumber alloc] initWithInt:6]; // no-warning
|
|
|
|
|
|
|
|
VTCompressionSessionRef session = 0;
|
|
|
|
OSStatus status = VTCompressionSessionCreate(allocator,
|
|
|
|
width, height, codecType, encoderSpecification,
|
|
|
|
sourceImageBufferAttributes,
|
|
|
|
compressedDataAllocator, outputCallback, contextForCreate,
|
|
|
|
&session);
|
|
|
|
|
|
|
|
VTEncodeInfoFlags encodeInfoFlags;
|
|
|
|
|
|
|
|
status = VTCompressionSessionEncodeFrame(session, imageBuffer,
|
|
|
|
presentationTimeStamp, duration, frameProperties, contextForEncode,
|
|
|
|
&encodeInfoFlags);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-11-03 13:34:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/7358899> False leak associated with
|
|
|
|
// CGBitmapContextCreateWithData
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
typedef uint32_t CGBitmapInfo;
|
|
|
|
typedef void (*CGBitmapContextReleaseDataCallback)(void *releaseInfo, void *data);
|
|
|
|
|
|
|
|
CGContextRef CGBitmapContextCreateWithData(void *data,
|
|
|
|
size_t width, size_t height, size_t bitsPerComponent,
|
|
|
|
size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo,
|
|
|
|
CGBitmapContextReleaseDataCallback releaseCallback, void *releaseInfo);
|
|
|
|
|
|
|
|
void rdar_7358899(void *data,
|
|
|
|
size_t width, size_t height, size_t bitsPerComponent,
|
|
|
|
size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo,
|
|
|
|
CGBitmapContextReleaseDataCallback releaseCallback) {
|
|
|
|
|
|
|
|
// For the allocated object, it doesn't really matter what type it is
|
|
|
|
// for the purpose of this test. All we want to show is that
|
|
|
|
// this is freed later by the callback.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-11-03 13:34:07 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
CGBitmapContextCreateWithData(data, width, height, bitsPerComponent, // expected-warning{{leak}}
|
2009-11-03 13:34:07 +08:00
|
|
|
bytesPerRow, space, bitmapInfo, releaseCallback, number);
|
|
|
|
}
|
|
|
|
|
2009-10-20 08:13:00 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/7265711> allow 'new', 'copy', 'alloc', 'init' prefix to
|
|
|
|
// start before '_' when determining Cocoa fundamental rule
|
|
|
|
//
|
|
|
|
// Previously the retain/release checker just skipped prefixes before the
|
|
|
|
// first '_' entirely. Now the checker honors the prefix if it results in a
|
|
|
|
// recognizable naming convention (e.g., 'new', 'init').
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar7265711 {}
|
|
|
|
- (id) new_stuff;
|
|
|
|
@end
|
|
|
|
|
|
|
|
void rdar7265711_a(RDar7265711 *x) {
|
2012-09-07 15:40:40 +08:00
|
|
|
id y = [x new_stuff]; // expected-warning{{leak}}
|
2009-10-20 08:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rdar7265711_b(RDar7265711 *x) {
|
2012-09-07 15:40:40 +08:00
|
|
|
id y = [x new_stuff]; // no-warning
|
2009-10-20 08:13:00 +08:00
|
|
|
[y release];
|
|
|
|
}
|
|
|
|
|
2009-10-14 08:27:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-16 06:25:12 +08:00
|
|
|
// <rdar://problem/7306898> clang thinks [NSCursor dragCopyCursor] returns a
|
|
|
|
// retained reference
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface NSCursor : NSObject
|
|
|
|
+ (NSCursor *)dragCopyCursor;
|
|
|
|
@end
|
|
|
|
|
|
|
|
void rdar7306898(void) {
|
|
|
|
// 'dragCopyCursor' does not follow Cocoa's fundamental rule. It is a noun, not an sentence
|
|
|
|
// implying a 'copy' of something.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSCursor *c = [NSCursor dragCopyCursor]; // no-warning
|
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}}
|
2009-10-16 06:25:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-11-20 13:27:05 +08:00
|
|
|
// <rdar://problem/7252064> sending 'release', 'retain', etc. to a Class
|
|
|
|
// directly is not likely what the user intended
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface RDar7252064 : NSObject @end
|
|
|
|
void rdar7252064(void) {
|
2012-09-07 15:40:40 +08:00
|
|
|
[RDar7252064 release]; // expected-warning{{The 'release' message should be sent to instances of class 'RDar7252064' and not the class directly}}
|
|
|
|
[RDar7252064 retain]; // expected-warning{{The 'retain' message should be sent to instances of class 'RDar7252064' and not the class directly}}
|
|
|
|
[RDar7252064 autorelease]; // expected-warning{{The 'autorelease' message should be sent to instances of class 'RDar7252064' and not the class directly}}
|
|
|
|
[NSAutoreleasePool drain]; // expected-warning{{method '+drain' not found}} expected-warning{{The 'drain' message should be sent to instances of class 'NSAutoreleasePool' and not the class directly}}
|
2009-11-20 13:27:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-05-09 11:10:32 +08:00
|
|
|
// Tests of ownership attributes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-05-14 05:07:32 +08:00
|
|
|
typedef NSString* MyStringTy;
|
|
|
|
|
2009-07-22 05:21:04 +08:00
|
|
|
@protocol FooP;
|
|
|
|
|
2009-05-09 11:10:32 +08:00
|
|
|
@interface TestOwnershipAttr : NSObject
|
2012-09-07 15:40:40 +08:00
|
|
|
- (NSString*) returnsAnOwnedString NS_RETURNS_RETAINED; // no-warning
|
|
|
|
- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; // no-warning
|
|
|
|
- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning
|
|
|
|
- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning
|
2012-12-21 03:36:22 +08:00
|
|
|
- (NSString*) newString_auto NS_RETURNS_AUTORELEASED; // no-warning
|
2010-02-18 08:06:12 +08:00
|
|
|
- (NSString*) newStringNoAttr;
|
2012-09-07 15:40:40 +08:00
|
|
|
- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to methods that return an Objective-C object}}
|
2011-01-27 14:54:14 +08:00
|
|
|
- (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED;
|
2011-01-28 02:43:03 +08:00
|
|
|
+ (void) consume:(id) NS_CONSUMED x;
|
|
|
|
+ (void) consume2:(id) CF_CONSUMED x;
|
2009-05-09 11:10:32 +08:00
|
|
|
@end
|
|
|
|
|
2017-07-15 19:06:46 +08:00
|
|
|
static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' only applies to function types; type here is 'int'}}
|
2009-05-14 05:07:32 +08:00
|
|
|
|
2009-05-09 11:10:32 +08:00
|
|
|
void test_attr_1(TestOwnershipAttr *X) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}}
|
2009-05-09 11:10:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_attr_1b(TestOwnershipAttr *X) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
|
2009-05-09 11:10:32 +08:00
|
|
|
}
|
2009-06-06 07:00:33 +08:00
|
|
|
|
2010-02-18 08:06:12 +08:00
|
|
|
void test_attr1c(TestOwnershipAttr *X) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *str = [X newString]; // no-warning
|
|
|
|
NSString *str2 = [X newStringNoAttr]; // expected-warning{{leak}}
|
2012-12-21 03:36:22 +08:00
|
|
|
NSString *str3 = [X newString_auto]; // no-warning
|
|
|
|
NSString *str4 = [[X newString_auto] retain]; // expected-warning {{leak}}
|
2010-02-18 08:06:12 +08:00
|
|
|
}
|
|
|
|
|
2011-01-27 14:54:14 +08:00
|
|
|
void testattr2_a() {
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // expected-warning{{leak}}
|
2011-01-27 14:54:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void testattr2_b() {
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // expected-warning{{leak}}
|
2011-01-27 14:54:14 +08:00
|
|
|
}
|
|
|
|
|
2012-05-02 08:15:40 +08:00
|
|
|
void testattr2_b_11358224_self_assign_looses_the_leak() {
|
|
|
|
TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];// expected-warning{{leak}}
|
|
|
|
x = x;
|
|
|
|
}
|
|
|
|
|
2011-01-27 14:54:14 +08:00
|
|
|
void testattr2_c() {
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // no-warning
|
2011-01-27 14:54:14 +08:00
|
|
|
[x release];
|
|
|
|
}
|
|
|
|
|
2011-01-28 02:43:03 +08:00
|
|
|
void testattr3() {
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning
|
2011-01-28 02:43:03 +08:00
|
|
|
[TestOwnershipAttr consume:x];
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning
|
2011-01-28 02:43:03 +08:00
|
|
|
[TestOwnershipAttr consume2:y];
|
|
|
|
}
|
|
|
|
|
|
|
|
void consume_ns(id NS_CONSUMED x);
|
|
|
|
void consume_cf(id CF_CONSUMED x);
|
|
|
|
|
|
|
|
void testattr4() {
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning
|
2011-01-28 02:43:03 +08:00
|
|
|
consume_ns(x);
|
2012-09-07 15:40:40 +08:00
|
|
|
TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning
|
2011-01-28 02:43:03 +08:00
|
|
|
consume_cf(y);
|
|
|
|
}
|
|
|
|
|
2012-09-07 07:03:07 +08:00
|
|
|
@interface TestOwnershipAttr2 : NSObject
|
2012-09-07 15:40:40 +08:00
|
|
|
- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning
|
2012-09-07 07:03:07 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TestOwnershipAttr2
|
|
|
|
- (NSString*) newString {
|
2012-09-07 15:40:40 +08:00
|
|
|
return [NSString alloc]; // expected-warning {{Potential leak of an object}}
|
2012-09-07 07:03:07 +08:00
|
|
|
}
|
|
|
|
@end
|
2011-01-28 02:43:03 +08:00
|
|
|
|
2009-06-06 07:00:33 +08:00
|
|
|
@interface MyClassTestCFAttr : NSObject {}
|
2009-07-17 08:19:33 +08:00
|
|
|
- (NSDate*) returnsCFRetained CF_RETURNS_RETAINED;
|
|
|
|
- (CFDateRef) returnsCFRetainedAsCF CF_RETURNS_RETAINED;
|
2010-02-18 08:06:12 +08:00
|
|
|
- (CFDateRef) newCFRetainedAsCF CF_RETURNS_NOT_RETAINED;
|
|
|
|
- (CFDateRef) newCFRetainedAsCFNoAttr;
|
2009-06-06 07:00:33 +08:00
|
|
|
- (NSDate*) alsoReturnsRetained;
|
2009-07-07 02:30:43 +08:00
|
|
|
- (CFDateRef) alsoReturnsRetainedAsCF;
|
2009-07-17 08:19:33 +08:00
|
|
|
- (NSDate*) returnsNSRetained NS_RETURNS_RETAINED;
|
2009-06-06 07:00:33 +08:00
|
|
|
@end
|
|
|
|
|
2009-07-17 08:19:33 +08:00
|
|
|
CF_RETURNS_RETAINED
|
2009-06-06 07:00:33 +08:00
|
|
|
CFDateRef returnsRetainedCFDate() {
|
|
|
|
return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation MyClassTestCFAttr
|
|
|
|
- (NSDate*) returnsCFRetained {
|
|
|
|
return (NSDate*) returnsRetainedCFDate(); // No leak.
|
|
|
|
}
|
|
|
|
|
2009-07-07 02:30:43 +08:00
|
|
|
- (CFDateRef) returnsCFRetainedAsCF {
|
|
|
|
return returnsRetainedCFDate(); // No leak.
|
|
|
|
}
|
|
|
|
|
2010-02-18 08:06:12 +08:00
|
|
|
- (CFDateRef) newCFRetainedAsCF {
|
|
|
|
return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CFDateRef) newCFRetainedAsCFNoAttr {
|
2012-09-07 15:40:40 +08:00
|
|
|
return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}
|
2010-02-18 08:06:12 +08:00
|
|
|
}
|
2009-07-07 02:30:43 +08:00
|
|
|
|
2009-06-06 07:00:33 +08:00
|
|
|
- (NSDate*) alsoReturnsRetained {
|
2012-09-07 15:40:40 +08:00
|
|
|
return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
|
2009-06-06 07:00:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-07 02:30:43 +08:00
|
|
|
- (CFDateRef) alsoReturnsRetainedAsCF {
|
2012-09-07 15:40:40 +08:00
|
|
|
return returnsRetainedCFDate(); // expected-warning{{leak}}
|
2009-07-07 02:30:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-06 07:00:33 +08:00
|
|
|
- (NSDate*) returnsNSRetained {
|
2012-09-07 15:40:40 +08:00
|
|
|
return (NSDate*) returnsRetainedCFDate(); // no-warning
|
2009-06-06 07:00:33 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2009-09-15 08:40:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test that leaks post-dominated by "panic" functions are not reported.
|
|
|
|
//
|
|
|
|
// <rdar://problem/5905851> do not report a leak when post-dominated by a call
|
|
|
|
// to a noreturn or panic function
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void panic() __attribute__((noreturn));
|
2010-03-27 06:57:13 +08:00
|
|
|
void panic_not_in_hardcoded_list() __attribute__((noreturn));
|
2009-09-15 08:40:32 +08:00
|
|
|
|
|
|
|
void test_panic_negative() {
|
|
|
|
signed z = 1;
|
2012-09-07 15:40:40 +08:00
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // expected-warning{{leak}}
|
2009-09-15 08:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_panic_positive() {
|
|
|
|
signed z = 1;
|
2012-09-07 15:40:40 +08:00
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // no-warning
|
2009-09-15 08:40:32 +08:00
|
|
|
panic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_panic_neg_2(int x) {
|
|
|
|
signed z = 1;
|
2012-09-07 15:40:40 +08:00
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // expected-warning{{leak}}
|
2009-09-15 08:40:32 +08:00
|
|
|
if (x)
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_panic_pos_2(int x) {
|
|
|
|
signed z = 1;
|
2012-09-07 15:40:40 +08:00
|
|
|
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // no-warning
|
2009-09-15 08:40:32 +08:00
|
|
|
if (x)
|
|
|
|
panic();
|
2010-03-27 06:57:13 +08:00
|
|
|
if (!x) {
|
|
|
|
// This showed up in <rdar://problem/7796563>, where we silently missed checking
|
|
|
|
// the function type for noreturn. "panic()" is a hard-coded known panic function
|
|
|
|
// that isn't always noreturn.
|
|
|
|
panic_not_in_hardcoded_list();
|
|
|
|
}
|
2009-09-15 08:40:32 +08:00
|
|
|
}
|
|
|
|
|
2009-11-25 09:35:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test uses of blocks (closures)
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void test_blocks_1_pos(void) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}}
|
2009-11-25 09:35:18 +08:00
|
|
|
^{}();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_blocks_1_indirect_release(void) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-11-25 09:35:18 +08:00
|
|
|
^{ [number release]; }();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_blocks_1_indirect_retain(void) {
|
|
|
|
// Eventually this should be reported as a leak.
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-11-25 09:35:18 +08:00
|
|
|
^{ [number retain]; }();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_blocks_1_indirect_release_via_call(void) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning
|
2009-11-25 09:35:18 +08:00
|
|
|
^(NSObject *o){ [o release]; }(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_blocks_1_indirect_retain_via_call(void) {
|
2012-09-07 15:40:40 +08:00
|
|
|
NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning {{leak}}
|
2009-11-25 09:35:18 +08:00
|
|
|
^(NSObject *o){ [o retain]; }(number);
|
|
|
|
}
|
|
|
|
|
2010-05-22 05:57:00 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Test sending message to super that returns an object alias. Previously
|
|
|
|
// this caused a crash in the analyzer.
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface Rdar8015556 : NSObject {} @end
|
|
|
|
@implementation Rdar8015556
|
|
|
|
- (id)retain {
|
|
|
|
return [super retain];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2010-08-05 08:19:24 +08:00
|
|
|
// <rdar://problem/8272168> - Correcly handle Class<...> in Cocoa Conventions
|
|
|
|
// detector.
|
|
|
|
|
|
|
|
@protocol Prot_R8272168 @end
|
|
|
|
Class <Prot_R8272168> GetAClassThatImplementsProt_R8272168();
|
|
|
|
void r8272168() {
|
|
|
|
GetAClassThatImplementsProt_R8272168();
|
|
|
|
}
|
|
|
|
|
2010-10-28 10:50:32 +08:00
|
|
|
// Test case for <rdar://problem/8356342>, which in the past triggered
|
|
|
|
// a false positive.
|
|
|
|
@interface RDar8356342
|
|
|
|
- (NSDate*) rdar8356342:(NSDate *)inValue;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar8356342
|
|
|
|
- (NSDate*) rdar8356342:(NSDate*)inValue {
|
|
|
|
NSDate *outValue = inValue;
|
|
|
|
if (outValue == 0)
|
2012-09-07 15:40:40 +08:00
|
|
|
outValue = [[NSDate alloc] init]; // no-warning
|
2010-10-28 10:50:32 +08:00
|
|
|
|
|
|
|
if (outValue != inValue)
|
|
|
|
[outValue autorelease];
|
|
|
|
|
|
|
|
return outValue;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2010-12-03 14:53:12 +08:00
|
|
|
// <rdar://problem/8724287> - This test case previously crashed because
|
|
|
|
// of a bug in BugReporter.
|
|
|
|
extern const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key);
|
|
|
|
typedef struct __CFError * CFErrorRef;
|
|
|
|
extern const CFStringRef kCFErrorUnderlyingErrorKey;
|
|
|
|
extern CFDictionaryRef CFErrorCopyUserInfo(CFErrorRef err);
|
|
|
|
static void rdar_8724287(CFErrorRef error)
|
|
|
|
{
|
|
|
|
CFErrorRef error_to_dump;
|
|
|
|
|
|
|
|
error_to_dump = error;
|
|
|
|
while (error_to_dump != ((void*)0)) {
|
|
|
|
CFDictionaryRef info;
|
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
info = CFErrorCopyUserInfo(error_to_dump); // expected-warning{{Potential leak of an object}}
|
2010-12-03 14:53:12 +08:00
|
|
|
|
|
|
|
if (info != ((void*)0)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
error_to_dump = (CFErrorRef) CFDictionaryGetValue(info, kCFErrorUnderlyingErrorKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-06 17:02:12 +08:00
|
|
|
// <rdar://problem/9234108> - Make sure the model applies cf_consumed
|
|
|
|
// correctly in argument positions besides the first.
|
|
|
|
extern void *CFStringCreate(void);
|
|
|
|
extern void rdar_9234108_helper(void *key, void * CF_CONSUMED value);
|
|
|
|
void rdar_9234108() {
|
|
|
|
rdar_9234108_helper(0, CFStringCreate());
|
|
|
|
}
|
2011-07-07 00:00:34 +08:00
|
|
|
|
|
|
|
// <rdar://problem/9726279> - Make sure that objc_method_family works
|
|
|
|
// to override naming conventions.
|
|
|
|
struct TwoDoubles {
|
|
|
|
double one;
|
|
|
|
double two;
|
|
|
|
};
|
|
|
|
typedef struct TwoDoubles TwoDoubles;
|
|
|
|
|
|
|
|
@interface NSValue (Mine)
|
|
|
|
- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles __attribute__((objc_method_family(init)));
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSValue (Mine)
|
|
|
|
- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles
|
|
|
|
{
|
|
|
|
return [self init];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
void rdar9726279() {
|
|
|
|
TwoDoubles twoDoubles = { 0.0, 0.0 };
|
|
|
|
NSValue *value = [[NSValue alloc] _prefix_initWithTwoDoubles:twoDoubles];
|
|
|
|
[value release];
|
|
|
|
}
|
2011-07-17 03:50:36 +08:00
|
|
|
|
|
|
|
// <rdar://problem/9732321>
|
|
|
|
// Test camelcase support for CF conventions. While Core Foundation APIs
|
|
|
|
// don't use camel casing, other code is allowed to use it.
|
|
|
|
CFArrayRef camelcase_create_1() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camelcase_createno() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}}
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camelcase_copy() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camelcase_copying() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}}
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef copyCamelCase() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef __copyCamelCase() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef __createCamelCase() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camel_create() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFArrayRef camel_creat() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}}
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camel_copy() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camel_copyMachine() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef camel_copymachine() {
|
2012-09-07 15:40:40 +08:00
|
|
|
return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}}
|
2011-07-17 03:50:36 +08:00
|
|
|
}
|
|
|
|
|
2011-07-22 10:45:48 +08:00
|
|
|
// rdar://problem/8024350
|
|
|
|
@protocol F18P
|
2017-09-20 13:39:18 +08:00
|
|
|
- (id) clone; // expected-note 2 {{method declared here}}
|
2011-07-22 10:45:48 +08:00
|
|
|
@end
|
|
|
|
@interface F18 : NSObject<F18P> @end
|
|
|
|
@interface F18(Cat)
|
2017-09-20 13:39:18 +08:00
|
|
|
- (id) clone NS_RETURNS_RETAINED; // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
|
2011-07-22 10:45:48 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation F18
|
2017-09-20 13:39:18 +08:00
|
|
|
- (id) clone { // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
|
2011-07-22 10:45:48 +08:00
|
|
|
return [F18 alloc];
|
|
|
|
}
|
|
|
|
@end
|
2011-07-29 07:08:16 +08:00
|
|
|
|
|
|
|
// Radar 6582778.
|
|
|
|
void rdar6582778(void) {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
2012-09-07 15:40:40 +08:00
|
|
|
CFTypeRef vals[] = { CFDateCreate(0, t) }; // expected-warning {{leak}}
|
2011-07-29 07:08:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CFTypeRef global;
|
|
|
|
|
|
|
|
void rdar6582778_2(void) {
|
|
|
|
CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
|
2012-09-07 15:40:40 +08:00
|
|
|
global = CFDateCreate(0, t); // no-warning
|
2011-07-29 07:08:16 +08:00
|
|
|
}
|
2011-10-06 07:54:29 +08:00
|
|
|
|
|
|
|
// <rdar://problem/10232019> - Test that objects passed to containers
|
|
|
|
// are marked "escaped".
|
|
|
|
|
|
|
|
void rdar10232019() {
|
|
|
|
NSMutableArray *array = [NSMutableArray array];
|
|
|
|
|
|
|
|
NSString *string = [[NSString alloc] initWithUTF8String:"foo"];
|
|
|
|
[array addObject:string];
|
|
|
|
[string release];
|
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *otherString = [string stringByAppendingString:@"bar"]; // no-warning
|
2011-10-06 07:54:29 +08:00
|
|
|
NSLog(@"%@", otherString);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdar10232019_positive() {
|
|
|
|
NSMutableArray *array = [NSMutableArray array];
|
|
|
|
|
|
|
|
NSString *string = [[NSString alloc] initWithUTF8String:"foo"];
|
|
|
|
[string release];
|
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
NSString *otherString = [string stringByAppendingString:@"bar"]; // expected-warning {{Reference-counted object is used after it is release}}
|
2011-10-06 07:54:29 +08:00
|
|
|
NSLog(@"%@", otherString);
|
|
|
|
}
|
|
|
|
|
2012-01-04 08:35:48 +08:00
|
|
|
// RetainCountChecker support for XPC.
|
|
|
|
// <rdar://problem/9658496>
|
|
|
|
typedef void * xpc_object_t;
|
|
|
|
xpc_object_t _CFXPCCreateXPCObjectFromCFObject(CFTypeRef cf);
|
|
|
|
void xpc_release(xpc_object_t object);
|
|
|
|
|
|
|
|
void rdar9658496() {
|
|
|
|
CFStringRef cf;
|
|
|
|
xpc_object_t xpc;
|
2012-09-07 15:40:40 +08:00
|
|
|
cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 ); // no-warning
|
2012-01-04 08:35:48 +08:00
|
|
|
xpc = _CFXPCCreateXPCObjectFromCFObject( cf );
|
|
|
|
CFRelease(cf);
|
|
|
|
xpc_release(xpc);
|
|
|
|
}
|
|
|
|
|
2012-03-10 07:34:08 +08:00
|
|
|
// Support annotations with method families.
|
|
|
|
@interface RDar10824732 : NSObject
|
|
|
|
- (id)initWithObj:(id CF_CONSUMED)obj;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RDar10824732
|
|
|
|
- (id)initWithObj:(id)obj {
|
|
|
|
[obj release];
|
|
|
|
return [super init];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
void rdar_10824732() {
|
|
|
|
@autoreleasepool {
|
|
|
|
NSString *obj = @"test";
|
2012-09-07 15:40:40 +08:00
|
|
|
RDar10824732 *foo = [[RDar10824732 alloc] initWithObj:obj]; // no-warning
|
2012-03-10 07:34:08 +08:00
|
|
|
[foo release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 06:18:39 +08:00
|
|
|
// Stop tracking objects passed to functions, which take callbacks as parameters.
|
|
|
|
// radar://10973977
|
|
|
|
typedef int (*CloseCallback) (void *);
|
|
|
|
void ReaderForIO(CloseCallback ioclose, void *ioctx);
|
|
|
|
int IOClose(void *context);
|
|
|
|
|
|
|
|
@protocol SInS <NSObject>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface radar10973977 : NSObject
|
|
|
|
- (id<SInS>)inputS;
|
|
|
|
- (void)reader;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation radar10973977
|
|
|
|
- (void)reader
|
|
|
|
{
|
|
|
|
id<SInS> inputS = [[self inputS] retain];
|
|
|
|
ReaderForIO(IOClose, inputS);
|
|
|
|
}
|
|
|
|
- (id<SInS>)inputS
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2012-05-10 01:23:11 +08:00
|
|
|
// Object escapes through a selector callback: radar://11398514
|
|
|
|
extern id NSApp;
|
|
|
|
@interface MySheetController
|
|
|
|
- (id<SInS>)inputS;
|
|
|
|
- (void)showDoSomethingSheetAction:(id)action;
|
|
|
|
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MySheetController
|
|
|
|
- (id<SInS>)inputS {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
- (void)showDoSomethingSheetAction:(id)action {
|
|
|
|
id<SInS> inputS = [[self inputS] retain];
|
|
|
|
[NSApp beginSheet:0
|
|
|
|
modalForWindow:0
|
|
|
|
modalDelegate:0
|
|
|
|
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
|
|
|
|
contextInfo:(void *)inputS]; // no - warning
|
|
|
|
}
|
|
|
|
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
|
|
|
|
|
|
|
|
id contextObject = (id)contextInfo;
|
|
|
|
[contextObject release];
|
|
|
|
}
|
2013-02-01 06:36:17 +08:00
|
|
|
|
|
|
|
- (id)copyAutoreleaseRadar13081402 {
|
|
|
|
id x = [[[NSString alloc] initWithUTF8String:"foo"] autorelease];
|
|
|
|
[x retain];
|
|
|
|
return x; // no warning
|
|
|
|
}
|
|
|
|
|
2012-05-10 01:23:11 +08:00
|
|
|
@end
|
2012-03-27 09:12:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test returning allocated memory in a struct.
|
2012-08-21 06:15:44 +08:00
|
|
|
//
|
2012-03-27 09:12:45 +08:00
|
|
|
// We currently don't have a general way to track pointers that "escape".
|
|
|
|
// Here we test that RetainCountChecker doesn't get excited about returning
|
|
|
|
// allocated CF objects in struct fields.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void *malloc(size_t);
|
|
|
|
struct rdar11104566 { CFStringRef myStr; };
|
|
|
|
struct rdar11104566 test_rdar11104566() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 ); // no-warning
|
2012-03-27 09:12:45 +08:00
|
|
|
struct rdar11104566 V;
|
|
|
|
V.myStr = cf;
|
2012-09-07 15:40:40 +08:00
|
|
|
return V; // no-warning
|
2012-03-27 09:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct rdar11104566 *test_2_rdar11104566() {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 ); // no-warning
|
2012-03-27 09:12:45 +08:00
|
|
|
struct rdar11104566 *V = (struct rdar11104566 *) malloc(sizeof(*V));
|
|
|
|
V->myStr = cf;
|
2012-09-07 15:40:40 +08:00
|
|
|
return V; // no-warning
|
2012-03-27 09:12:45 +08:00
|
|
|
}
|
|
|
|
|
2012-03-07 04:06:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjC literals support.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void test_objc_arrays() {
|
|
|
|
{ // CASE ONE -- OBJECT IN ARRAY CREATED DIRECTLY
|
|
|
|
NSObject *o = [[NSObject alloc] init];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSArray *a = [[NSArray alloc] initWithObjects:o, (void*)0]; // expected-warning {{leak}}
|
2012-03-07 04:06:12 +08:00
|
|
|
[o release];
|
|
|
|
[a description];
|
|
|
|
[o description];
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // CASE TWO -- OBJECT IN ARRAY CREATED BY DUPING AUTORELEASED ARRAY
|
|
|
|
NSObject *o = [[NSObject alloc] init];
|
|
|
|
NSArray *a1 = [NSArray arrayWithObjects:o, (void*)0];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSArray *a2 = [[NSArray alloc] initWithArray:a1]; // expected-warning {{leak}}
|
2012-03-07 04:06:12 +08:00
|
|
|
[o release];
|
|
|
|
[a2 description];
|
|
|
|
[o description];
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // CASE THREE -- OBJECT IN RETAINED @[]
|
|
|
|
NSObject *o = [[NSObject alloc] init];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSArray *a3 = [@[o] retain]; // expected-warning {{leak}}
|
2012-03-07 04:06:12 +08:00
|
|
|
[o release];
|
|
|
|
[a3 description];
|
|
|
|
[o description];
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // CASE FOUR -- OBJECT IN ARRAY CREATED BY DUPING @[]
|
|
|
|
NSObject *o = [[NSObject alloc] init];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSArray *a = [[NSArray alloc] initWithArray:@[o]]; // expected-warning {{leak}}
|
2012-03-07 04:06:12 +08:00
|
|
|
[o release];
|
|
|
|
|
|
|
|
[a description];
|
|
|
|
[o description];
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // CASE FIVE -- OBJECT IN RETAINED @{}
|
|
|
|
NSValue *o = [[NSValue alloc] init];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSDictionary *a = [@{o : o} retain]; // expected-warning {{leak}}
|
2012-03-07 04:06:12 +08:00
|
|
|
[o release];
|
|
|
|
|
|
|
|
[a description];
|
|
|
|
[o description];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 13:10:43 +08:00
|
|
|
void test_objc_integer_literals() {
|
2012-09-07 15:40:40 +08:00
|
|
|
id value = [@1 retain]; // expected-warning {{leak}}
|
2012-05-12 13:10:43 +08:00
|
|
|
[value description];
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_objc_boxed_expressions(int x, const char *y) {
|
2012-09-07 15:40:40 +08:00
|
|
|
id value = [@(x) retain]; // expected-warning {{leak}}
|
2012-05-12 13:10:43 +08:00
|
|
|
[value description];
|
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
value = [@(y) retain]; // expected-warning {{leak}}
|
2012-05-12 13:10:43 +08:00
|
|
|
[value description];
|
|
|
|
}
|
|
|
|
|
2012-05-08 08:12:09 +08:00
|
|
|
// Test NSLog doesn't escape tracked objects.
|
|
|
|
void rdar11400885(int y)
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
NSString *printString;
|
|
|
|
if(y > 2)
|
|
|
|
printString = [[NSString alloc] init];
|
|
|
|
else
|
|
|
|
printString = [[NSString alloc] init];
|
|
|
|
NSLog(@"Once %@", printString);
|
|
|
|
[printString release];
|
2012-09-07 15:40:40 +08:00
|
|
|
NSLog(@"Again: %@", printString); // expected-warning {{Reference-counted object is used after it is released}}
|
2012-05-08 08:12:09 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-07 09:11:14 +08:00
|
|
|
|
2018-08-18 05:42:59 +08:00
|
|
|
id makeCollectableNonLeak() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
|
|
|
|
CFTypeRef object = CFCreateSomething(); // +1
|
|
|
|
CFRetain(object); // +2
|
|
|
|
id objCObject = NSMakeCollectable(object); // +2
|
|
|
|
[objCObject release]; // +1
|
|
|
|
return [objCObject autorelease]; // +0
|
|
|
|
}
|
|
|
|
|
2012-08-21 04:01:15 +08:00
|
|
|
void consumeAndStopTracking(id NS_CONSUMED obj, void (^callback)(void));
|
2012-08-21 06:15:44 +08:00
|
|
|
void CFConsumeAndStopTracking(CFTypeRef CF_CONSUMED obj, void (^callback)(void));
|
|
|
|
|
2012-08-21 04:01:15 +08:00
|
|
|
void testConsumeAndStopTracking() {
|
|
|
|
id retained = [@[] retain]; // +1
|
2012-09-07 15:40:40 +08:00
|
|
|
consumeAndStopTracking(retained, ^{}); // no-warning
|
2012-08-21 04:01:15 +08:00
|
|
|
|
|
|
|
id doubleRetained = [[@[] retain] retain]; // +2
|
|
|
|
consumeAndStopTracking(doubleRetained, ^{
|
|
|
|
[doubleRetained release];
|
2012-09-07 15:40:40 +08:00
|
|
|
}); // no-warning
|
2012-08-21 04:01:15 +08:00
|
|
|
|
|
|
|
id unretained = @[]; // +0
|
2012-09-07 15:40:40 +08:00
|
|
|
consumeAndStopTracking(unretained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
2012-08-21 04:01:15 +08:00
|
|
|
}
|
2012-08-21 06:15:44 +08:00
|
|
|
|
|
|
|
void testCFConsumeAndStopTracking() {
|
|
|
|
id retained = [@[] retain]; // +1
|
2012-09-07 15:40:40 +08:00
|
|
|
CFConsumeAndStopTracking((CFTypeRef)retained, ^{}); // no-warning
|
2012-08-21 06:15:44 +08:00
|
|
|
|
2012-09-07 15:40:40 +08:00
|
|
|
id doubleRetained = [[@[] retain] retain]; // +2
|
2012-08-21 06:15:44 +08:00
|
|
|
CFConsumeAndStopTracking((CFTypeRef)doubleRetained, ^{
|
|
|
|
[doubleRetained release];
|
2012-09-07 15:40:40 +08:00
|
|
|
}); // no-warning
|
2012-08-21 06:15:44 +08:00
|
|
|
|
|
|
|
id unretained = @[]; // +0
|
2012-09-07 15:40:40 +08:00
|
|
|
CFConsumeAndStopTracking((CFTypeRef)unretained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
2012-08-21 06:15:44 +08:00
|
|
|
}
|
2012-08-31 03:27:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test 'pragma clang arc_cf_code_audited' support.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef void *MyCFType;
|
|
|
|
#pragma clang arc_cf_code_audited begin
|
|
|
|
MyCFType CreateMyCFType();
|
|
|
|
#pragma clang arc_cf_code_audited end
|
|
|
|
|
|
|
|
void test_custom_cf() {
|
2012-09-07 15:40:40 +08:00
|
|
|
MyCFType x = CreateMyCFType(); // expected-warning {{leak of an object stored into 'x'}}
|
2012-08-31 03:27:02 +08:00
|
|
|
}
|
|
|
|
|
2012-09-07 07:47:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Test calling CFPlugInInstanceCreate, which appears in CF but doesn't
|
|
|
|
// return a CF object.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void test_CFPlugInInstanceCreate(CFUUIDRef factoryUUID, CFUUIDRef typeUUID) {
|
2012-09-07 15:40:40 +08:00
|
|
|
CFPlugInInstanceCreate(kCFAllocatorDefault, factoryUUID, typeUUID); // no-warning
|
|
|
|
}
|
2012-09-08 12:26:37 +08:00
|
|
|
|
2013-01-15 02:58:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PR14927: -drain only has retain-count semantics on NSAutoreleasePool.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
@interface PR14927 : NSObject
|
|
|
|
- (void)drain;
|
|
|
|
@end
|
|
|
|
|
|
|
|
void test_drain() {
|
|
|
|
PR14927 *obj = [[PR14927 alloc] init];
|
|
|
|
[obj drain];
|
|
|
|
[obj release]; // no-warning
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:31:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Allow cf_returns_retained and cf_returns_not_retained to mark a return
|
|
|
|
// value as tracked, even if the object isn't a known CF type.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
MyCFType getCustom() __attribute__((cf_returns_not_retained));
|
|
|
|
MyCFType makeCustom() __attribute__((cf_returns_retained));
|
|
|
|
|
|
|
|
void testCustomReturnsRetained() {
|
|
|
|
MyCFType obj = makeCustom(); // expected-warning {{leak of an object stored into 'obj'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCustomReturnsNotRetained() {
|
|
|
|
CFRelease(getCustom()); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
|
|
|
}
|
2013-01-15 02:58:33 +08:00
|
|
|
|
2013-04-11 05:42:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Don't print variables which are out of the current scope.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@interface MyObj12706177 : NSObject
|
|
|
|
-(id)initX;
|
|
|
|
+(void)test12706177;
|
|
|
|
@end
|
|
|
|
static int Cond;
|
|
|
|
@implementation MyObj12706177
|
|
|
|
-(id)initX {
|
|
|
|
if (Cond)
|
|
|
|
return 0;
|
|
|
|
self = [super init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
+(void)test12706177 {
|
|
|
|
id x = [[MyObj12706177 alloc] initX]; //expected-warning {{Potential leak of an object}}
|
|
|
|
[x release];
|
|
|
|
}
|
|
|
|
@end
|
2013-05-02 09:51:40 +08:00
|
|
|
|
2013-10-08 01:16:52 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CFAutorelease
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CFTypeRef getAutoreleasedCFType() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
return CFAutorelease(CFCreateSomething()); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
CFTypeRef getIncorrectlyAutoreleasedCFType() {
|
|
|
|
extern CFTypeRef CFGetSomething();
|
|
|
|
return CFAutorelease(CFGetSomething()); // expected-warning{{Object autoreleased too many times}}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFTypeRef createIncorrectlyAutoreleasedCFType() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
return CFAutorelease(CFCreateSomething()); // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void useAfterAutorelease() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
CFTypeRef obj = CFCreateSomething();
|
|
|
|
CFAutorelease(obj);
|
|
|
|
|
|
|
|
extern void useCF(CFTypeRef);
|
|
|
|
useCF(obj); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void useAfterRelease() {
|
|
|
|
// Sanity check that the previous example would have warned with CFRelease.
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
CFTypeRef obj = CFCreateSomething();
|
|
|
|
CFRelease(obj);
|
|
|
|
|
|
|
|
extern void useCF(CFTypeRef);
|
|
|
|
useCF(obj); // expected-warning{{Reference-counted object is used after it is released}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testAutoreleaseReturnsInput() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
CFTypeRef obj = CFCreateSomething(); // expected-warning{{Potential leak of an object stored into 'obj'}}
|
|
|
|
CFTypeRef second = CFAutorelease(obj);
|
|
|
|
CFRetain(second);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFTypeRef testAutoreleaseReturnsInputSilent() {
|
|
|
|
extern CFTypeRef CFCreateSomething();
|
|
|
|
CFTypeRef obj = CFCreateSomething();
|
|
|
|
CFTypeRef alias = CFAutorelease(obj);
|
|
|
|
CFRetain(alias);
|
|
|
|
CFRelease(obj);
|
|
|
|
return obj; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void autoreleaseTypedObject() {
|
|
|
|
CFArrayRef arr = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
CFAutorelease((CFTypeRef)arr); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void autoreleaseReturningTypedObject() {
|
|
|
|
CFArrayRef arr = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Potential leak of an object stored into 'arr'}}
|
|
|
|
CFArrayRef alias = (CFArrayRef)CFAutorelease((CFTypeRef)arr);
|
|
|
|
CFRetain(alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFArrayRef autoreleaseReturningTypedObjectSilent() {
|
|
|
|
CFArrayRef arr = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
|
|
|
|
CFArrayRef alias = (CFArrayRef)CFAutorelease((CFTypeRef)arr);
|
|
|
|
CFRetain(alias);
|
|
|
|
CFRelease(arr);
|
|
|
|
return alias; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void autoreleaseObjC() {
|
|
|
|
id obj = [@1 retain];
|
|
|
|
CFAutorelease(obj); // no-warning
|
|
|
|
|
|
|
|
id anotherObj = @1;
|
|
|
|
CFAutorelease(anotherObj);
|
|
|
|
} // expected-warning{{Object autoreleased too many times}}
|
|
|
|
|
2013-05-02 09:51:40 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <rdar://problem/13783514> xpc_connection_set_finalizer_f
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef xpc_object_t xpc_connection_t;
|
|
|
|
typedef void (*xpc_finalizer_t)(void *value);
|
|
|
|
void xpc_connection_set_context(xpc_connection_t connection, void *ctx);
|
|
|
|
void xpc_connection_set_finalizer_f(xpc_connection_t connection,
|
|
|
|
xpc_finalizer_t finalizer);
|
|
|
|
void releaseAfterXPC(void *context) {
|
|
|
|
[(NSArray *)context release];
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdar13783514(xpc_connection_t connection) {
|
|
|
|
xpc_connection_set_context(connection, [[NSMutableArray alloc] init]);
|
|
|
|
xpc_connection_set_finalizer_f(connection, releaseAfterXPC);
|
|
|
|
} // no-warning
|
|
|
|
|
2013-09-17 08:53:28 +08:00
|
|
|
// Do not report leaks when object is cleaned up with __attribute__((cleanup ..)).
|
|
|
|
inline static void cleanupFunction(void *tp) {
|
|
|
|
CFTypeRef x = *(CFTypeRef *)tp;
|
|
|
|
if (x) {
|
|
|
|
CFRelease(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#define ADDCLEANUP __attribute__((cleanup(cleanupFunction)))
|
|
|
|
void foo() {
|
|
|
|
ADDCLEANUP CFStringRef myString;
|
|
|
|
myString = CFStringCreateWithCString(0, "hello world", kCFStringEncodingUTF8);
|
|
|
|
ADDCLEANUP CFStringRef myString2 =
|
|
|
|
CFStringCreateWithCString(0, "hello world", kCFStringEncodingUTF8);
|
|
|
|
}
|
2013-05-02 09:51:40 +08:00
|
|
|
|
2014-01-03 09:19:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Handle NSNull
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
__attribute__((ns_returns_retained))
|
|
|
|
id returnNSNull() {
|
|
|
|
return [NSNull null]; // no-warning
|
|
|
|
}
|
|
|
|
|
2015-06-20 07:17:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// cf_returns_[not_]retained on parameters
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void testCFReturnsNotRetained() {
|
|
|
|
extern void getViaParam(CFTypeRef * CF_RETURNS_NOT_RETAINED outObj);
|
|
|
|
CFTypeRef obj;
|
|
|
|
getViaParam(&obj);
|
|
|
|
CFRelease(obj); // // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
|
|
|
}
|
|
|
|
|
2015-06-20 07:17:51 +08:00
|
|
|
void testCFReturnsNotRetainedAnnotated() {
|
2015-06-25 06:02:08 +08:00
|
|
|
extern void getViaParam2(CFTypeRef * _Nonnull CF_RETURNS_NOT_RETAINED outObj);
|
2015-06-20 07:17:51 +08:00
|
|
|
CFTypeRef obj;
|
|
|
|
getViaParam2(&obj);
|
|
|
|
CFRelease(obj); // // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
|
|
|
}
|
|
|
|
|
2015-06-20 07:17:46 +08:00
|
|
|
void testCFReturnsRetained() {
|
|
|
|
extern int copyViaParam(CFTypeRef * CF_RETURNS_RETAINED outObj);
|
|
|
|
CFTypeRef obj;
|
|
|
|
copyViaParam(&obj);
|
|
|
|
CFRelease(obj);
|
|
|
|
CFRelease(obj); // // FIXME-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCFReturnsRetainedError() {
|
|
|
|
extern int copyViaParam(CFTypeRef * CF_RETURNS_RETAINED outObj);
|
|
|
|
CFTypeRef obj;
|
|
|
|
if (copyViaParam(&obj) == -42)
|
|
|
|
return; // no-warning
|
|
|
|
CFRelease(obj);
|
|
|
|
}
|