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