struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr42833.c
blobd84810de3602fd72162cf05084f7f39b49dff924
1 /*
2 pr42833.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <stdint.h>
12 #include <string.h>
13 #include <limits.h>
15 /* If SSIZE_MAX is defined in limits.h, then we are running in a POSIX */
16 /* environment that already has a ssize_t definition (which may have been */
17 /* included indirectly via string.h). In this case, use the guaranteed */
18 /* definition in sys/types.h, otherwise assume int compatible and hope */
19 /* for the best. */
20 #ifdef SSIZE_MAX
21 #include <sys/types.h>
22 #else
23 typedef int ssize_t;
24 #endif
26 #ifndef __SDCC_pdk14 // Lack of memory
27 typedef struct { int8_t v1; int8_t v2; int8_t v3; int8_t v4; } neon_s8;
29 uint32_t helper_neon_rshl_s8 (uint32_t arg1, uint32_t arg2);
31 uint32_t
32 helper_neon_rshl_s8 (uint32_t arg1, uint32_t arg2)
34 uint32_t res;
35 neon_s8 vsrc1;
36 neon_s8 vsrc2;
37 neon_s8 vdest;
40 union
42 neon_s8 v;
43 uint32_t i;
44 } conv_u;
45 conv_u.i = (arg1);
46 /*vsrc1 = conv_u.v; not in sdcc */
47 memcpy (&vsrc1, &(conv_u.v), sizeof (neon_s8));
49 while (0);
52 union
54 neon_s8 v;
55 uint32_t i;
56 } conv_u;
57 conv_u.i = (arg2);
58 /*vsrc2 = conv_u.v; not in sdcc*/
59 memcpy (&vsrc2, &(conv_u.v), sizeof (neon_s8));
61 while (0);
64 int8_t tmp;
65 tmp = (int8_t) vsrc2.v1;
66 if (tmp >= (ssize_t) sizeof (vsrc1.v1) * 8)
68 vdest.v1 = 0;
70 else if (tmp < -(ssize_t) sizeof (vsrc1.v1) * 8)
72 vdest.v1 = vsrc1.v1 >> (sizeof (vsrc1.v1) * 8 - 1);
74 else if (tmp == -(ssize_t) sizeof (vsrc1.v1) * 8)
76 vdest.v1 = vsrc1.v1 >> (tmp - 1);
77 vdest.v1++;
78 vdest.v1 >>= 1;
80 else if (tmp < 0)
82 vdest.v1 = (vsrc1.v1 + (1 << (-1 - tmp))) >> -tmp;
84 else
86 vdest.v1 = vsrc1.v1 << tmp;
89 while (0);
92 int8_t tmp;
93 tmp = (int8_t) vsrc2.v2;
94 if (tmp >= (ssize_t) sizeof (vsrc1.v2) * 8)
96 vdest.v2 = 0;
98 else if (tmp < -(ssize_t) sizeof (vsrc1.v2) * 8)
100 vdest.v2 = vsrc1.v2 >> (sizeof (vsrc1.v2) * 8 - 1);
102 else if (tmp == -(ssize_t) sizeof (vsrc1.v2) * 8)
104 vdest.v2 = vsrc1.v2 >> (tmp - 1);
105 vdest.v2++;
106 vdest.v2 >>= 1;
108 else if (tmp < 0)
110 vdest.v2 = (vsrc1.v2 + (1 << (-1 - tmp))) >> -tmp;
112 else
114 vdest.v2 = vsrc1.v2 << tmp;
117 while (0);
120 int8_t tmp;
121 tmp = (int8_t) vsrc2.v3;
122 if (tmp >= (ssize_t) sizeof (vsrc1.v3) * 8)
124 vdest.v3 = 0;
126 else if (tmp < -(ssize_t) sizeof (vsrc1.v3) * 8)
128 vdest.v3 = vsrc1.v3 >> (sizeof (vsrc1.v3) * 8 - 1);
130 else if (tmp == -(ssize_t) sizeof (vsrc1.v3) * 8)
132 vdest.v3 = vsrc1.v3 >> (tmp - 1);
133 vdest.v3++;
134 vdest.v3 >>= 1;
136 else if (tmp < 0)
138 vdest.v3 = (vsrc1.v3 + (1 << (-1 - tmp))) >> -tmp;
140 else
142 vdest.v3 = vsrc1.v3 << tmp;
145 while (0);
148 int8_t tmp;
149 tmp = (int8_t) vsrc2.v4;
150 if (tmp >= (ssize_t) sizeof (vsrc1.v4) * 8)
152 vdest.v4 = 0;
154 else if (tmp < -(ssize_t) sizeof (vsrc1.v4) * 8)
156 vdest.v4 = vsrc1.v4 >> (sizeof (vsrc1.v4) * 8 - 1);
158 else if (tmp == -(ssize_t) sizeof (vsrc1.v4) * 8)
160 vdest.v4 = vsrc1.v4 >> (tmp - 1);
161 vdest.v4++;
162 vdest.v4 >>= 1;
164 else if (tmp < 0)
166 vdest.v4 = (vsrc1.v4 + (1 << (-1 - tmp))) >> -tmp;
168 else
170 vdest.v4 = vsrc1.v4 << tmp;
173 while (0);;
176 union
178 neon_s8 v;
179 uint32_t i;
180 } conv_u;
181 /*conv_u.v = (vdest) not in sdcc */;
182 memcpy (&conv_u.v, &(vdest), sizeof (neon_s8));
183 res = conv_u.i;
185 while (0);
186 return res;
188 #endif
190 void
191 testTortureExecute (void)
193 #if !(defined(__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Bug #2939
194 #ifndef __SDCC_pdk14 // Lack of memory
195 #if !(defined (__GNUC__) && __GNUC__ < 5)
196 uint32_t r = helper_neon_rshl_s8 (0x05050505, 0x01010101);
197 if (r != 0x0a0a0a0a)
198 ASSERT (0);
199 return;
200 #endif
201 #endif
202 #endif