| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core,deadcode.DeadStores -verify %s |
| 2 |
|
| 3 |
// These declarations were reduced using Delta-Debugging from Foundation.h |
| 4 |
// on Mac OS X. The test cases are below. |
| 5 |
|
| 6 |
typedef struct objc_selector *SEL; |
| 7 |
typedef signed char BOOL; |
| 8 |
typedef unsigned int NSUInteger; |
| 9 |
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
| 10 |
@protocol NSObject |
| 11 |
- (BOOL)isEqual:(id)object; |
| 12 |
- (id)retain; |
| 13 |
@end |
| 14 |
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; |
| 15 |
@end |
| 16 |
@interface NSObject <NSObject> {} |
| 17 |
+ (id)alloc; |
| 18 |
@end |
| 19 |
typedef float CGFloat; |
| 20 |
typedef struct _NSPoint {} NSRect; |
| 21 |
NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h); |
| 22 |
enum { NSBackingStoreRetained = 0, NSBackingStoreNonretained = 1, NSBackingStoreBuffered = 2 }; |
| 23 |
typedef NSUInteger NSBackingStoreType; |
| 24 |
@interface NSResponder : NSObject <NSCoding> {} |
| 25 |
@end |
| 26 |
@protocol NSAnimatablePropertyContainer |
| 27 |
- (id)animator; |
| 28 |
@end |
| 29 |
extern NSString *NSAnimationTriggerOrderIn ; |
| 30 |
@class CIFilter, CALayer, NSDictionary, NSScreen, NSShadow, NSTrackingArea; |
| 31 |
@interface NSView : NSResponder <NSAnimatablePropertyContainer> {} @end |
| 32 |
@protocol NSValidatedUserInterfaceItem - (SEL)action; @end |
| 33 |
@protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem; @end @class NSNotification, NSText, NSView, NSMutableSet, NSSet, NSDate; |
| 34 |
enum { NSBorderlessWindowMask = 0, NSTitledWindowMask = 1 << 0, NSClosableWindowMask = 1 << 1, NSMiniaturizableWindowMask = 1 << 2, NSResizableWindowMask = 1 << 3 }; |
| 35 |
@interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations> { |
| 36 |
struct __wFlags {} _wFlags; |
| 37 |
} |
| 38 |
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag; |
| 39 |
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag screen:(NSScreen *)screen; |
| 40 |
- (void)orderFrontRegardless; |
| 41 |
@end |
| 42 |
|
| 43 |
extern NSString *NSWindowDidBecomeKeyNotification; |
| 44 |
|
| 45 |
// Test cases. |
| 46 |
|
| 47 |
void f1(void) { |
| 48 |
NSWindow *window = [[NSWindow alloc] |
| 49 |
initWithContentRect:NSMakeRect(0,0,100,100) |
| 50 |
styleMask:NSTitledWindowMask|NSClosableWindowMask |
| 51 |
backing:NSBackingStoreBuffered |
| 52 |
defer:0]; |
| 53 |
|
| 54 |
[window orderFrontRegardless]; // no-warning |
| 55 |
} |
| 56 |
|
| 57 |
void f2(void) { |
| 58 |
NSWindow *window = [[NSWindow alloc] |
| 59 |
initWithContentRect:NSMakeRect(0,0,100,100) |
| 60 |
styleMask:NSTitledWindowMask|NSClosableWindowMask |
| 61 |
backing:NSBackingStoreBuffered |
| 62 |
defer:0 |
| 63 |
screen:0]; |
| 64 |
|
| 65 |
[window orderFrontRegardless]; // no-warning |
| 66 |
} |
| 67 |
|
| 68 |
void f2b(void) { |
| 69 |
// FIXME: NSWindow doesn't own itself until it is displayed. |
| 70 |
NSWindow *window = [[NSWindow alloc] // no-warning |
| 71 |
initWithContentRect:NSMakeRect(0,0,100,100) |
| 72 |
styleMask:NSTitledWindowMask|NSClosableWindowMask |
| 73 |
backing:NSBackingStoreBuffered |
| 74 |
defer:0 |
| 75 |
screen:0]; |
| 76 |
|
| 77 |
[window orderFrontRegardless]; |
| 78 |
|
| 79 |
[window retain]; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
void f3(void) { |
| 84 |
// FIXME: For now we don't track NSWindow. |
| 85 |
NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}} |
| 86 |
} |