1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core,deadcode.DeadStores -analyzer-store=region -analyzer-constraints=range -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc// These declarations were reduced using Delta-Debugging from Foundation.h 4*f4a2713aSLionel Sambuc// on Mac OS X. The test cases are below. 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuctypedef struct objc_selector *SEL; 7*f4a2713aSLionel Sambuctypedef signed char BOOL; 8*f4a2713aSLionel Sambuctypedef unsigned int NSUInteger; 9*f4a2713aSLionel Sambuc@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 10*f4a2713aSLionel Sambuc@protocol NSObject 11*f4a2713aSLionel Sambuc- (BOOL)isEqual:(id)object; 12*f4a2713aSLionel Sambuc- (id)retain; 13*f4a2713aSLionel Sambuc@end 14*f4a2713aSLionel Sambuc@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; 15*f4a2713aSLionel Sambuc@end 16*f4a2713aSLionel Sambuc@interface NSObject <NSObject> {} 17*f4a2713aSLionel Sambuc + (id)alloc; 18*f4a2713aSLionel Sambuc@end 19*f4a2713aSLionel Sambuctypedef float CGFloat; 20*f4a2713aSLionel Sambuctypedef struct _NSPoint {} NSRect; 21*f4a2713aSLionel SambucNSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h); 22*f4a2713aSLionel Sambucenum { NSBackingStoreRetained = 0, NSBackingStoreNonretained = 1, NSBackingStoreBuffered = 2 }; 23*f4a2713aSLionel Sambuctypedef NSUInteger NSBackingStoreType; 24*f4a2713aSLionel Sambuc@interface NSResponder : NSObject <NSCoding> {} 25*f4a2713aSLionel Sambuc@end 26*f4a2713aSLionel Sambuc@protocol NSAnimatablePropertyContainer 27*f4a2713aSLionel Sambuc- (id)animator; 28*f4a2713aSLionel Sambuc@end 29*f4a2713aSLionel Sambucextern NSString *NSAnimationTriggerOrderIn ; 30*f4a2713aSLionel Sambuc@class CIFilter, CALayer, NSDictionary, NSScreen, NSShadow, NSTrackingArea; 31*f4a2713aSLionel Sambuc@interface NSView : NSResponder <NSAnimatablePropertyContainer> {} @end 32*f4a2713aSLionel Sambuc@protocol NSValidatedUserInterfaceItem - (SEL)action; @end 33*f4a2713aSLionel Sambuc@protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem; @end @class NSNotification, NSText, NSView, NSMutableSet, NSSet, NSDate; 34*f4a2713aSLionel Sambucenum { NSBorderlessWindowMask = 0, NSTitledWindowMask = 1 << 0, NSClosableWindowMask = 1 << 1, NSMiniaturizableWindowMask = 1 << 2, NSResizableWindowMask = 1 << 3 }; 35*f4a2713aSLionel Sambuc@interface NSWindow : NSResponder <NSAnimatablePropertyContainer, NSUserInterfaceValidations> { 36*f4a2713aSLionel Sambuc struct __wFlags {} _wFlags; 37*f4a2713aSLionel Sambuc} 38*f4a2713aSLionel Sambuc- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag; 39*f4a2713aSLionel Sambuc- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag screen:(NSScreen *)screen; 40*f4a2713aSLionel Sambuc- (void)orderFrontRegardless; 41*f4a2713aSLionel Sambuc@end 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambucextern NSString *NSWindowDidBecomeKeyNotification; 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc// Test cases. 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambucvoid f1() { 48*f4a2713aSLionel Sambuc NSWindow *window = [[NSWindow alloc] 49*f4a2713aSLionel Sambuc initWithContentRect:NSMakeRect(0,0,100,100) 50*f4a2713aSLionel Sambuc styleMask:NSTitledWindowMask|NSClosableWindowMask 51*f4a2713aSLionel Sambuc backing:NSBackingStoreBuffered 52*f4a2713aSLionel Sambuc defer:0]; 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc [window orderFrontRegardless]; // no-warning 55*f4a2713aSLionel Sambuc} 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambucvoid f2() { 58*f4a2713aSLionel Sambuc NSWindow *window = [[NSWindow alloc] 59*f4a2713aSLionel Sambuc initWithContentRect:NSMakeRect(0,0,100,100) 60*f4a2713aSLionel Sambuc styleMask:NSTitledWindowMask|NSClosableWindowMask 61*f4a2713aSLionel Sambuc backing:NSBackingStoreBuffered 62*f4a2713aSLionel Sambuc defer:0 63*f4a2713aSLionel Sambuc screen:0]; 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc [window orderFrontRegardless]; // no-warning 66*f4a2713aSLionel Sambuc} 67*f4a2713aSLionel Sambuc 68*f4a2713aSLionel Sambucvoid f2b() { 69*f4a2713aSLionel Sambuc // FIXME: NSWindow doesn't own itself until it is displayed. 70*f4a2713aSLionel Sambuc NSWindow *window = [[NSWindow alloc] // no-warning 71*f4a2713aSLionel Sambuc initWithContentRect:NSMakeRect(0,0,100,100) 72*f4a2713aSLionel Sambuc styleMask:NSTitledWindowMask|NSClosableWindowMask 73*f4a2713aSLionel Sambuc backing:NSBackingStoreBuffered 74*f4a2713aSLionel Sambuc defer:0 75*f4a2713aSLionel Sambuc screen:0]; 76*f4a2713aSLionel Sambuc 77*f4a2713aSLionel Sambuc [window orderFrontRegardless]; 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc [window retain]; 80*f4a2713aSLionel Sambuc} 81*f4a2713aSLionel Sambuc 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambucvoid f3() { 84*f4a2713aSLionel Sambuc // FIXME: For now we don't track NSWindow. 85*f4a2713aSLionel Sambuc NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}} 86*f4a2713aSLionel Sambuc} 87