Home | History | Annotate | Download | only in CodeGenObjC
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -fobjc-gc -emit-llvm -o %t %s
      2 // RUN: grep -F '@objc_assign_ivar' %t  | count 14
      3 
      4 typedef struct {
      5   id  element;
      6   id elementArray[10];
      7   __strong id cfElement;
      8   __strong id cfElementArray[10];
      9 } struct_with_ids_t;
     10 
     11 
     12 @interface NSString @end
     13 
     14 @interface Foo  {
     15 @public
     16 // assignments to any/all of these fields should generate objc_assign_ivar
     17   __strong id dict;
     18   __strong id dictArray[3];
     19   id ivar;
     20   id array[10];
     21   id nsobject;
     22   NSString *stringArray[10];
     23   struct_with_ids_t inner;
     24 
     25   Foo *obj[20];
     26   short idx[5];
     27 }
     28 @end
     29 
     30 // The test cases
     31 int IvarAssigns;
     32 void *rhs = 0;
     33 #define ASSIGNTEST(expr, global) expr = rhs
     34 
     35 void testIvars() {
     36   Foo *foo;
     37   ASSIGNTEST(foo->ivar, IvarAssigns);                                   // objc_assign_ivar
     38   ASSIGNTEST(foo->dict, IvarAssigns);                                   // objc_assign_ivar
     39   ASSIGNTEST(foo->dictArray[0], IvarAssigns);                           // objc_assign_ivar
     40   ASSIGNTEST(foo->array[0], IvarAssigns);                               // objc_assign_ivar
     41   ASSIGNTEST(foo->nsobject, IvarAssigns);                               // objc_assign_ivar
     42   ASSIGNTEST(foo->stringArray[0], IvarAssigns);                         // objc_assign_ivar
     43   ASSIGNTEST(foo->inner.element, IvarAssigns);                          // objc_assign_ivar
     44   ASSIGNTEST(foo->inner.elementArray[0], IvarAssigns);                  // objc_assign_ivar
     45   ASSIGNTEST(foo->inner.cfElement, IvarAssigns);                        // objc_assign_ivar
     46   ASSIGNTEST(foo->inner.cfElementArray[0], IvarAssigns);                // objc_assign_ivar
     47   int counter=1;
     48   ASSIGNTEST(foo->obj[5], IvarAssigns);                 // objc_assign_ivar
     49   ASSIGNTEST(foo->obj[++counter], IvarAssigns);         // objc_assign_ivar
     50   foo->idx[++counter] = 15;
     51   ASSIGNTEST(foo->obj[foo->idx[2]], IvarAssigns);       // objc_assign_ivar
     52 }
     53