blob: ef8bff5c8d4a184d9875ce2ee65a1d3192a622de [file] [log] [blame]
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001// 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 Kremenek553cf182008-06-25 21:21:56 +00004
5// These declarations were reduced using Delta-Debugging from Foundation.h
6// on Mac OS X. The test cases are below.
7
8typedef struct objc_selector *SEL;
9typedef signed char BOOL;
10typedef 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
21typedef float CGFloat;
22typedef struct _NSPoint {} NSRect;
23NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h);
24enum { NSBackingStoreRetained = 0, NSBackingStoreNonretained = 1, NSBackingStoreBuffered = 2 };
25typedef NSUInteger NSBackingStoreType;
26@interface NSResponder : NSObject <NSCoding> {}
27@end
28@protocol NSAnimatablePropertyContainer
29- (id)animator;
30@end
31extern 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;
36enum { 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
45extern NSString *NSWindowDidBecomeKeyNotification;
46
47// Test cases.
48
49void 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
59void 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
70void f2b() {
Ted Kremenekcf118d42009-02-04 23:49:09 +000071 NSWindow *window = [[NSWindow alloc] // expected-warning{{leak}}
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() {
85 NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}} expected-warning{{leak}}
86}