2 bf-sign-2.c from the execute part of the gcc torture tests.
8 This test checks promotion of bitfields. Bitfields should be promoted
9 very much like chars and shorts:
11 Bitfields (signed or unsigned) should be promoted to signed int if their
12 value will fit in a signed int, otherwise to an unsigned int if their
13 value will fit in an unsigned int, otherwise we don't promote them (ANSI/ISO
14 does not specify the behavior of bitfields larger than an unsigned int).
16 We test the behavior by subtracting two from the promoted value: this will
17 result in a negitive value for signed types, a positive value for unsigned
18 types. This test (of course) assumes that the compiler is correctly
19 implementing signed and unsigned arithmetic.
24 #if 0 // Enable when SDCC supports bit-fields wider than 16 bits
25 signed long int s31
:31;
26 signed long int s32
:32;
27 unsigned long int u31
:31;
28 unsigned long int u32
:32;
29 unsigned long long ull3
:3;
30 unsigned long long ull35
:35;
38 testTortureExecute (void)
40 if ((x
.u3
- 2) >= 0) /* promoted value should be signed */
43 if ((x
.s31
- 2) >= 0) /* promoted value should be signed */
46 if ((x
.s32
- 2) >= 0) /* promoted value should be signed */
49 if ((x
.u15
- 2) >= 0) /* promoted value should be signed */
52 /* Conditionalize check on whether integers are 4 bytes or larger, i.e.
53 larger than a 31 bit bitfield. */
54 if (sizeof (int) >= 4)
56 if ((x
.u31
- 2) >= 0) /* promoted value should be signed */
61 if ((x
.u31
- 2) < 0) /* promoted value should be UNsigned */
65 if ((x
.u32
- 2) < 0) /* promoted value should be UNsigned */
68 if ((x
.ull3
- 2) >= 0) /* promoted value should be signed */
71 if ((x
.ull35
- 2) < 0) /* promoted value should be UNsigned */