aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.apple/bitreverse-16.c
blob: ee9876b02aae9a7ed7baae913b53d30f9ae7478e (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
/* APPLE LOCAL file 4401224 */
extern void abort();
/* { dg-do run { target powerpc*-*-darwin* } } */
/* { dg-options "-std=gnu99" } */
#pragma reverse_bitfields on

#pragma pack(push,2)
typedef struct _S5
{
        unsigned short s;
        unsigned int lbf1 : 8;
        unsigned int lbf2 : 8;
        unsigned int lbf3 : 8;
        unsigned int lbf4 : 8;
} S5;
#pragma pack(pop)

void TestS5_1(void)
{
        S5 s5 = {0};
        unsigned char * rgb = (unsigned char *) &s5;

        rgb[0] = 0x1;
        rgb[1] = 0x2;
        rgb[2] = 0x3;
        rgb[3] = 0x4;
        rgb[4] = 0x5;
        rgb[5] = 0x6;

	if (s5.lbf1!=6 ||
	    s5.lbf2!=5 ||
	    s5.lbf3!=4 ||
	    s5.lbf4!=3 )
	  abort();
};

void TestS5_2(void)
{
        S5 s5 = {0};
        unsigned char * rgb = (unsigned char *) &s5;

        s5.lbf1 = 0x3;
        s5.lbf2 = 0x4;
        s5.lbf3 = 0x5;
        s5.lbf4 = 0x6;

	if (rgb[2]!=6 ||
	    rgb[3]!=5 ||
	    rgb[4]!=4 ||
	    rgb[5]!=3 )
	  abort();
};



#pragma pack(push,2)

typedef struct _S6
{
        unsigned int lbf1 : 8;
        unsigned int lbf2 : 8;
        unsigned int lbf3 : 8;
        unsigned int lbf4 : 8;
} S6;

#pragma pack(pop)

void TestS6_1(void)
{
        S6 s6 = {0};
        unsigned char * rgb = (unsigned char *) &s6;
        rgb[0] = 0x3;
        rgb[1] = 0x4;
        rgb[2] = 0x5;
        rgb[3] = 0x6;

	if (s6.lbf1!=6 ||
	    s6.lbf2!=5 ||
	    s6.lbf3!=4 ||
	    s6.lbf4!=3 )
	  abort();
};



void TestS6_2(void)
{
        S6 s6 = {0};
        unsigned char * rgb = (unsigned char *) &s6;
        s6.lbf1 = 0x3;
        s6.lbf2 = 0x4;
        s6.lbf3 = 0x5;
        s6.lbf4 = 0x6;
	if (rgb[0]!=6 ||
	    rgb[1]!=5 ||
	    rgb[2]!=4 ||
	    rgb[3]!=3 )
	  abort();
};

int main(void)
{
	if(sizeof(S5)!=6 || sizeof(S6)!=4)
	  abort();
        TestS5_1();
        TestS6_1();
        TestS5_2();
        TestS6_2();
        return 0;
}