Merge from mainline (157519:158021).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc / execute / bf-common.h
blob5d6ef577a9094b8e59d5288f29cbed932fe35445
1 #include <stdlib.h>
2 #include "../../objc-obj-c++-shared/next-mapping.h"
3 #ifndef __NEXT_RUNTIME__
4 #include <objc/encoding.h>
5 #endif
7 void print_ivars (Class class)
9 struct objc_ivar_list* ivars = class->ivars;
10 int i;
12 for (i = 0; i < ivars->ivar_count; i++) {
13 struct objc_ivar *ivar = &(ivars->ivar_list[i]);
14 printf ("ivar '%s', type '%s', offset %d\n",
15 ivar->ivar_name, ivar->ivar_type, ivar->ivar_offset);
19 void compare_structures (Class class, const char* type)
21 struct objc_struct_layout layout;
22 struct objc_ivar_list* ivars = class->ivars;
23 int i = 0;
24 int position;
26 objc_layout_structure (type, &layout);
28 while (objc_layout_structure_next_member (&layout))
30 struct objc_ivar *ivar;
31 const char *ivar_type;
33 if (i > ivars->ivar_count)
35 printf ("too many ivars in type %s, layout = %s\n",
36 type, layout.type);
37 exit (1);
40 ivar = &(ivars->ivar_list[i]);
41 objc_layout_structure_get_info (&layout, &position, NULL, &ivar_type);
42 printf ("real ivar '%s' offset %d\n",
43 ivar->ivar_name, ivar->ivar_offset);
44 printf ("computed type '%s' offset %d\n", ivar_type, position);
45 if (position != ivar->ivar_offset)
47 printf ("offset %d and computed position %d don't match on ivar '%s'"
48 " (i = %d)\n",
49 ivar->ivar_offset, position, ivar->ivar_name, i);
50 exit (1);
52 i++;
55 printf ("%d ivars checked\n", i);
58 int main ()
60 struct class_vars
62 @defs (MyObject);
64 int size1, size2;
65 Class class = objc_get_class ("MyObject");
67 printf ("type = %s\n", @encode (struct class_vars));
68 print_ivars (class);
70 compare_structures (class, @encode(struct class_vars));
71 if ((size1 = objc_sizeof_type (@encode(struct class_vars)))
72 != (size2 = sizeof (struct class_vars)))
74 printf ("sizes don't match (computed %d, exact %d)\n", size1, size2);
75 abort ();
78 exit (0);