Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.NonNilReturnValue,debug.ExprInspection -verify %s
      2 
      3 typedef unsigned int NSUInteger;
      4 typedef signed char BOOL;
      5 
      6 @protocol NSObject  - (BOOL)isEqual:(id)object; @end
      7 
      8 @interface NSObject <NSObject> {}
      9 +(id)alloc;
     10 +(id)new;
     11 -(id)init;
     12 -(id)autorelease;
     13 -(id)copy;
     14 - (Class)class;
     15 -(id)retain;
     16 @end
     17 
     18 @interface NSArray : NSObject
     19 - (id)objectAtIndex:(unsigned long)index;
     20 @end
     21 
     22 @interface NSArray (NSExtendedArray)
     23 - (id)objectAtIndexedSubscript:(NSUInteger)idx;
     24 @end
     25 
     26 @interface NSMutableArray : NSArray
     27 - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
     28 @end
     29 
     30 @interface NSOrderedSet : NSObject
     31 @end
     32 @interface NSOrderedSet (NSOrderedSetCreation)
     33 - (id)objectAtIndexedSubscript:(NSUInteger)idx;
     34 @end
     35 
     36 void clang_analyzer_eval(id);
     37 
     38 void assumeThatNSArrayObjectAtIndexIsNeverNull(NSArray *A, NSUInteger i) {
     39   clang_analyzer_eval([A objectAtIndex: i]); // expected-warning {{TRUE}} 
     40   id subscriptObj = A[1];
     41   clang_analyzer_eval(subscriptObj); // expected-warning {{TRUE}} 
     42 }
     43 
     44 void assumeThatNSMutableArrayObjectAtIndexIsNeverNull(NSMutableArray *A, NSUInteger i) {
     45   clang_analyzer_eval([A objectAtIndex: i]); // expected-warning {{TRUE}} 
     46 }
     47 
     48 void assumeThatNSArrayObjectAtIndexedSubscriptIsNeverNull(NSOrderedSet *A, NSUInteger i) {
     49   clang_analyzer_eval(A[i]); // expected-warning {{TRUE}}
     50 }