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 i?86-*-* x86_64-*-* } } */
9 /* { dg-options "-D_TEST_MS_LAYOUT" } */
10 /* This test uses the attribute instead of the command line option. */
20 #define ATTR __attribute__ ((ms_struct))
45 /* Bitfields of size 0 have some truly odd behaviors. */
50 unsigned int :0; /* forces struct alignment to int */
56 int :0; /* ignored; prior field is not a bitfield. */
63 int :0; /* not ignored; prior field IS a bitfield, causes
64 struct alignment as well. */
72 int :0; /* Ignored; prior field is zero size bitfield. */
77 struct eight
{ /* ms size 4 */
83 #define LONGLONG __int64
85 #define LONGLONG long long
88 union nine
{ /* ms size 8 */
93 struct ten
{ /* ms size 16 */
100 #define val(s,f) (s.f)
102 #define check_struct(_X) \
104 if (sizeof (struct _X) != exp_sizeof_##_X ) \
106 memcpy(&test_##_X, filler, sizeof(test_##_X));\
107 if (val(test_##_X,c) != exp_##_X##_c) \
111 #define check_union(_X) \
113 if (sizeof (union _X) != exp_sizeof_##_X ) \
115 memcpy(&test_##_X, filler, sizeof(test_##_X));\
116 if (val(test_##_X,c) != exp_##_X##_c) \
120 #define check_struct_size(_X) \
122 if (sizeof (struct _X) != exp_sizeof_##_X ) \
126 #define check_struct_off(_X) \
128 memcpy(&test_##_X, filler, sizeof(test_##_X));\
129 if (val(test_##_X,c) != exp_##_X##_c) \
133 #define check_union_size(_X) \
135 if (sizeof (union _X) != exp_sizeof_##_X ) \
139 #define check_union_off(_X) \
141 memcpy(&test_##_X, filler, sizeof(test_##_X));\
142 if (val(test_##_X,c) != exp_##_X##_c) \
148 unsigned char filler
[16];
151 struct three test_three
;
152 struct four test_four
;
153 struct five test_five
;
155 struct seven test_seven
;
156 struct eight test_eight
;
157 union nine test_nine
;
160 #if defined (_TEST_MS_LAYOUT) || defined (_MSC_VER)
161 size_t exp_sizeof_one
= 12;
162 size_t exp_sizeof_two
= 16;
163 size_t exp_sizeof_three
=6;
164 size_t exp_sizeof_four
= 8;
165 size_t exp_sizeof_five
= 3;
166 size_t exp_sizeof_six
= 8;
167 size_t exp_sizeof_seven
= 3;
168 size_t exp_sizeof_eight
= 4;
169 size_t exp_sizeof_nine
= 8;
170 size_t exp_sizeof_ten
= 16;
172 unsigned char exp_one_c
= 8;
173 unsigned char exp_two_c
= 12;
174 unsigned char exp_three_c
= 4;
175 unsigned char exp_four_c
= 4;
178 char exp_seven_c
= 2;
179 char exp_eight_c
= 2;
183 #else /* testing -mno-ms-bitfields */
185 size_t exp_sizeof_one
= 8;
186 size_t exp_sizeof_two
= 8;
187 size_t exp_sizeof_three
= 6;
188 size_t exp_sizeof_four
= 6;
189 size_t exp_sizeof_five
= 6;
190 size_t exp_sizeof_six
= 6;
191 size_t exp_sizeof_seven
= 6;
192 size_t exp_sizeof_eight
= 2;
193 size_t exp_sizeof_nine
= 8;
194 size_t exp_sizeof_ten
= 8;
196 unsigned short exp_one_c
= 6;
197 unsigned int exp_two_c
= 6;
198 unsigned char exp_three_c
= 64;
199 unsigned char exp_four_c
= 4;
202 char exp_seven_c
= 5;
203 char exp_eight_c
= 1;
210 for ( i
= 0; i
< 16; i
++ )
213 check_struct_off (one
);
214 check_struct_off (two
);
215 check_struct_off (three
);
216 check_struct_off (four
);
217 check_struct_off (five
);
218 check_struct_off (six
);
219 check_struct_off (seven
);
220 check_struct_off (eight
);
221 check_union_off (nine
);
222 check_struct_off (ten
);
224 check_struct_size (one
);
225 check_struct_size (two
);
226 check_struct_size (three
);
227 check_struct_size (four
);
228 check_struct_size (five
);
229 check_struct_size (six
);
230 check_struct_size (seven
);
231 check_struct_size (eight
);
232 check_union_size (nine
);
233 check_struct_size (ten
);