1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -fobjc-gc -emit-llvm -o %t %s 2*f4a2713aSLionel Sambuc// RUN: grep -F '@objc_assign_global' %t | count 21 3*f4a2713aSLionel Sambuc// RUN: grep -F '@objc_assign_ivar' %t | count 11 4*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc// RUN: grep -F '@objc_assign_global' %t | count 21 6*f4a2713aSLionel Sambuc// RUN: grep -F '@objc_assign_ivar' %t | count 11 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuctypedef const struct __CFDictionary * CFDictionaryRef; 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc// callouts to these are generated with cc -fobjc-gc 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambucint GlobalAssigns; 14*f4a2713aSLionel Sambucint IvarAssigns; 15*f4a2713aSLionel Sambucint StrongCastAssigns; 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc// The test case elements; 19*f4a2713aSLionel Sambuc@class NSObject; 20*f4a2713aSLionel Sambuc@class NSString; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuctypedef struct { 23*f4a2713aSLionel Sambuc id element; 24*f4a2713aSLionel Sambuc id elementArray[10]; 25*f4a2713aSLionel Sambuc __strong CFDictionaryRef cfElement; 26*f4a2713aSLionel Sambuc __strong CFDictionaryRef cfElementArray[10]; 27*f4a2713aSLionel Sambuc} struct_with_ids_t; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc@interface Foo { 30*f4a2713aSLionel Sambuc@public 31*f4a2713aSLionel Sambuc// assignments to any/all of these fields should generate objc_assign_ivar 32*f4a2713aSLionel Sambuc __strong CFDictionaryRef dict; 33*f4a2713aSLionel Sambuc __strong CFDictionaryRef dictArray[3]; 34*f4a2713aSLionel Sambuc id ivar; 35*f4a2713aSLionel Sambuc id array[10]; 36*f4a2713aSLionel Sambuc NSObject *nsobject; 37*f4a2713aSLionel Sambuc NSString *stringArray[10]; 38*f4a2713aSLionel Sambuc struct_with_ids_t inner; 39*f4a2713aSLionel Sambuc} 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc@end 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc// assignments to these should generate objc_assign_global 44*f4a2713aSLionel Sambucid GlobalId; 45*f4a2713aSLionel Sambucid GlobalArray[20]; 46*f4a2713aSLionel SambucNSObject *GlobalObject; 47*f4a2713aSLionel SambucNSObject *GlobalObjectArray[20]; 48*f4a2713aSLionel Sambuc__strong CFDictionaryRef Gdict; 49*f4a2713aSLionel Sambuc__strong CFDictionaryRef Gdictarray[10]; 50*f4a2713aSLionel Sambucstruct_with_ids_t GlobalStruct; 51*f4a2713aSLionel Sambucstruct_with_ids_t GlobalStructArray[10]; 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc// The test cases 55*f4a2713aSLionel Sambucvoid* rhs = 0; 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc#define ASSIGNTEST(expr, global) expr = (typeof(expr))rhs 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambucint testGlobals() { 60*f4a2713aSLionel Sambuc // Everything in this function generates assign_global intercepts 61*f4a2713aSLionel Sambuc int counter = 0; 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc static id staticGlobalId; 64*f4a2713aSLionel Sambuc static id staticGlobalArray[20]; 65*f4a2713aSLionel Sambuc static NSObject *staticGlobalObject; 66*f4a2713aSLionel Sambuc static NSObject *staticGlobalObjectArray[20]; 67*f4a2713aSLionel Sambuc static __strong CFDictionaryRef staticGdict; 68*f4a2713aSLionel Sambuc static __strong CFDictionaryRef staticGdictarray[10]; 69*f4a2713aSLionel Sambuc static struct_with_ids_t staticGlobalStruct; 70*f4a2713aSLionel Sambuc static struct_with_ids_t staticGlobalStructArray[10]; 71*f4a2713aSLionel Sambuc 72*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalId, GlobalAssigns); // objc_assign_global 73*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalArray[0], GlobalAssigns); // objc_assign_global 74*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalObject, GlobalAssigns); // objc_assign_global 75*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalObjectArray[0], GlobalAssigns); // objc_assign_global 76*f4a2713aSLionel Sambuc ASSIGNTEST(Gdict, GlobalAssigns); // objc_assign_global 77*f4a2713aSLionel Sambuc ASSIGNTEST(Gdictarray[1], GlobalAssigns); // objc_assign_global 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalStruct.element, GlobalAssigns); // objc_assign_global 80*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global 81*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalStruct.cfElement, GlobalAssigns); // objc_assign_global 82*f4a2713aSLionel Sambuc ASSIGNTEST(GlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalId, GlobalAssigns); // objc_assign_global 85*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalArray[0], GlobalAssigns); // objc_assign_global 86*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalObject, GlobalAssigns); // objc_assign_global 87*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalObjectArray[0], GlobalAssigns); // objc_assign_global 88*f4a2713aSLionel Sambuc ASSIGNTEST(staticGdict, GlobalAssigns); // objc_assign_global 89*f4a2713aSLionel Sambuc ASSIGNTEST(staticGdictarray[1], GlobalAssigns); // objc_assign_global 90*f4a2713aSLionel Sambuc 91*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalStruct.element, GlobalAssigns); // objc_assign_global 92*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global 93*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalStruct.cfElement, GlobalAssigns); // objc_assign_global 94*f4a2713aSLionel Sambuc ASSIGNTEST(staticGlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc return counter; 97*f4a2713aSLionel Sambuc} 98*f4a2713aSLionel Sambuc 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambucint testIvars() { 101*f4a2713aSLionel Sambuc Foo *foo; 102*f4a2713aSLionel Sambuc int counter = 0; 103*f4a2713aSLionel Sambuc 104*f4a2713aSLionel Sambuc ASSIGNTEST(foo->ivar, IvarAssigns); // objc_assign_ivar 105*f4a2713aSLionel Sambuc ASSIGNTEST(foo->dict, IvarAssigns); // objc_assign_ivar 106*f4a2713aSLionel Sambuc ASSIGNTEST(foo->dictArray[0], IvarAssigns); // objc_assign_ivar 107*f4a2713aSLionel Sambuc ASSIGNTEST(foo->array[0], IvarAssigns); // objc_assign_ivar 108*f4a2713aSLionel Sambuc ASSIGNTEST(foo->nsobject, IvarAssigns); // objc_assign_ivar 109*f4a2713aSLionel Sambuc ASSIGNTEST(foo->stringArray[0], IvarAssigns); // objc_assign_ivar 110*f4a2713aSLionel Sambuc ASSIGNTEST(foo->inner.element, IvarAssigns); // objc_assign_ivar 111*f4a2713aSLionel Sambuc ASSIGNTEST(foo->inner.elementArray[0], IvarAssigns); // objc_assign_ivar 112*f4a2713aSLionel Sambuc ASSIGNTEST(foo->inner.cfElement, IvarAssigns); // objc_assign_ivar 113*f4a2713aSLionel Sambuc ASSIGNTEST(foo->inner.cfElementArray[0], IvarAssigns); // objc_assign_ivar 114*f4a2713aSLionel Sambuc 115*f4a2713aSLionel Sambuc return counter; 116*f4a2713aSLionel Sambuc} 117