2018-04-09 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / bitfld-4.c
blobe642bec5ad365f7456b797b31a2b812a09855f09
1 /* { dg-do run { target { pcc_bitfield_type_matters || default_packed } } } */
2 /* { dg-options "" } */
4 /* Check bitfields and non-bitfields are aligned & sized similarly.
6 Copyright (C) 2002 Free Software Foundation Inc
7 Contributed by Nathan Sidwell <nathan@codesourcery.com>
8 */
10 #include <limits.h>
11 #include <stdio.h>
13 static int fail;
15 #define CHECK1(N, T) do { \
16 typedef struct Field_##N { char c; T f; } Field_##N; \
17 typedef struct BitField_##N { char c; T f : sizeof (T) * CHAR_BIT; } BitField_##N; \
18 if (sizeof (Field_##N) != sizeof (BitField_##N)) { \
19 fail = 1; printf ("sizeof %s failed\n", #T); \
20 } \
21 if (__alignof__ (Field_##N) != __alignof__ (BitField_##N)) { \
22 fail = 1; printf ("__alignof__ %s failed\n", #T); \
23 } \
24 } while (0)
26 #define CHECK(N, T) do { \
27 CHECK1(N, T); \
28 CHECK1 (s##N, signed T); \
29 CHECK1 (u##N, unsigned T); \
30 } while (0)
32 int main ()
35 CHECK (c, char);
36 CHECK (s, short);
37 CHECK (i, int);
38 CHECK (l, long);
39 CHECK (ll, long long);
41 return fail;