1290001Sglebius/* { dg-do run { target { pcc_bitfield_type_matters || default_packed } } } */
2290001Sglebius
3290001Sglebius/* Check bitfields and non-bitfields are aligned & sized similarly.
4290001Sglebius
5290001Sglebius   Copyright (C) 2002 Free Software Foundation Inc
6290001Sglebius   Contributed by Nathan Sidwell <nathan@codesourcery.com>
7290001Sglebius*/
8290001Sglebius
9290001Sglebius#include <limits.h>
10290001Sglebius#include <stdio.h>
11290001Sglebius
12290001Sglebiusstatic int fail;
13290001Sglebius
14290001Sglebius#define CHECK1(N, T) do { \
15290001Sglebius  typedef struct Field_##N { char c; T f; } Field_##N; \
16290001Sglebius  typedef struct BitField_##N { char c; T f : sizeof (T) * CHAR_BIT; } BitField_##N; \
17290001Sglebius  if (sizeof (Field_##N) != sizeof (BitField_##N)) { \
18290001Sglebius    fail = 1; printf ("sizeof %s failed\n", #T); \
19290001Sglebius  } \
20290001Sglebius  if (__alignof__ (Field_##N) != __alignof__ (BitField_##N)) { \
21290001Sglebius    fail = 1; printf ("__alignof__ %s failed\n", #T); \
22290001Sglebius  } \
23290001Sglebius} while (0)
24290001Sglebius
25290001Sglebius#define CHECK(N, T) do { \
26290001Sglebius  CHECK1(N, T); \
27290001Sglebius  CHECK1 (s##N, signed T); \
28290001Sglebius  CHECK1 (u##N, unsigned T); \
29290001Sglebius} while (0)
30290001Sglebius
31290001Sglebiusint main ()
32290001Sglebius{
33290001Sglebius
34290001Sglebius  CHECK (c, char);
35290001Sglebius  CHECK (s, short);
36290001Sglebius  CHECK (i, int);
37290001Sglebius  CHECK (l, long);
38290001Sglebius  CHECK (ll, long long);
39290001Sglebius
40290001Sglebius  return fail;
41290001Sglebius}
42290001Sglebius