blob: 2655fc70cd4c427bde64cf2062014bb79c1025b1 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9
Eli Friedman4bd998b2008-05-30 09:31:38 +00002
3#define CHECK_SIZE(kind, name, size) extern int name##1[sizeof(kind name) == size ? 1 : -1];
4#define CHECK_ALIGN(kind, name, size) extern int name##2[__alignof(kind name) == size ? 1 : -1];
5
6// Zero-width bit-fields
7struct a {char x; int : 0; char y;};
8CHECK_SIZE(struct, a, 5)
9CHECK_ALIGN(struct, a, 1)
10
11union b {char x; int : 0; char y;};
12CHECK_SIZE(union, b, 1)
13CHECK_ALIGN(union, b, 1)
14
15// Unnamed bit-field align
16struct c {char x; int : 20;};
17CHECK_SIZE(struct, c, 4)
18CHECK_ALIGN(struct, c, 1)
19
20union d {char x; int : 20;};
21CHECK_SIZE(union, d, 3)
22CHECK_ALIGN(union, d, 1)
23
24// Bit-field packing
25struct __attribute__((packed)) e {int x : 4, y : 30, z : 30;};
26CHECK_SIZE(struct, e, 8)
27CHECK_ALIGN(struct, e, 1)
28
29// Alignment on bit-fields
30struct f {__attribute((aligned(8))) int x : 30, y : 30, z : 30;};
31CHECK_SIZE(struct, f, 24)
32CHECK_ALIGN(struct, f, 8)
Daniel Dunbar84b03162010-06-29 18:34:35 +000033
34// Large structure (overflows i32, in bits).
35struct s0 {
36 char a[0x32100000];
37 int x:30, y:30;
38};
39
40CHECK_SIZE(struct, s0, 0x32100008)
41CHECK_ALIGN(struct, s0, 4)
42