blob: bcb6c41abab20fc01acd400531362737879a9734 [file] [log] [blame]
Ted Kremenekf536ca32009-01-22 18:54:47 +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-region -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() {
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
83void f3() {
84 NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}} expected-warning{{leak}}
85}