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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.target/] [x86_64/] [abi/] [test_bitfields.c] - Blame information for rev 859

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 328 jeremybenn
/* This is a small test to see if bitfields are working.  It is only a
2
   few structs and a union and a test to see if they have the correct
3
   size, if values can be read and written and a couple of argument
4
   passing tests.  No alignment testing is done.  */
5
 
6
#include "defines.h"
7
#include "macros.h"
8
 
9
 
10
/* These five bitfields are taken from the System V ABI, Intel 386
11
   architecture supplement.  */
12
 
13
/* Word aligned, sizeof is 4.  */
14
struct RightToLeft
15
{
16
  int j:5;
17
  int k:6;
18
  int m:7;
19
};
20
 
21
/* Word aligned, sizeof is 12.  */
22
struct BoundaryAlignment
23
{
24
  short s:9;
25
  int   j:9;
26
  char  c;
27
  short t:9;
28
  short u:9;
29
  char  d;
30
};
31
 
32
/* Halfword aligned, sizeof is 2.  */
33
struct StorageUnitSharing
34
{
35
  char  c;
36
  short s:8;
37
};
38
 
39
/* Halfword aligned, sizeof is 2.  */
40
union Allocation
41
{
42
  char  c;
43
  short s:8;
44
};
45
 
46
/* Byte aligned, sizeof is 9.  */
47
struct Unnamed
48
{
49
  char  c;
50
  int    :0;
51
  char  d;
52
  short  :9;
53
  char  e;
54
  char   :0;
55
};
56
 
57
/* Extra struct testing bitfields in larger types.
58
   Doubleword aligned, sizeof is 8.  */
59
struct LargerTypes
60
{
61
  long long l:33;
62
  int       i:31;
63
};
64
 
65
 
66
void
67
passing1 (struct RightToLeft str, int j, int k, int m)
68
{
69
  assert (str.j == j);
70
  assert (str.k == k);
71
  assert (str.m == m);
72
}
73
 
74
void
75
passing2 (struct BoundaryAlignment str, short s, int j, char c, short t,
76
          short u, char d)
77
{
78
  assert (str.s == s);
79
  assert (str.j == j);
80
  assert (str.c == c);
81
  assert (str.t == t);
82
  assert (str.u == u);
83
  assert (str.d == d);
84
}
85
 
86
void
87
passing3 (struct StorageUnitSharing str, char c, short s)
88
{
89
  assert (str.c == c);
90
  assert (str.s == s);
91
}
92
 
93
void
94
passing4 (struct Unnamed str, char c, char d, char e)
95
{
96
  assert (str.c == c);
97
  assert (str.d == d);
98
  assert (str.e == e);
99
}
100
 
101
void
102
passing5 (struct LargerTypes str, long long l, int i)
103
{
104
  assert (str.l == l);
105
  assert (str.i == i);
106
}
107
 
108
 
109
void
110
passingU (union Allocation u, char c)
111
{
112
  assert (u.c == c);
113
  assert (u.s == c);
114
}
115
 
116
 
117
int
118
main (void)
119
{
120
  struct RightToLeft str1;
121
  struct BoundaryAlignment str2;
122
  struct StorageUnitSharing str3;
123
  struct Unnamed str4;
124
  struct LargerTypes str5;
125
  union Allocation u;
126
 
127
  /* Check sizeof's.  */
128
  check_size(str1, 4);
129
  check_size(str2, 12);
130
  check_size(str3, 2);
131
  check_size(str4, 9);
132
  check_size(str5, 8);
133
  check_size(u, 2);
134
 
135
  /* Check alignof's.  */
136
  check_align_lv(str1, 4);
137
  check_align_lv(str2, 4);
138
  check_align_lv(str3, 2);
139
  check_align_lv(str4, 1);
140
  check_align_lv(str5, 8);
141
  check_align_lv(u, 2);
142
 
143
  /* Check passing.  */
144
  str1.j = str2.s = str3.c = str4.c = str5.l = 4;
145
  str1.k = str2.j = str3.s = str4.d = str5.i = 5;
146
  str1.m = str2.c = str4.e = 6;
147
  str2.t = 7;
148
  str2.u = 8;
149
  str2.d = 9;
150
  passing1 (str1, 4, 5, 6);
151
  passing2 (str2, 4, 5, 6, 7, 8, 9);
152
  passing3 (str3, 4, 5);
153
  passing4 (str4, 4, 5, 6);
154
  passing5 (str5, 4, 5);
155
 
156
  u.c = 5;
157
  passingU (u, 5);
158
  u.s = 6;
159
  passingU (u, 6);
160
 
161
  return 0;
162
}

powered by: WebSVN 2.1.0

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