Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.ObjCGenerics -verify %s
      2 
      3 #if !__has_feature(objc_generics)
      4 #  error Compiler does not support Objective-C generics?
      5 #endif
      6 
      7 #define nil 0
      8 typedef unsigned long NSUInteger;
      9 typedef int BOOL;
     10 
     11 @protocol NSCopying
     12 @end
     13 
     14 __attribute__((objc_root_class))
     15 @interface NSObject
     16 - (void) myFunction:(int*)p myParam:(int) n;
     17 @end
     18 
     19 @interface MyType : NSObject <NSCopying>
     20 - (void) myFunction:(int*)p myParam:(int) n;
     21 @end
     22 
     23 @interface NSArray<ObjectType> : NSObject
     24 - (BOOL)contains:(ObjectType)obj;
     25 - (ObjectType)getObjAtIndex:(NSUInteger)idx;
     26 - (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx;
     27 @property(readonly) ObjectType firstObject;
     28 @end
     29 
     30 @implementation NSObject
     31 - (void) myFunction:(int*)p myParam:(int) n {
     32   (void)*p;// no warning
     33 }
     34 @end
     35 
     36 @implementation MyType
     37 - (void) myFunction:(int*)p myParam:(int) n {
     38   int i = 5/n;  // expected-warning {{}}
     39   (void)i;
     40 }
     41 @end
     42 
     43 void testReturnType(NSArray<MyType *> *arr) {
     44   NSArray *erased = arr;
     45   NSObject *element = [erased firstObject];
     46   // TODO: myFunction currently dispatches to NSObject. Make it dispatch to
     47   // MyType instead!
     48   [element myFunction:0 myParam:0 ];
     49 }
     50 
     51 void testArgument(NSArray<MyType *> *arr, id element) {
     52   NSArray *erased = arr;
     53   [erased contains: element];
     54   // TODO: myFunction currently is not dispatched to MyType. Make it dispatch to
     55   // MyType!
     56   [element myFunction:0 myParam:0 ];
     57 }
     58