2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -emit-llvm -o %t %s
|
2009-11-08 09:45:36 +08:00
|
|
|
// RUN: grep -F '@objc_assign_global' %t | count 21
|
|
|
|
// RUN: grep -F '@objc_assign_ivar' %t | count 11
|
2010-05-21 02:22:28 +08:00
|
|
|
// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fobjc-gc -emit-llvm -o %t %s
|
|
|
|
// RUN: grep -F '@objc_assign_global' %t | count 21
|
|
|
|
// RUN: grep -F '@objc_assign_ivar' %t | count 11
|
2009-09-17 07:30:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
typedef const struct __CFDictionary * CFDictionaryRef;
|
|
|
|
|
|
|
|
// callouts to these are generated with cc -fobjc-gc
|
|
|
|
|
|
|
|
int GlobalAssigns;
|
|
|
|
int IvarAssigns;
|
|
|
|
int StrongCastAssigns;
|
|
|
|
|
|
|
|
|
|
|
|
// The test case elements;
|
|
|
|
@class NSObject;
|
|
|
|
@class NSString;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
id element;
|
|
|
|
id elementArray[10];
|
|
|
|
__strong CFDictionaryRef cfElement;
|
|
|
|
__strong CFDictionaryRef cfElementArray[10];
|
|
|
|
} struct_with_ids_t;
|
|
|
|
|
|
|
|
@interface Foo {
|
|
|
|
@public
|
|
|
|
// assignments to any/all of these fields should generate objc_assign_ivar
|
|
|
|
__strong CFDictionaryRef dict;
|
|
|
|
__strong CFDictionaryRef dictArray[3];
|
|
|
|
id ivar;
|
|
|
|
id array[10];
|
|
|
|
NSObject *nsobject;
|
|
|
|
NSString *stringArray[10];
|
|
|
|
struct_with_ids_t inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// assignments to these should generate objc_assign_global
|
|
|
|
id GlobalId;
|
|
|
|
id GlobalArray[20];
|
|
|
|
NSObject *GlobalObject;
|
|
|
|
NSObject *GlobalObjectArray[20];
|
|
|
|
__strong CFDictionaryRef Gdict;
|
|
|
|
__strong CFDictionaryRef Gdictarray[10];
|
|
|
|
struct_with_ids_t GlobalStruct;
|
|
|
|
struct_with_ids_t GlobalStructArray[10];
|
|
|
|
|
|
|
|
|
|
|
|
// The test cases
|
2010-05-21 02:22:28 +08:00
|
|
|
void* rhs = 0;
|
2009-09-17 07:30:59 +08:00
|
|
|
|
2010-05-21 02:22:28 +08:00
|
|
|
#define ASSIGNTEST(expr, global) expr = (typeof(expr))rhs
|
2009-09-17 07:30:59 +08:00
|
|
|
|
|
|
|
int testGlobals() {
|
|
|
|
// Everything in this function generates assign_global intercepts
|
|
|
|
int counter = 0;
|
|
|
|
|
|
|
|
static id staticGlobalId;
|
|
|
|
static id staticGlobalArray[20];
|
|
|
|
static NSObject *staticGlobalObject;
|
|
|
|
static NSObject *staticGlobalObjectArray[20];
|
|
|
|
static __strong CFDictionaryRef staticGdict;
|
|
|
|
static __strong CFDictionaryRef staticGdictarray[10];
|
|
|
|
static struct_with_ids_t staticGlobalStruct;
|
|
|
|
static struct_with_ids_t staticGlobalStructArray[10];
|
|
|
|
|
|
|
|
ASSIGNTEST(GlobalId, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalObject, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalObjectArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(Gdict, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(Gdictarray[1], GlobalAssigns); // objc_assign_global
|
|
|
|
|
|
|
|
ASSIGNTEST(GlobalStruct.element, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(GlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
|
|
|
|
ASSIGNTEST(staticGlobalId, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalObject, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalObjectArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGdict, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGdictarray[1], GlobalAssigns); // objc_assign_global
|
|
|
|
|
|
|
|
ASSIGNTEST(staticGlobalStruct.element, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalStruct.elementArray[0], GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalStruct.cfElement, GlobalAssigns); // objc_assign_global
|
|
|
|
ASSIGNTEST(staticGlobalStruct.cfElementArray[0], GlobalAssigns); // objc_assign_global
|
2009-09-17 15:21:40 +08:00
|
|
|
|
2009-09-17 07:30:59 +08:00
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int testIvars() {
|
|
|
|
Foo *foo;
|
|
|
|
int counter = 0;
|
|
|
|
|
|
|
|
ASSIGNTEST(foo->ivar, IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->dict, IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->dictArray[0], IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->array[0], IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->nsobject, IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->stringArray[0], IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->inner.element, IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->inner.elementArray[0], IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->inner.cfElement, IvarAssigns); // objc_assign_ivar
|
|
|
|
ASSIGNTEST(foo->inner.cfElementArray[0], IvarAssigns); // objc_assign_ivar
|
|
|
|
|
|
|
|
return counter;
|
|
|
|
}
|