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