blob: ff3ecef72d8d767e71b6232fcbac70bfa9bf8e46 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -emit-llvm -o %t %s
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00002// RUN: grep -F '@objc_assign_global' %t | count 26
Fariborz Jahanianb123ea32009-09-16 21:37:16 +00003
4@class NSObject;
5typedef const struct __CFDictionary * CFDictionaryRef;
6typedef struct {
7 id element;
8 id elementArray[10];
9 __strong CFDictionaryRef cfElement;
10 __strong CFDictionaryRef cfElementArray[10];
11} struct_with_ids_t;
12
13
14// assignments to these should generate objc_assign_global
15@interface A
16@end
17
18typedef struct s0 {
19 A *a[4];
20} T;
21
22T g0;
23
24extern id FileExternID;
25static id FileStaticID;
26id GlobalId;
27id GlobalArray[20];
28NSObject *GlobalObject;
29NSObject *GlobalObjectArray[20];
30__strong CFDictionaryRef Gdict;
31__strong CFDictionaryRef Gdictarray[10];
32struct_with_ids_t GlobalStruct;
33struct_with_ids_t GlobalStructArray[10];
34
35#define ASSIGNTEST(expr, global) expr = rhs
36void *rhs = 0;
37
Fariborz Jahanianbf63b872009-05-04 23:27:20 +000038int main() {
Fariborz Jahanianb123ea32009-09-16 21:37:16 +000039 static id staticGlobalId;
40 static id staticGlobalArray[20];
41 static NSObject *staticGlobalObject;
42 static NSObject *staticGlobalObjectArray[20];
43 static __strong CFDictionaryRef staticGdict;
44 static __strong CFDictionaryRef staticGdictarray[10];
45 static struct_with_ids_t staticGlobalStruct;
46 static struct_with_ids_t staticGlobalStructArray[10];
47 extern id ExID;
48 id localID;
49
50 ASSIGNTEST(GlobalId, GlobalAssigns); // objc_assign_global
51 ASSIGNTEST(GlobalArray[0], GlobalAssigns); // objc_assign_global
52 ASSIGNTEST(GlobalObject, GlobalAssigns); // objc_assign_global
53 ASSIGNTEST(GlobalObjectArray[0], GlobalAssigns); // objc_assign_global
54 ASSIGNTEST(Gdict, GlobalAssigns); // objc_assign_global
55 ASSIGNTEST(Gdictarray[1], GlobalAssigns); // objc_assign_global
56
57 ASSIGNTEST(GlobalStruct.element, GlobalAssigns); // objc_assign_global
58 ASSIGNTEST(GlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
59 ASSIGNTEST(GlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
60 ASSIGNTEST(GlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
61
62 ASSIGNTEST(staticGlobalId, GlobalAssigns); // objc_assign_global
63 ASSIGNTEST(staticGlobalArray[0], GlobalAssigns); // objc_assign_global
64 ASSIGNTEST(staticGlobalObject, GlobalAssigns); // objc_assign_global
65 ASSIGNTEST(staticGlobalObjectArray[0], GlobalAssigns); // objc_assign_global
66 ASSIGNTEST(staticGdict, GlobalAssigns); // objc_assign_global
67 ASSIGNTEST(staticGdictarray[1], GlobalAssigns); // objc_assign_global
68
69 ASSIGNTEST(staticGlobalStruct.element, GlobalAssigns); // objc_assign_global
70 ASSIGNTEST(staticGlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
71 ASSIGNTEST(staticGlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
72 ASSIGNTEST(staticGlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
73
74 ExID = 0;
75 localID = 0;
76 FileStaticID = 0;
77 FileExternID=0;
78 g0.a[0] = 0;
79 ((T*) &g0)->a[0] = 0;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +000080}