diff options
author | ed <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
commit | f27e5a09a0d815b8a4814152954ff87dadfdefc0 (patch) | |
tree | ce7d964cbb5e39695b71481698f10cb099c23d4a /test/Sema/bitfield-layout.c | |
download | FreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.zip FreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.tar.gz |
Import Clang, at r72732.
Diffstat (limited to 'test/Sema/bitfield-layout.c')
-rw-r--r-- | test/Sema/bitfield-layout.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/Sema/bitfield-layout.c b/test/Sema/bitfield-layout.c new file mode 100644 index 0000000..4405c80 --- /dev/null +++ b/test/Sema/bitfield-layout.c @@ -0,0 +1,32 @@ +// RUN: clang-cc %s -fsyntax-only -verify -triple=i686-apple-darwin9 + +#define CHECK_SIZE(kind, name, size) extern int name##1[sizeof(kind name) == size ? 1 : -1]; +#define CHECK_ALIGN(kind, name, size) extern int name##2[__alignof(kind name) == size ? 1 : -1]; + +// Zero-width bit-fields +struct a {char x; int : 0; char y;}; +CHECK_SIZE(struct, a, 5) +CHECK_ALIGN(struct, a, 1) + +union b {char x; int : 0; char y;}; +CHECK_SIZE(union, b, 1) +CHECK_ALIGN(union, b, 1) + +// Unnamed bit-field align +struct c {char x; int : 20;}; +CHECK_SIZE(struct, c, 4) +CHECK_ALIGN(struct, c, 1) + +union d {char x; int : 20;}; +CHECK_SIZE(union, d, 3) +CHECK_ALIGN(union, d, 1) + +// Bit-field packing +struct __attribute__((packed)) e {int x : 4, y : 30, z : 30;}; +CHECK_SIZE(struct, e, 8) +CHECK_ALIGN(struct, e, 1) + +// Alignment on bit-fields +struct f {__attribute((aligned(8))) int x : 30, y : 30, z : 30;}; +CHECK_SIZE(struct, f, 24) +CHECK_ALIGN(struct, f, 8) |