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