OSDN Git Service

365e061c839b805041079510f7c6bce3dde0090d
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / bf-sign-2.c
1 /* 
2  This test checks promotion of bitfields.  Bitfields should be promoted
3  very much like chars and shorts: 
4
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).
9
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.
14  */
15
16 struct X {
17   unsigned int       u3:3;
18            long int  s31:31;
19            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;
25 };
26
27 struct X x;
28
29 main ()
30 {
31   if ((x.u3 - 2) >= 0)          /* promoted value should be signed */
32     abort ();
33
34   if ((x.s31 - 2) >= 0)         /* promoted value should be signed */
35     abort ();
36
37   if ((x.s32 - 2) >= 0)         /* promoted value should be signed */
38     abort ();
39
40   if ((x.u15 - 2) >= 0)         /* promoted value should be signed */
41     abort ();
42
43   if (sizeof (struct { unsigned long u32:32;}) <= sizeof (int))
44     {
45       if ((x.u31 - 2) >= 0)     /* promoted value should be signed */
46         abort ();
47     }
48   else
49     {
50       if ((x.u31 - 2) < 0)      /* promoted value should be UNsigned */
51         abort ();
52     }
53
54   if ((x.u32 - 2) < 0)          /* promoted value should be UNsigned */
55     abort ();
56
57   if ((x.ull3 - 2) >= 0)        /* promoted value should be signed */
58     abort ();
59
60   if ((x.ull35 - 2) < 0)        /* promoted value should be UNsigned */
61     abort ();
62
63   exit (0);
64 }