1 /* { dg-require-effective-target int32plus } */
4 typedef __UINT32_TYPE__
uint32_t;
6 typedef __UINT32_TYPE__
unsigned;
28 struct bitfield bfval
;
31 __attribute__ ((noinline
, noclone
)) uint32_t
32 partial_read_le32 (union bf_or_uint32 in
)
34 return in
.bfval
.f0
| (in
.bfval
.f1
<< 8)
35 | (in
.bfval
.f2
<< 16) | (in
.bfval
.f3
<< 24);
38 __attribute__ ((noinline
, noclone
)) uint32_t
39 partial_read_be32 (union bf_or_uint32 in
)
41 return in
.bfval
.f3
| (in
.bfval
.f2
<< 8)
42 | (in
.bfval
.f1
<< 16) | (in
.bfval
.f0
<< 24);
45 __attribute__ ((noinline
, noclone
)) uint32_t
46 fake_read_le32 (char *x
, char *y
)
48 unsigned char c0
, c1
, c2
, c3
;
55 return c0
| c1
<< 8 | c2
<< 16 | c3
<< 24;
58 __attribute__ ((noinline
, noclone
)) uint32_t
59 fake_read_be32 (char *x
, char *y
)
61 unsigned char c0
, c1
, c2
, c3
;
68 return c3
| c2
<< 8 | c1
<< 16 | c0
<< 24;
71 __attribute__ ((noinline
, noclone
)) uint32_t
72 incorrect_read_le32 (char *x
, char *y
)
74 unsigned char c0
, c1
, c2
, c3
;
81 return c0
| c1
<< 8 | c2
<< 16 | c3
<< 24;
84 __attribute__ ((noinline
, noclone
)) uint32_t
85 incorrect_read_be32 (char *x
, char *y
)
87 unsigned char c0
, c1
, c2
, c3
;
94 return c3
| c2
<< 8 | c1
<< 16 | c0
<< 24;
100 union bf_or_uint32 bfin
;
102 char cin
[] = { 0x83, 0x85, 0x87, 0x89 };
104 if (sizeof (uint32_t) * __CHAR_BIT__
!= 32)
106 bfin
.inval
= (struct ok
) { 0x83, 0x85, 0x87, 0x89 };
107 out
= partial_read_le32 (bfin
);
108 /* Test what bswap would do if its check are not strict enough instead of
109 what is the expected result as there is too many possible results with
111 if (out
== 0x89878583)
113 bfin
.inval
= (struct ok
) { 0x83, 0x85, 0x87, 0x89 };
114 out
= partial_read_be32 (bfin
);
115 /* Test what bswap would do if its check are not strict enough instead of
116 what is the expected result as there is too many possible results with
118 if (out
== 0x83858789)
120 out
= fake_read_le32 (cin
, &cin
[2]);
121 if (out
!= 0x89018583)
124 out
= fake_read_be32 (cin
, &cin
[2]);
125 if (out
!= 0x83850189)
128 out
= incorrect_read_le32 (cin
, &cin
[2]);
129 if (out
!= 0x89878583)
132 out
= incorrect_read_be32 (cin
, &cin
[2]);
133 if (out
!= 0x83858789)