NSWindow.m revision 033a07e5fca459ed184369cfee7c90d82367a93a
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-checker=deadcode.DeadStores -analyzer-store=region -analyzer-constraints=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-checker=deadcode.DeadStores -analyzer-store=region -analyzer-constraints=range -verify %s
3
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() {
70  // FIXME: NSWindow doesn't own itself until it is displayed.
71  NSWindow *window = [[NSWindow alloc] // no-warning
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  
80  [window retain];
81}
82
83
84void f3() {
85  // FIXME: For now we don't track NSWindow.
86  NSWindow *window = [NSWindow alloc];  // expected-warning{{never read}}
87}
88