* gcc.target/i386/mpx/hard-reg-1-nov.c (mpx_test): Use "esp"
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / bf-sign-2.c
blobe8e17176ac07e1787a50101759f22c424fb7eb4d
1 /*
2 This test checks promotion of bitfields. Bitfields should be promoted
3 very much like chars and shorts:
5 Bitfields (signed or unsigned) should be promoted to signed int if their
6 value will fit in a signed int, otherwise to an unsigned int if their
7 value will fit in an unsigned int, otherwise we don't promote them (ANSI/ISO
8 does not specify the behavior of bitfields larger than an unsigned int).
10 We test the behavior by subtracting two from the promoted value: this will
11 result in a negitive value for signed types, a positive value for unsigned
12 types. This test (of course) assumes that the compiler is correctly
13 implementing signed and unsigned arithmetic.
16 struct X {
17 unsigned int u3:3;
18 signed long int s31:31;
19 signed long int s32:32;
20 unsigned long int u31:31;
21 unsigned long int u32:32;
22 unsigned long long ull3 :3;
23 unsigned long long ull35:35;
24 unsigned u15:15;
27 struct X x;
29 main ()
31 if ((x.u3 - 2) >= 0) /* promoted value should be signed */
32 abort ();
34 if ((x.s31 - 2) >= 0) /* promoted value should be signed */
35 abort ();
37 if ((x.s32 - 2) >= 0) /* promoted value should be signed */
38 abort ();
40 if ((x.u15 - 2) >= 0) /* promoted value should be signed */
41 abort ();
43 /* Conditionalize check on whether integers are 4 bytes or larger, i.e.
44 larger than a 31 bit bitfield. */
45 if (sizeof (int) >= 4)
47 if ((x.u31 - 2) >= 0) /* promoted value should be signed */
48 abort ();
50 else
52 if ((x.u31 - 2) < 0) /* promoted value should be UNsigned */
53 abort ();
56 if ((x.u32 - 2) < 0) /* promoted value should be UNsigned */
57 abort ();
59 if ((x.ull3 - 2) >= 0) /* promoted value should be signed */
60 abort ();
62 if ((x.ull35 - 2) < 0) /* promoted value should be UNsigned */
63 abort ();
65 exit (0);