3 /* Test for MS bitfield layout */
4 /* Adapted from Donn Terry <donnte@microsoft.com> testcase
6 http://gcc.gnu.org/ml/gcc-patches/2000-08/msg00577.html */
8 /* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* } } */
9 /* { dg-options "-mms-bitfields -D_TEST_MS_LAYOUT" } */
40 /* Bitfields of size 0 have some truly odd behaviors. */
45 unsigned int :0; /* forces struct alignment to int */
51 int :0; /* ignored; prior field is not a bitfield. */
58 int :0; /* not ignored; prior field IS a bitfield, causes
59 struct alignment as well. */
67 int :0; /* Ignored; prior field is zero size bitfield. */
72 struct eight
{ /* ms size 4 */
78 #define LONGLONG __int64
80 #define LONGLONG long long
83 union nine
{ /* ms size 8 */
88 struct ten
{ /* ms size 16 */
95 #define val(s,f) (s.f)
97 #define check_struct(_X) \
99 if (sizeof (struct _X) != exp_sizeof_##_X ) \
101 memcpy(&test_##_X, filler, sizeof(test_##_X));\
102 if (val(test_##_X,c) != exp_##_X##_c) \
106 #define check_union(_X) \
108 if (sizeof (union _X) != exp_sizeof_##_X ) \
110 memcpy(&test_##_X, filler, sizeof(test_##_X));\
111 if (val(test_##_X,c) != exp_##_X##_c) \
115 #define check_struct_size(_X) \
117 if (sizeof (struct _X) != exp_sizeof_##_X ) \
121 #define check_struct_off(_X) \
123 memcpy(&test_##_X, filler, sizeof(test_##_X));\
124 if (val(test_##_X,c) != exp_##_X##_c) \
128 #define check_union_size(_X) \
130 if (sizeof (union _X) != exp_sizeof_##_X ) \
134 #define check_union_off(_X) \
136 memcpy(&test_##_X, filler, sizeof(test_##_X));\
137 if (val(test_##_X,c) != exp_##_X##_c) \
143 unsigned char filler
[16];
146 struct three test_three
;
147 struct four test_four
;
148 struct five test_five
;
150 struct seven test_seven
;
151 struct eight test_eight
;
152 union nine test_nine
;
155 #if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
156 size_t exp_sizeof_one
= 12;
157 size_t exp_sizeof_two
= 16;
158 size_t exp_sizeof_three
=6;
159 size_t exp_sizeof_four
= 8;
160 size_t exp_sizeof_five
= 3;
161 size_t exp_sizeof_six
= 8;
162 size_t exp_sizeof_seven
= 3;
163 size_t exp_sizeof_eight
= 4;
164 size_t exp_sizeof_nine
= 8;
165 size_t exp_sizeof_ten
= 16;
167 unsigned char exp_one_c
= 8;
168 unsigned char exp_two_c
= 12;
169 unsigned char exp_three_c
= 4;
170 unsigned char exp_four_c
= 4;
173 char exp_seven_c
= 2;
174 char exp_eight_c
= 2;
178 #else /* testing -mno-ms-bitfields */
180 size_t exp_sizeof_one
= 8;
181 size_t exp_sizeof_two
= 8;
182 size_t exp_sizeof_three
= 6;
183 size_t exp_sizeof_four
= 6;
184 size_t exp_sizeof_five
= 6;
185 size_t exp_sizeof_six
= 6;
186 size_t exp_sizeof_seven
= 6;
187 size_t exp_sizeof_eight
= 2;
188 size_t exp_sizeof_nine
= 8;
189 size_t exp_sizeof_ten
= 8;
191 unsigned short exp_one_c
= 6;
192 unsigned int exp_two_c
= 6;
193 unsigned char exp_three_c
= 64;
194 unsigned char exp_four_c
= 4;
197 char exp_seven_c
= 5;
198 char exp_eight_c
= 1;
205 for ( i
= 0; i
< 16; i
++ )
208 check_struct_off (one
);
209 check_struct_off (two
);
210 check_struct_off (three
);
211 check_struct_off (four
);
212 check_struct_off (five
);
213 check_struct_off (six
);
214 check_struct_off (seven
);
215 check_struct_off (eight
);
216 check_union_off (nine
);
217 check_struct_off (ten
);
219 check_struct_size (one
);
220 check_struct_size (two
);
221 check_struct_size (three
);
222 check_struct_size (four
);
223 check_struct_size (five
);
224 check_struct_size (six
);
225 check_struct_size (seven
);
226 check_struct_size (eight
);
227 check_union_size (nine
);
228 check_struct_size (ten
);