Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core,deadcode.DeadStores -analyzer-store=region -analyzer-constraints=basic -verify %s
      2 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core,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 
      7 typedef struct objc_selector *SEL;
      8 typedef signed char BOOL;
      9 typedef 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
     20 typedef float CGFloat;
     21 typedef struct _NSPoint {} NSRect;
     22 NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h);
     23 enum { NSBackingStoreRetained = 0,     NSBackingStoreNonretained = 1,     NSBackingStoreBuffered = 2 };
     24 typedef NSUInteger NSBackingStoreType;
     25 @interface NSResponder : NSObject <NSCoding> {}
     26 @end
     27 @protocol NSAnimatablePropertyContainer
     28 - (id)animator;
     29 @end
     30 extern 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;
     35 enum { 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 
     44 extern NSString *NSWindowDidBecomeKeyNotification;
     45 
     46 // Test cases.
     47 
     48 void 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 
     58 void 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 
     69 void 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 
     84 void f3() {
     85   // FIXME: For now we don't track NSWindow.
     86   NSWindow *window = [NSWindow alloc];  // expected-warning{{never read}}
     87 }
     88