xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/bitfield-layout.c (revision 0b98e8aad89f2bd4ba80b523d73cf29e9dd82ce1)
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9
2 // expected-no-diagnostics
3 
4 #define CHECK_SIZE(kind, name, size) extern int name##1[sizeof(kind name) == size ? 1 : -1];
5 #define CHECK_ALIGN(kind, name, size) extern int name##2[__alignof(kind name) == size ? 1 : -1];
6 
7 // Zero-width bit-fields
8 struct a {char x; int : 0; char y;};
9 CHECK_SIZE(struct, a, 5)
10 CHECK_ALIGN(struct, a, 1)
11 
12 union b {char x; int : 0; char y;};
13 CHECK_SIZE(union, b, 1)
14 CHECK_ALIGN(union, b, 1)
15 
16 // Unnamed bit-field align
17 struct c {char x; int : 20;};
18 CHECK_SIZE(struct, c, 4)
19 CHECK_ALIGN(struct, c, 1)
20 
21 union d {char x; int : 20;};
22 CHECK_SIZE(union, d, 3)
23 CHECK_ALIGN(union, d, 1)
24 
25 // Bit-field packing
26 struct __attribute__((packed)) e {int x : 4, y : 30, z : 30;};
27 CHECK_SIZE(struct, e, 8)
28 CHECK_ALIGN(struct, e, 1)
29 
30 // Alignment on bit-fields
31 struct f {__attribute((aligned(8))) int x : 30, y : 30, z : 30;};
32 CHECK_SIZE(struct, f, 24)
33 CHECK_ALIGN(struct, f, 8)
34 
35 // Large structure (overflows i32, in bits).
36 struct s0 {
37   char a[0x32100000];
38   int x:30, y:30;
39 };
40 
41 CHECK_SIZE(struct, s0, 0x32100008)
42 CHECK_ALIGN(struct, s0, 4)
43 
44