1 /* Check ObjC class layout follows the ABI (informally)
2 set in the past. ObjC structs must be laid out as if
3 all ivars, including those inherited from superclasses,
4 were defined at once (i.e., any padding introduced for
5 superclasses should be removed). */
6 /* Contributed by Ziemowit Laski <zlaski@apple.com>. */
7 /* { dg-options "-Wpadded" } */
10 #include "../objc-obj-c++-shared/TestsuiteObject.m"
11 #include <objc/objc.h>
14 #define CHECK_IF(expr) if(!(expr)) abort()
16 enum Enum { zero, one, two, three, four };
18 @interface Base: TestsuiteObject {
24 } /* { dg-warning "padding struct size to alignment boundary" } */
33 }; /* { dg-warning "padding struct size to alignment boundary" } */
35 @interface Derived: Base {
40 } /* { dg-warning "padding struct size to alignment boundary" } */
52 }; /* { dg-warning "padding struct size to alignment boundary" } */
54 @interface Leaf: Derived {
57 } /* { dg-warning "padding struct size to alignment boundary" } */
70 }; /* { dg-warning "padding struct size to alignment boundary" } */
72 /* Note that the semicolon after @defs(...) is optional. */
74 typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */
75 typedef struct { @defs(Derived); } Derived_t; /* { dg-warning "padding struct size to alignment boundary" } */
76 typedef struct { @defs(Leaf); } Leaf_t; /* { dg-warning "padding struct size to alignment boundary" } */
81 Leaf *l = (Leaf *)&l_0;
82 Leaf_t *l_t = (Leaf_t *)&l_0;
84 CHECK_IF(sizeof(Base_t) == sizeof(Base));
85 CHECK_IF(sizeof(Derived_t) == sizeof(Derived));
86 CHECK_IF(sizeof(Leaf_t) == sizeof(Leaf));
88 CHECK_IF(sizeof(struct Base_0) == sizeof(Base));
89 CHECK_IF(sizeof(struct Derived_0) == sizeof(Derived));
90 CHECK_IF(sizeof(struct Leaf_0) == sizeof(Leaf));
103 CHECK_IF(l->a == 3 && l_t->a == 3);
104 CHECK_IF(!l->b && !l_t->b);
105 CHECK_IF(l->c == three && l_t->c == three);
106 CHECK_IF(l->d == 31 && l_t->d == 31);
107 CHECK_IF(!l->e && !l_t->e);
108 CHECK_IF(l->f == 15 && l_t->f == 15);
109 CHECK_IF(l->g == zero && l_t->g == zero);
110 CHECK_IF(l->h == -2 && l_t->h == -2);