OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [bf-sign-2.c] - Blame information for rev 297

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 297 jeremybenn
/*
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
    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;
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
  /* Conditionalize check on whether integers are 4 bytes or larger, i.e.
44
     larger than a 31 bit bitfield.  */
45
  if (sizeof (int) >= 4)
46
    {
47
      if ((x.u31 - 2) >= 0)      /* promoted value should be signed */
48
        abort ();
49
    }
50
  else
51
    {
52
      if ((x.u31 - 2) < 0)       /* promoted value should be UNsigned */
53
        abort ();
54
    }
55
 
56
  if ((x.u32 - 2) < 0)           /* promoted value should be UNsigned */
57
    abort ();
58
 
59
  if ((x.ull3 - 2) >= 0) /* promoted value should be signed */
60
    abort ();
61
 
62
  if ((x.ull35 - 2) < 0) /* promoted value should be UNsigned */
63
    abort ();
64
 
65
  exit (0);
66
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.