blob: e1ece81b78173f228aaad5f5ece0dfb9d3ed9901 (
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
|
/* APPLE LOCAL file 4430139 */
#include <string.h>
extern void abort();
/* { dg-do run { target powerpc*-*-darwin* } } */
/* { dg-options "-std=gnu99" } */
typedef unsigned short WORD;
typedef unsigned int DWORD;
#pragma reverse_bitfields on
#pragma ms_struct on
#define USE_STRUCT_WRAPPER 0
#pragma pack(push, 2)
typedef struct
{
DWORD a;
#if USE_STRUCT_WRAPPER
struct {
#endif
WORD b:2,
c:14;
#if USE_STRUCT_WRAPPER
};
#endif
DWORD d:22,
e:10;
DWORD f;
DWORD g:25,
h:1,
i:6;
#if USE_STRUCT_WRAPPER
struct {
#endif
WORD j:14,
k:2;
#if USE_STRUCT_WRAPPER
};
#endif
} Foo;
typedef union { Foo x; int y[6]; } u1;
#pragma pack(pop)
int main(int argc, char* argv[])
{
Foo foo;
int i;
u1 U;
memset (&U, 0, sizeof(u1));
U.x.a = 1;
U.x.b = 1;
U.x.c = 1;
U.x.d = 1;
U.x.e = 1;
U.x.f = 1;
U.x.g = 1;
U.x.h = 1;
U.x.i = 1;
U.x.j = 1;
U.x.k = 1;
// s should be == 20. In the bad case, it ends up as 22
int s = sizeof(Foo);
if (sizeof(Foo) != 20
|| U.y[0] != 0x00000001
|| U.y[1] != 0x00050040
|| U.y[2] != 0x00010000
|| U.y[3] != 0x00010600
|| U.y[4] != 0x00014001
|| U.y[5] != 0x00000000)
abort();
return 0;
}
|