1 // { dg-do run { target i?86-*-linux* i?86-*-gnu* x86_64-*-linux* i?86-*-freebsd* } }
2 // { dg-require-effective-target ilp32 }
3 // { dg-options "-malign-double" }
4 // Origin: Alex Samuel <samuel@codesourcery.com>
6 /* Test the layout of bitfields in C aggretagtes for compliance with
21 return (unsigned) & ((S *) 0)->object_;
24 /* Computes the alignment, in bytes, of TYPE. */
26 #define alignof(type) (alignmentof<type> ())
28 /* Returns true iff all the bits in the range
29 START_BIT <= bit < START_BIT + NUM_BITS, and only those bits, are
30 set in the region of memory starting at BUF of LENGTH bytes. */
33 check_bits (char *buf,
38 for (unsigned bit = 0; bit < 8 * length; ++bit) {
39 bool is_set = (buf[bit / 8] & (1 << (bit % 8))) != 0;
40 if (start_bit <= bit && bit < start_bit + num_bits) {
52 /* Creates a variable of type AGGREGATE, sets FIELD to -1, and
53 verifies that NUM_BITS bits starting at START_BIT, and no other
54 bits, are set. If the check fails, returns with value RVAL. */
56 #define CHECK_FIELD(AGGREGATE, FIELD, START_BIT, NUM_BITS, RVAL) \
59 std::memset (& a__, 0, sizeof (a__)); \
61 if (! check_bits ((char *) & a__, sizeof (a__), START_BIT, NUM_BITS)) \
67 /* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
68 Software Conventions and Runtime Architecture Guide", version of
78 #ifdef HAVE_IA64_TYPES
88 #endif /* HAVE_IA64_TYPES */
116 if (sizeof (struct S1) != 4)
118 if (alignof (struct S1) != 4)
120 CHECK_FIELD (S1, j, 0, 5, 3);
121 CHECK_FIELD (S1, k, 5, 6, 4);
122 CHECK_FIELD (S1, m, 11, 7, 5);
124 #ifdef HAVE_IA64_TYPES
125 if (sizeof (struct S2) != 16)
127 if (alignof (struct S2) != 8)
129 CHECK_FIELD (S2, s, 0, 9, 8);
130 CHECK_FIELD (S2, j, 9, 9, 9);
131 CHECK_FIELD (S2, c, 24, 8, 10);
132 CHECK_FIELD (S2, t, 32, 9, 11);
133 CHECK_FIELD (S2, u, 48, 9, 12);
134 CHECK_FIELD (S2, d, 64, 8, 13);
135 #endif /* HAVE_IA64_TYPES */
137 if (sizeof (struct S3) != 2)
139 if (sizeof (struct S3) != 2)
141 CHECK_FIELD (S3, c, 0, 8, 16);
142 CHECK_FIELD (S3, s, 8, 8, 17);
144 if (sizeof (union U4) != 2)
146 if (alignof (union U4) != 2)
148 CHECK_FIELD (U4, c, 0, 8, 20);
149 CHECK_FIELD (U4, s, 0, 8, 21);
151 if (sizeof (struct S5) != 9)
153 if (alignof (struct S5) != 1)
155 CHECK_FIELD (S5, c, 0, 8, 24);
156 CHECK_FIELD (S5, d, 32, 8, 25);
157 CHECK_FIELD (S5, e, 64, 8, 26);