xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/objc2-assign-global.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
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 26
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@class NSObject;
5*f4a2713aSLionel Sambuctypedef const struct __CFDictionary * CFDictionaryRef;
6*f4a2713aSLionel Sambuctypedef struct {
7*f4a2713aSLionel Sambuc  id  element;
8*f4a2713aSLionel Sambuc  id elementArray[10];
9*f4a2713aSLionel Sambuc  __strong CFDictionaryRef cfElement;
10*f4a2713aSLionel Sambuc  __strong CFDictionaryRef cfElementArray[10];
11*f4a2713aSLionel Sambuc} struct_with_ids_t;
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc
14*f4a2713aSLionel Sambuc// assignments to these should generate objc_assign_global
15*f4a2713aSLionel Sambuc@interface A
16*f4a2713aSLionel Sambuc@end
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuctypedef struct s0 {
19*f4a2713aSLionel Sambuc  A *a[4];
20*f4a2713aSLionel Sambuc} T;
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel SambucT g0;
23*f4a2713aSLionel Sambuc
24*f4a2713aSLionel Sambucextern id FileExternID;
25*f4a2713aSLionel Sambucstatic id FileStaticID;
26*f4a2713aSLionel Sambucid GlobalId;
27*f4a2713aSLionel Sambucid GlobalArray[20];
28*f4a2713aSLionel SambucNSObject *GlobalObject;
29*f4a2713aSLionel SambucNSObject *GlobalObjectArray[20];
30*f4a2713aSLionel Sambuc__strong CFDictionaryRef Gdict;
31*f4a2713aSLionel Sambuc__strong CFDictionaryRef Gdictarray[10];
32*f4a2713aSLionel Sambucstruct_with_ids_t GlobalStruct;
33*f4a2713aSLionel Sambucstruct_with_ids_t GlobalStructArray[10];
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc#define ASSIGNTEST(expr, global) expr = rhs
36*f4a2713aSLionel Sambucvoid *rhs = 0;
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambucint main() {
39*f4a2713aSLionel Sambuc  static id staticGlobalId;
40*f4a2713aSLionel Sambuc  static id staticGlobalArray[20];
41*f4a2713aSLionel Sambuc  static NSObject *staticGlobalObject;
42*f4a2713aSLionel Sambuc  static NSObject *staticGlobalObjectArray[20];
43*f4a2713aSLionel Sambuc  static __strong CFDictionaryRef staticGdict;
44*f4a2713aSLionel Sambuc  static __strong CFDictionaryRef staticGdictarray[10];
45*f4a2713aSLionel Sambuc  static struct_with_ids_t staticGlobalStruct;
46*f4a2713aSLionel Sambuc  static struct_with_ids_t staticGlobalStructArray[10];
47*f4a2713aSLionel Sambuc  extern id ExID;
48*f4a2713aSLionel Sambuc  id localID;
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalId, GlobalAssigns);                          // objc_assign_global
51*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalArray[0], GlobalAssigns);                    // objc_assign_global
52*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalObject, GlobalAssigns);                      // objc_assign_global
53*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalObjectArray[0], GlobalAssigns);              // objc_assign_global
54*f4a2713aSLionel Sambuc  ASSIGNTEST(Gdict, GlobalAssigns);                             // objc_assign_global
55*f4a2713aSLionel Sambuc  ASSIGNTEST(Gdictarray[1], GlobalAssigns);                     // objc_assign_global
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalStruct.element, GlobalAssigns);              // objc_assign_global
58*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalStruct.elementArray[0], GlobalAssigns);      // objc_assign_global
59*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalStruct.cfElement, GlobalAssigns);            // objc_assign_global
60*f4a2713aSLionel Sambuc  ASSIGNTEST(GlobalStruct.cfElementArray[0], GlobalAssigns);    // objc_assign_global
61*f4a2713aSLionel Sambuc
62*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalId, GlobalAssigns);                    // objc_assign_global
63*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalArray[0], GlobalAssigns);              // objc_assign_global
64*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalObject, GlobalAssigns);                // objc_assign_global
65*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalObjectArray[0], GlobalAssigns);        // objc_assign_global
66*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGdict, GlobalAssigns);                       // objc_assign_global
67*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGdictarray[1], GlobalAssigns);               // objc_assign_global
68*f4a2713aSLionel Sambuc
69*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalStruct.element, GlobalAssigns);                // objc_assign_global
70*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalStruct.elementArray[0], GlobalAssigns);        // objc_assign_global
71*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalStruct.cfElement, GlobalAssigns);              // objc_assign_global
72*f4a2713aSLionel Sambuc  ASSIGNTEST(staticGlobalStruct.cfElementArray[0], GlobalAssigns);      // objc_assign_global
73*f4a2713aSLionel Sambuc
74*f4a2713aSLionel Sambuc  ExID = 0;
75*f4a2713aSLionel Sambuc  localID = 0;
76*f4a2713aSLionel Sambuc  FileStaticID = 0;
77*f4a2713aSLionel Sambuc  FileExternID=0;
78*f4a2713aSLionel Sambuc  g0.a[0] = 0;
79*f4a2713aSLionel Sambuc  ((T*) &g0)->a[0] = 0;
80*f4a2713aSLionel Sambuc}
81