1 // Skip if not target: i?86-*-linux* i?86-*-freebsd*
2 // Special g++ Options: -malign-double
3 // Origin: Alex Samuel <samuel@codesourcery.com>
5 /* Test the layout of bitfields in C aggretagtes for compliance with
20 return (unsigned) & ((S *) 0)->object_;
23 /* Computes the alignment, in bytes, of TYPE. */
25 #define alignof(type) (alignmentof<type> ())
27 /* Returns true iff all the bits in the range
28 START_BIT <= bit < START_BIT + NUM_BITS, and only those bits, are
29 set in the region of memory starting at BUF of LENGTH bytes. */
32 check_bits (char *buf,
37 for (unsigned bit = 0; bit < 8 * length; ++bit) {
38 bool is_set = (buf[bit / 8] & (1 << (bit % 8))) != 0;
39 if (start_bit <= bit && bit < start_bit + num_bits) {
51 /* Creates a variable of type AGGREGATE, sets FIELD to -1, and
52 verifies that NUM_BITS bits starting at START_BIT, and no other
53 bits, are set. If the check fails, returns with value RVAL. */
55 #define CHECK_FIELD(AGGREGATE, FIELD, START_BIT, NUM_BITS, RVAL) \
58 std::memset (& a__, 0, sizeof (a__)); \
60 if (! check_bits ((char *) & a__, sizeof (a__), START_BIT, NUM_BITS)) \
66 /* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
67 Software Conventions and Runtime Architecture Guide", version of
77 #ifdef HAVE_IA64_TYPES
87 #endif /* HAVE_IA64_TYPES */
115 if (sizeof (struct S1) != 4)
117 if (alignof (struct S1) != 4)
119 CHECK_FIELD (S1, j, 0, 5, 3);
120 CHECK_FIELD (S1, k, 5, 6, 4);
121 CHECK_FIELD (S1, m, 11, 7, 5);
123 #ifdef HAVE_IA64_TYPES
124 if (sizeof (struct S2) != 16)
126 if (alignof (struct S2) != 8)
128 CHECK_FIELD (S2, s, 0, 9, 8);
129 CHECK_FIELD (S2, j, 9, 9, 9);
130 CHECK_FIELD (S2, c, 24, 8, 10);
131 CHECK_FIELD (S2, t, 32, 9, 11);
132 CHECK_FIELD (S2, u, 48, 9, 12);
133 CHECK_FIELD (S2, d, 64, 8, 13);
134 #endif /* HAVE_IA64_TYPES */
136 if (sizeof (struct S3) != 2)
138 if (sizeof (struct S3) != 2)
140 CHECK_FIELD (S3, c, 0, 8, 16);
141 CHECK_FIELD (S3, s, 8, 8, 17);
143 if (sizeof (union U4) != 2)
145 if (alignof (union U4) != 2)
147 CHECK_FIELD (U4, c, 0, 8, 20);
148 CHECK_FIELD (U4, s, 0, 8, 21);
150 if (sizeof (struct S5) != 9)
152 if (alignof (struct S5) != 1)
154 CHECK_FIELD (S5, c, 0, 8, 24);
155 CHECK_FIELD (S5, d, 32, 8, 25);
156 CHECK_FIELD (S5, e, 64, 8, 26);