struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-bf-sign-2.c
blob7355df429335b2c3b9afebbf2131fecbfd76fc3d
1 /*
2 bf-sign-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 /*
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.
22 struct X {
23 unsigned int u3:3;
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;
31 #endif
32 unsigned u15:15;
35 struct X x;
37 void
38 testTortureExecute (void)
40 if ((x.u3 - 2) >= 0) /* promoted value should be signed */
41 ASSERT (0);
42 #if 0
43 if ((x.s31 - 2) >= 0) /* promoted value should be signed */
44 ASSERT (0);
46 if ((x.s32 - 2) >= 0) /* promoted value should be signed */
47 ASSERT (0);
48 #endif
49 if ((x.u15 - 2) >= 0) /* promoted value should be signed */
50 ASSERT (0);
51 #if 0
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 */
57 ASSERT (0);
59 else
61 if ((x.u31 - 2) < 0) /* promoted value should be UNsigned */
62 ASSERT (0);
65 if ((x.u32 - 2) < 0) /* promoted value should be UNsigned */
66 ASSERT (0);
68 if ((x.ull3 - 2) >= 0) /* promoted value should be signed */
69 ASSERT (0);
71 if ((x.ull35 - 2) < 0) /* promoted value should be UNsigned */
72 ASSERT (0);
73 #endif
74 return;