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_global' %t | count 21
3 // RUN: grep -F '@objc_assign_ivar' %t | count 11
4 // RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -fobjc-gc -emit-llvm -o %t %s
5 // RUN: grep -F '@objc_assign_global' %t | count 21
6 // RUN: grep -F '@objc_assign_ivar' %t | count 11
9 typedef const struct __CFDictionary * CFDictionaryRef;
11 // callouts to these are generated with cc -fobjc-gc
15 int StrongCastAssigns;
18 // The test case elements;
25 __strong CFDictionaryRef cfElement;
26 __strong CFDictionaryRef cfElementArray[10];
31 // assignments to any/all of these fields should generate objc_assign_ivar
32 __strong CFDictionaryRef dict;
33 __strong CFDictionaryRef dictArray[3];
37 NSString *stringArray[10];
38 struct_with_ids_t inner;
43 // assignments to these should generate objc_assign_global
46 NSObject *GlobalObject;
47 NSObject *GlobalObjectArray[20];
48 __strong CFDictionaryRef Gdict;
49 __strong CFDictionaryRef Gdictarray[10];
50 struct_with_ids_t GlobalStruct;
51 struct_with_ids_t GlobalStructArray[10];
57 #define ASSIGNTEST(expr, global) expr = (typeof(expr))rhs
59 int testGlobals(void) {
60 // Everything in this function generates assign_global intercepts
63 static id staticGlobalId;
64 static id staticGlobalArray[20];
65 static NSObject *staticGlobalObject;
66 static NSObject *staticGlobalObjectArray[20];
67 static __strong CFDictionaryRef staticGdict;
68 static __strong CFDictionaryRef staticGdictarray[10];
69 static struct_with_ids_t staticGlobalStruct;
70 static struct_with_ids_t staticGlobalStructArray[10];
72 ASSIGNTEST(GlobalId, GlobalAssigns); // objc_assign_global
73 ASSIGNTEST(GlobalArray[0], GlobalAssigns); // objc_assign_global
74 ASSIGNTEST(GlobalObject, GlobalAssigns); // objc_assign_global
75 ASSIGNTEST(GlobalObjectArray[0], GlobalAssigns); // objc_assign_global
76 ASSIGNTEST(Gdict, GlobalAssigns); // objc_assign_global
77 ASSIGNTEST(Gdictarray[1], GlobalAssigns); // objc_assign_global
79 ASSIGNTEST(GlobalStruct.element, GlobalAssigns); // objc_assign_global
80 ASSIGNTEST(GlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
81 ASSIGNTEST(GlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
82 ASSIGNTEST(GlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
84 ASSIGNTEST(staticGlobalId, GlobalAssigns); // objc_assign_global
85 ASSIGNTEST(staticGlobalArray[0], GlobalAssigns); // objc_assign_global
86 ASSIGNTEST(staticGlobalObject, GlobalAssigns); // objc_assign_global
87 ASSIGNTEST(staticGlobalObjectArray[0], GlobalAssigns); // objc_assign_global
88 ASSIGNTEST(staticGdict, GlobalAssigns); // objc_assign_global
89 ASSIGNTEST(staticGdictarray[1], GlobalAssigns); // objc_assign_global
91 ASSIGNTEST(staticGlobalStruct.element, GlobalAssigns); // objc_assign_global
92 ASSIGNTEST(staticGlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
93 ASSIGNTEST(staticGlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
94 ASSIGNTEST(staticGlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
100 int testIvars(void) {
104 ASSIGNTEST(foo->ivar, IvarAssigns); // objc_assign_ivar
105 ASSIGNTEST(foo->dict, IvarAssigns); // objc_assign_ivar
106 ASSIGNTEST(foo->dictArray[0], IvarAssigns); // objc_assign_ivar
107 ASSIGNTEST(foo->array[0], IvarAssigns); // objc_assign_ivar
108 ASSIGNTEST(foo->nsobject, IvarAssigns); // objc_assign_ivar
109 ASSIGNTEST(foo->stringArray[0], IvarAssigns); // objc_assign_ivar
110 ASSIGNTEST(foo->inner.element, IvarAssigns); // objc_assign_ivar
111 ASSIGNTEST(foo->inner.elementArray[0], IvarAssigns); // objc_assign_ivar
112 ASSIGNTEST(foo->inner.cfElement, IvarAssigns); // objc_assign_ivar
113 ASSIGNTEST(foo->inner.cfElementArray[0], IvarAssigns); // objc_assign_ivar