1 /* Check if 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>. */
8 /* { dg-options "-Wpadded -Wabi" } */
10 /* Leave blank lines here to keep warnings on the same lines. */
12 #include "../objc-obj-c++-shared/TestsuiteObject.m"
13 #include <objc/objc.h>
16 #define CHECK_IF(expr) if(!(expr)) abort()
18 enum Enum { zero, one, two, three, four };
20 @interface Base: TestsuiteObject {
26 } /* { dg-warning "padding struct size to alignment boundary" } */
29 struct Base_0 { /* { dg-warning "padding struct size to alignment boundary" } */
37 @interface Derived: Base {
56 @interface Leaf: Derived {
74 /* Note that the semicolon after @defs(...) is optional. */
76 typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */
77 typedef struct { @defs(Derived); } Derived_t;
78 typedef struct { @defs(Leaf); } Leaf_t;
83 Leaf *l = (Leaf *)&l_0;
84 Leaf_t *l_t = (Leaf_t *)&l_0;
86 CHECK_IF(sizeof(Base_t) == sizeof(Base));
87 CHECK_IF(sizeof(Derived_t) == sizeof(Derived));
88 CHECK_IF(sizeof(Leaf_t) == sizeof(Leaf));
90 CHECK_IF(sizeof(struct Base_0) == sizeof(Base));
91 CHECK_IF(sizeof(struct Derived_0) == sizeof(Derived));
92 CHECK_IF(sizeof(struct Leaf_0) == sizeof(Leaf));
105 CHECK_IF(l->a == 3 && l_t->a == 3);
106 CHECK_IF(!l->b && !l_t->b);
107 CHECK_IF(l->c == three && l_t->c == three);
108 CHECK_IF(l->d == 31 && l_t->d == 31);
109 CHECK_IF(!l->e && !l_t->e);
110 CHECK_IF(l->f == 15 && l_t->f == 15);
111 CHECK_IF(l->g == zero && l_t->g == zero);
112 CHECK_IF(l->h == -2 && l_t->h == -2);
117 /* { dg-prune-output "In file included from" } Ignore this message. */
118 /* { dg-bogus "padding struct to align" "PR23610" { target *-*-* } 0 } */
119 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 42 } */
120 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 45 } */
121 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 59 } */
122 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 62 } */
123 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 77 } */
124 /* { dg-bogus "padding struct size" "PR23610" { xfail lp64 } 78 } */