blob: 495f8e19d8ef023bf277d142118f9f2731bcebfb [file] [log] [blame]
Jordy Rose17a38e22011-09-02 05:55:19 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core,deadcode.DeadStores -analyzer-store=region -analyzer-constraints=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core,deadcode.DeadStores -analyzer-store=region -analyzer-constraints=range -verify %s
Ted Kremenek553cf182008-06-25 21:21:56 +00003
4// These declarations were reduced using Delta-Debugging from Foundation.h
5// on Mac OS X. The test cases are below.
6
7typedef struct objc_selector *SEL;
8typedef signed char BOOL;
9typedef 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
20typedef float CGFloat;
21typedef struct _NSPoint {} NSRect;
22NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h);
23enum { NSBackingStoreRetained = 0, NSBackingStoreNonretained = 1, NSBackingStoreBuffered = 2 };
24typedef NSUInteger NSBackingStoreType;
25@interface NSResponder : NSObject <NSCoding> {}
26@end
27@protocol NSAnimatablePropertyContainer
28- (id)animator;
29@end
30extern 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;
35enum { 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
44extern NSString *NSWindowDidBecomeKeyNotification;
45
46// Test cases.
47
48void 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
58void 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
69void f2b() {
Ted Kremenek89e202d2009-02-23 02:51:29 +000070 // FIXME: NSWindow doesn't own itself until it is displayed.
71 NSWindow *window = [[NSWindow alloc] // no-warning
Ted Kremenek553cf182008-06-25 21:21:56 +000072 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 Kremenekcf118d42009-02-04 23:49:09 +000080 [window retain];
Ted Kremenek553cf182008-06-25 21:21:56 +000081}
82
83
84void f3() {
Ted Kremenek3aa7ecd2009-03-04 23:30:42 +000085 // FIXME: For now we don't track NSWindow.
86 NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}}
Ted Kremenek553cf182008-06-25 21:21:56 +000087}