Debian Codegraph @

gcc/testsuite/objc.dg/bitfield-3.m

raw
1 /* Check if the @defs() construct preserves the correct
2 layout of bitfields. */
3 /* Contributed by Ziemowit Laski <[email protected]>. */
4 /* { dg-options "-Wpadded" } */
5 /* { dg-do run } */
6
7 #include "../objc-obj-c++-shared/TestsuiteObject.m"
8
9 extern void abort(void);
10 extern int strcmp(const char *str1, const char *str2);
11 #define CHECK_IF(expr) if(!(expr)) abort()
12
13 enum Enum { one, two, three, four };
14
15 @interface Base: TestsuiteObject {
16 unsigned a: 2;
17 int b: 3;
18 enum Enum c: 4;
19 unsigned d: 5;
20 } /* { dg-warning "padding struct size to alignment boundary" } */
21 @end
22
23 @interface Derived: Base {
24 signed e: 5;
25 int f: 4;
26 enum Enum g: 3;
27 } /* { dg-warning "padding struct size to alignment boundary" } */
28 @end
29
30 /* Note that the semicolon after @defs(...) is optional. */
31
32 typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */
33 typedef struct { @defs(Derived); } Derived_t; /* { dg-warning "padding struct size to alignment boundary" } */
34
35 int main(void)
36 {
37 CHECK_IF(sizeof(Base_t) == sizeof(Base));
38 CHECK_IF(sizeof(Derived_t) == sizeof(Derived));
39
40 #ifdef __NEXT_RUNTIME__
41 CHECK_IF(!strcmp(@encode(Base), "{Base=#b2b3b4b5}"));
42 CHECK_IF(!strcmp(@encode(Derived), "{Derived=#b2b3b4b5b5b4b3}"));
43
44 CHECK_IF(!strcmp(@encode(Base_t), "{?=#b2b3b4b5}"));
45 CHECK_IF(!strcmp(@encode(Derived_t), "{?=#b2b3b4b5b5b4b3}"));
46 #endif /* __NEXT_RUNTIME__ */
47
48 return 0;
49 }