aboutsummaryrefslogtreecommitdiff
blob: edb3b9fadadf9e869f6698ca2edb55b45a7d62d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* Test program to test bit field operations on bit fields of large
   integer types.  */

/* This file is expected to fail to compile if the type long long int
   is not supported, but in that case it is irrelevant.  */

#include <stdlib.h>
#include <string.h>

#if !defined(__STDC__) && !defined(__cplusplus)
#define signed  /**/
#endif

struct fields
{
  unsigned long long u1 : 15;
  unsigned long long u2 : 33;
  unsigned long long u3 : 16;
  signed long long   s1 : 15;
  signed long long   s2 : 33;
  signed long long   s3 : 16;
} flags;

void break1 ()
{
}

void break2 ()
{
}

void break3 ()
{
}

void break4 ()
{
}

void break5 ()
{
}

void break6 ()
{
}

void break7 ()
{
}

void break8 ()
{
}

void break9 ()
{
}

void break10 ()
{
}

/* This is used by bitfields.exp to determine if the target understands
   signed bitfields.  */
int i;

void tester ()
{
  memset ((char *) &flags, 0, sizeof (flags));

  /* For each member, set that member to 1, allow gdb to verify that the
     member (and only that member) is 1, and then reset it back to 0. */
  flags.s1 = 1;
  break1 ();
  flags.s1 = 0;

  flags.u1 = 1;
  break1 ();
  flags.u1 = 0;

  flags.s2  = 1;
  break1 ();
  flags.s2 = 0;

  flags.u2 = 1;
  break1 ();
  flags.u2 = 0;

  flags.s3  = 1;
  break1 ();
  flags.s3 = 0;

  flags.u3 = 1;
  break1 ();
  flags.u3 = 0;

  /* Fill alternating fields with all 1's and verify that none of the bits
     "bleed over" to the other fields. */

  flags.u1 = 0x7FFF;
  flags.u3 = 0xFFFF;
  flags.s2 = -1LL;
  break2 ();
  flags.u1 = 0;
  flags.u3 = 0;
  flags.s2 = 0;

  flags.u2 = 0x1FFFFFFFFLL;
  flags.s1 = -1;
  flags.s3 = -1;
  break2 ();

  flags.u2 = 0;
  flags.s1 = 0;
  flags.s3 = 0;

  /* Fill the unsigned fields with the maximum positive value and verify
     that the values are printed correctly. */

  flags.u1 = 0x7FFF;
  flags.u2 = 0x1FFFFFFFFLL;
  flags.u3 = 0xFFFF;
  break3 ();
  flags.u1 = 0;
  flags.u2 = 0;
  flags.u3 = 0;

  /* Fill the signed fields with the maximum positive value, then the maximally
     negative value, then -1, and verify in each case that the values are
     printed correctly. */

  /* Maximum positive values */
  flags.s1 = 0x3FFF;
  flags.s2 = 0xFFFFFFFFLL;
  flags.s3 = 0x7FFF;
  break4 ();

  /* Maximally negative values */
  flags.s1 = -0x4000;
  flags.s2 = -0x100000000LL;
  flags.s3 = -0x8000;

  /* Extract bitfield value so that bitfield.exp can check if the target
     understands signed bitfields.  */
  i = flags.s3;
  break4 ();

  /* -1 */
  flags.s1 = -1;
  flags.s2 = -1;
  flags.s3 = -1;
  break4 ();

  flags.s1 = 0;
  flags.s2 = 0;
  flags.s3 = 0;

  break5 ();
}

int main () 
{
  int i;

  for (i = 0; i < 5; i += 1)
    tester ();
  return 0;
}