| 1 |
/* Encoding tests for ObjC class layouts. */ |
| 2 |
/* Contributed by Ziemowit Laski <[email protected]>. */ |
| 3 |
/* { dg-options "" } */ |
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 6 |
|
| 7 |
#include "../objc-obj-c++-shared/TestsuiteObject.m" |
| 8 |
#include "../objc-obj-c++-shared/runtime.h" |
| 9 |
|
| 10 |
extern void abort(void); |
| 11 |
extern int strcmp(const char *s1, const char *s2); |
| 12 |
|
| 13 |
#define CHECK_IF(expr) if(!(expr)) abort() |
| 14 |
|
| 15 |
@class Int1, Int2; |
| 16 |
struct Nested; |
| 17 |
|
| 18 |
struct Innermost { |
| 19 |
unsigned char a, b; |
| 20 |
struct Nested *encl; |
| 21 |
}; |
| 22 |
|
| 23 |
struct Nested { |
| 24 |
float a, b; |
| 25 |
Int1 *next; |
| 26 |
struct Innermost innermost; |
| 27 |
}; |
| 28 |
|
| 29 |
@interface Int1: TestsuiteObject { |
| 30 |
signed char a, b; |
| 31 |
Int2 *int2; |
| 32 |
struct Nested nested; |
| 33 |
} |
| 34 |
@end |
| 35 |
|
| 36 |
@interface Int2: Int1 { |
| 37 |
struct Innermost *innermost; |
| 38 |
Int1 *base; |
| 39 |
} |
| 40 |
@end |
| 41 |
|
| 42 |
@implementation Int1 |
| 43 |
@end |
| 44 |
|
| 45 |
@implementation Int2 |
| 46 |
@end |
| 47 |
|
| 48 |
#if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE) |
| 49 |
struct objc_ivar *ivar; |
| 50 |
#else |
| 51 |
Ivar *ivar; |
| 52 |
#endif |
| 53 |
|
| 54 |
static void check_ivar(const char *name, const char *type) { |
| 55 |
#if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE) |
| 56 |
CHECK_IF(!strcmp(ivar->ivar_name, name)); |
| 57 |
CHECK_IF(!strcmp(ivar->ivar_type, type)); |
| 58 |
#else |
| 59 |
CHECK_IF(!strcmp(ivar_getName(*ivar), name)); |
| 60 |
CHECK_IF(!strcmp(ivar_getTypeEncoding(*ivar), type)); |
| 61 |
#endif |
| 62 |
ivar++; |
| 63 |
} |
| 64 |
|
| 65 |
int main(void) { |
| 66 |
#if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE) |
| 67 |
ivar = ((Class)objc_getClass("Int1"))->ivars->ivar_list; |
| 68 |
#else |
| 69 |
ivar = class_copyIvarList ((Class)objc_getClass("Int1"), NULL); |
| 70 |
#endif |
| 71 |
check_ivar("a", "c"); |
| 72 |
check_ivar("b", "c"); |
| 73 |
check_ivar("int2", "@\"Int2\""); |
| 74 |
check_ivar("nested", |
| 75 |
"{Nested=\"a\"f\"b\"f\"next\"@\"Int1\"\"innermost\"{Innermost=\"a\"C\"b\"C\"encl\"^{Nested}}}"); |
| 76 |
|
| 77 |
#if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE) |
| 78 |
ivar = ((Class)objc_getClass("Int2"))->ivars->ivar_list; |
| 79 |
#else |
| 80 |
ivar = class_copyIvarList ((Class)objc_getClass("Int2"), NULL); |
| 81 |
#endif |
| 82 |
check_ivar("innermost", "^{Innermost=CC^{Nested}}"); |
| 83 |
check_ivar("base", "@\"Int1\""); |
| 84 |
|
| 85 |
return 0; |
| 86 |
} |
| 87 |
|