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