• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-fragile-abi -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-fragile-abi -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 {
23  id  element;
24  id 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];
34  id ivar;
35  id array[10];
36  NSObject *nsobject;
37  NSString *stringArray[10];
38  struct_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() {
60  // Everything in this function generates assign_global intercepts
61  int counter = 0;
62
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];
71
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
78
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
83
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
90
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
95
96  return counter;
97}
98
99
100int testIvars() {
101  Foo *foo;
102  int counter = 0;
103
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
114
115  return counter;
116}
117