3 SDCC pic16 port currently does not support bitfields of size > 8,
4 so they are ifdefed out.
13 #ifndef __SDCC_pdk14 // Lack of memory
14 #if !defined(__SDCC_pic16)
38 #endif /* !__SDCC_pic16 */
64 #if !defined(__SDCC_pic16)
88 struct { /* Bit-fields that end on byte boundary */
105 #endif /* !__SDCC_pic16 */
108 testBitfieldSizeof(void)
110 /* Although bitfields are extremely implementation dependent, these
111 assertions should hold for all implementations with storage units
112 of 8 bits or larger (nearly universal).
114 ASSERT( sizeof(size1a_bf
) >= 1);
115 ASSERT( sizeof(size1b_bf
) >= 1);
116 ASSERT( sizeof(size1c_bf
) >= 1);
117 #if !defined(__SDCC_pic16)
118 ASSERT( sizeof(size2b_bf
) >= 2);
119 ASSERT( sizeof(size2c_bf
) >= 2);
120 ASSERT( sizeof(size2d_bf
) >= 2);
121 ASSERT( sizeof(size3a_bf
) >= 2);
122 ASSERT( sizeof(size1a_bf
) <= sizeof(size1b_bf
));
123 #endif /* !__SDCC_pic16 */
124 /* Some SDCC specific assertions. SDCC uses 8 bit storage units.
125 Bitfields that are less than 8 bits, but would (due to earlier
126 bitfield declarations) span a storage unit boundary are
127 realigned to the next storage unit boundary. Bitfields of
128 8 or greater bits are always aligned to start on a storage
132 ASSERT( sizeof(size1a_bf
) == 1);
133 ASSERT( sizeof(size1b_bf
) == 1);
134 ASSERT( sizeof(size1c_bf
) == 1);
135 ASSERT( sizeof(size2a_bf
) == 2);
136 #if !defined(__SDCC_pic16)
137 ASSERT( sizeof(size2b_bf
) == 2);
138 ASSERT( sizeof(size2c_bf
) == 2);
139 ASSERT( sizeof(size2d_bf
) == 2);
140 ASSERT( sizeof(size3a_bf
) == 3);
141 #endif /* !__SDCC_pic16 */
147 testBitfieldsSingleBitLiteral(void)
149 #ifndef __SDCC_pdk14 // Lack of memory
150 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
151 #if !defined(__SDCC_pic16)
163 /* make sure modulo 2 truncation works */
164 size2b_bf
.b0
= 0x3fe;
165 ASSERT(size2b_bf
.b0
==0);
166 ASSERT(size2b_bf
.b1
==0);
167 ASSERT(size2b_bf
.b2
==0);
168 ASSERT(size2b_bf
.b3
==0);
169 ASSERT(size2b_bf
.b4
==0);
170 ASSERT(size2b_bf
.b5
==0);
171 ASSERT(size2b_bf
.b6
==0);
172 ASSERT(size2b_bf
.b7
==0);
173 ASSERT(size2b_bf
.b8
==0);
174 ASSERT(size2b_bf
.b9
==0);
175 size2b_bf
.b0
= 0x3ff;
176 ASSERT(size2b_bf
.b0
==1);
177 ASSERT(size2b_bf
.b1
==0);
178 ASSERT(size2b_bf
.b2
==0);
179 ASSERT(size2b_bf
.b3
==0);
180 ASSERT(size2b_bf
.b4
==0);
181 ASSERT(size2b_bf
.b5
==0);
182 ASSERT(size2b_bf
.b6
==0);
183 ASSERT(size2b_bf
.b7
==0);
184 ASSERT(size2b_bf
.b8
==0);
185 ASSERT(size2b_bf
.b9
==0);
187 /* make sure both bytes work */
188 size2b_bf
.b9
= 0x3ff;
189 ASSERT(size2b_bf
.b0
==1);
190 ASSERT(size2b_bf
.b1
==0);
191 ASSERT(size2b_bf
.b2
==0);
192 ASSERT(size2b_bf
.b3
==0);
193 ASSERT(size2b_bf
.b4
==0);
194 ASSERT(size2b_bf
.b5
==0);
195 ASSERT(size2b_bf
.b6
==0);
196 ASSERT(size2b_bf
.b7
==0);
197 ASSERT(size2b_bf
.b8
==0);
198 ASSERT(size2b_bf
.b9
==1);
199 #endif /* !__SDCC_pic16 */
205 testBitfieldsSingleBit(void)
207 #ifndef __SDCC_pdk14 // Lack of memory
208 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
209 #if !defined(__SDCC_pic16)
210 volatile unsigned char c
;
224 /* make sure modulo 2 truncation works */
227 ASSERT(size2b_bf
.b0
==0);
228 ASSERT(size2b_bf
.b1
==0);
229 ASSERT(size2b_bf
.b2
==0);
230 ASSERT(size2b_bf
.b3
==0);
231 ASSERT(size2b_bf
.b4
==0);
232 ASSERT(size2b_bf
.b5
==0);
233 ASSERT(size2b_bf
.b6
==0);
234 ASSERT(size2b_bf
.b7
==0);
235 ASSERT(size2b_bf
.b8
==0);
236 ASSERT(size2b_bf
.b9
==0);
239 ASSERT(size2b_bf
.b0
==1);
240 ASSERT(size2b_bf
.b1
==0);
241 ASSERT(size2b_bf
.b2
==0);
242 ASSERT(size2b_bf
.b3
==0);
243 ASSERT(size2b_bf
.b4
==0);
244 ASSERT(size2b_bf
.b5
==0);
245 ASSERT(size2b_bf
.b6
==0);
246 ASSERT(size2b_bf
.b7
==0);
247 ASSERT(size2b_bf
.b8
==0);
248 ASSERT(size2b_bf
.b9
==0);
250 /* make sure both bytes work */
252 ASSERT(size2b_bf
.b0
==1);
253 ASSERT(size2b_bf
.b1
==0);
254 ASSERT(size2b_bf
.b2
==0);
255 ASSERT(size2b_bf
.b3
==0);
256 ASSERT(size2b_bf
.b4
==0);
257 ASSERT(size2b_bf
.b5
==0);
258 ASSERT(size2b_bf
.b6
==0);
259 ASSERT(size2b_bf
.b7
==0);
260 ASSERT(size2b_bf
.b8
==0);
261 ASSERT(size2b_bf
.b9
==1);
262 #endif /* !__SDCC_pic16 */
268 testBitfieldsMultibitLiteral(void)
270 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
271 #if !defined(__SDCC_pic16)
272 size2c_bf
.b0
= 0xff; /* should truncate to 0x0f */
274 ASSERT(size2c_bf
.b0
==0x0f);
275 ASSERT(size2c_bf
.b1
==0);
277 size2c_bf
.b1
= 0xff; /* should truncate to 0x1f */
279 ASSERT(size2c_bf
.b0
==0);
280 ASSERT(size2c_bf
.b1
==0x1f);
282 size2c_bf
.b0
= 0xff; /* should truncate to 0x0f */
283 size2c_bf
.b1
= 0xff; /* should truncate to 0x1f */
284 ASSERT(size2c_bf
.b0
==0x0f);
285 ASSERT(size2c_bf
.b1
==0x1f);
287 size2d_bf
.b0
= 0xffff; /* should truncate to 0x0fff */
289 ASSERT(size2d_bf
.b0
==0x0fff);
290 ASSERT(size2d_bf
.b1
==0);
292 size2d_bf
.b1
= 0xffff; /* should truncate to 0x07 */
294 ASSERT(size2d_bf
.b0
==0);
295 ASSERT(size2d_bf
.b1
==0x07);
297 size2d_bf
.b0
= 0xffff; /* should truncate to 0x0fff */
298 size2d_bf
.b1
= 0xffff; /* should truncate to 0x07 */
299 ASSERT(size2d_bf
.b0
==0x0fff);
300 ASSERT(size2d_bf
.b1
==0x07);
302 size2d_bf
.b0
= 0x0321;
304 ASSERT(size2d_bf
.b0
==0x0321);
305 ASSERT(size2d_bf
.b1
==1);
307 size2d_bf
.b0
= 0x0a46;
309 ASSERT(size2d_bf
.b0
==0x0a46);
310 ASSERT(size2d_bf
.b1
==5);
317 ASSERT(size2e_bf
.b0
==2);
318 ASSERT(size2e_bf
.b1
==2);
319 ASSERT(size2e_bf
.b2
==2);
320 ASSERT(size2e_bf
.b3
==2);
321 #endif /* !__SDCC_pic16 */
326 testBitfieldsMultibit(void)
328 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
329 #if !defined(__SDCC_pic16)
330 volatile int allones
= 0xffff;
331 volatile int zero
= 0;
334 size2c_bf
.b0
= allones
; /* should truncate to 0x0f */
336 ASSERT(size2c_bf
.b0
==0x0f);
337 ASSERT(size2c_bf
.b1
==0);
339 size2c_bf
.b1
= allones
; /* should truncate to 0x1f */
341 ASSERT(size2c_bf
.b0
==0);
342 ASSERT(size2c_bf
.b1
==0x1f);
344 size2d_bf
.b0
= allones
; /* should truncate to 0x0fff */
346 ASSERT(size2d_bf
.b0
==0x0fff);
347 ASSERT(size2d_bf
.b1
==0);
349 size2d_bf
.b1
= allones
; /* should truncate to 0x07 */
351 ASSERT(size2d_bf
.b0
==0);
352 ASSERT(size2d_bf
.b1
==0x07);
358 ASSERT(size2d_bf
.b0
==0x0321);
359 ASSERT(size2d_bf
.b1
==1);
365 ASSERT(size2d_bf
.b0
==0x0a46);
366 ASSERT(size2d_bf
.b1
==5);
374 ASSERT(size2e_bf
.b0
==2);
375 ASSERT(size2e_bf
.b1
==2);
376 ASSERT(size2e_bf
.b2
==2);
377 ASSERT(size2e_bf
.b3
==2);
378 #endif /* !__SDCC_pic16 */
387 #if defined(PORT_HOST) && (defined(__ppc__) || defined(__PPC__) || defined(__sparc) || defined(__sparc64__))
388 /* bitfields on powerpc and sparc architectures are allocated from left to right */
389 ASSERT(*(char *)(&c_bf
) == ((2<<(8-3)) + 3) );
391 ASSERT(*(char *)(&c_bf
) == (2 + (3<<3)) );
397 ASSERT(*(int *)(&i_bf
) == (23 + (234<<7)) );
399 l_bitfield
.l0_7
= 23;
400 l_bitfield
.l7_10
= 234;
401 l_bitfield
.l17_15
= 2345;
402 ASSERT(*(long *)(&l_bf
) == (23 + (234<<7) + (2345<<17)) );
407 testSignedBitfields(void)
409 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
410 #if !defined(__SDCC_pic16)
414 ASSERT(s_bf
.s0_7
== -16);
415 ASSERT(s_bf
.s7_1
== - 1);
416 ASSERT(s_bf
.s8_9
== - 8);
417 ASSERT(s_bf
.s0_7
< 0);
418 ASSERT(s_bf
.s7_1
< 0);
419 ASSERT(s_bf
.s8_9
< 0);
424 ASSERT(s_bf
.s0_7
== 0x3f);
425 ASSERT(s_bf
.s7_1
== 0);
426 ASSERT(s_bf
.s8_9
== 0xff);
427 ASSERT(s_bf
.s0_7
> 0);
428 ASSERT(s_bf
.s8_9
> 0);
429 #endif /* !__SDCC_pic16 */
433 /* test case for enhancement request #2291335 : Unnamed bit-field initialization */
447 struct s2291335_1 gs2291335_1
= {1, 2};
448 struct s2291335_2 gs2291335_2
= {1, 2};
453 struct s2291335_1 ls2291335_1
= {1, 2};
454 struct s2291335_2 ls2291335_2
= {1, 2};
456 ASSERT(gs2291335_1
.a
== 1);
457 ASSERT(gs2291335_1
.b
== 2);
458 ASSERT(gs2291335_2
.a
== 1);
459 ASSERT(gs2291335_2
.b
== 2);
461 ASSERT(ls2291335_1
.a
== 1);
462 ASSERT(ls2291335_1
.b
== 2);
463 ASSERT(ls2291335_2
.a
== 1);
464 ASSERT(ls2291335_2
.b
== 2);
467 /* test case for bug #2366757: segfault when initializing structure with bitfield */
475 /* test case for const struct with bitfields */
477 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
478 #ifndef __SDCC_pic16 // TODO: enable when the pic16 ports supports bitfields of size greater than 8 bits!
489 } cs
= { 1, 2, 345, 6, 2, 1, 54321};
493 #if defined(PORT_HOST) && (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 6)
494 /* Workaround to fix the (cs.f == 1) test failure, which appeared in svn build 6665, when -O2 gcc option was included.
495 * The failure only occurs on i386 and x86_64 host architectures with gcc 4.6 if -O2 is set.
496 * This seems like a gcc bug to me. (Borut)
498 #pragma GCC push_options
499 #pragma GCC optimize ("O0")
504 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
505 #ifndef __SDCC_pic16 // TODO: enable when the pic16 ports supports bitfields of size greater than 8 bits!
512 ASSERT(cs
.g
== 54321U);
516 #if defined(PORT_HOST) && defined(__sun) && defined(__i386__) && defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 6)
517 #pragma GCC pop_options