struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strlen-4.c
blob5f26926d7c719e443b0794cdc325c7dbb064ecca
1 /*
2 strlen-4.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #include <stddef.h>
9 /* PR tree-optimization/86622 - incorrect strlen of array of array plus
10 variable offset
11 Exercise strlen() with a multi-dimensional array of strings with
12 offsets. */
14 extern size_t strlen (const char*);
16 typedef char A28[28];
17 typedef A28 A3_28[3];
18 typedef A3_28 A2_3_28[2];
20 static const A2_3_28 a = {
21 /* [0][0] [0][1] [0][2] */
22 { "1\00012", "123\0001234", "12345\000123456" },
23 /* [1][0] [1][1] [1][2] */
24 { "1234567\00012345678", "123456789\0001234567890", "12345678901\000123456789012" }
27 volatile int v0 = 0;
28 volatile int v1 = 1;
29 volatile int v2 = 2;
30 volatile int v3 = 3;
31 volatile int v4 = 4;
32 volatile int v5 = 5;
33 volatile int v6 = 6;
34 volatile int v7 = 7;
36 #define A(expr, N) ASSERT (strlen (expr) == N)
38 /* Verify that strlen() involving pointer to array arguments computes
39 the correct result. */
41 void test_array_ptr (void)
43 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
44 /* Compute the length of the string at the refeenced array. */
45 A (*(&a[0][0] + 0), 1);
46 A (*(&a[0][0] + 1), 3);
47 A (*(&a[0][0] + 2), 5);
49 A (*(&a[0][1] - 1), 1);
50 A (*(&a[0][1] + 0), 3);
51 A (*(&a[0][1] + 1), 5);
53 A (*(&a[0][2] - 2), 1);
54 A (*(&a[0][2] - 1), 3);
55 A (*(&a[0][2] + 0), 5);
57 A (*(&a[1][0] + 0), 7);
58 A (*(&a[1][0] + 1), 9);
59 A (*(&a[1][0] + 2), 11);
61 A (*(&a[1][1] - 1), 7);
62 A (*(&a[1][1] + 0), 9);
63 A (*(&a[1][1] + 1), 11);
65 A (*(&a[1][2] - 2), 7);
66 A (*(&a[1][2] - 1), 9);
67 A (*(&a[1][2] - 0), 11);
69 /* Compute the length of the string past the first nul. */
70 A (*(&a[0][0] + 0) + 2, 2);
71 A (*(&a[0][0] + 1) + 4, 4);
72 A (*(&a[0][0] + 2) + 6, 6);
74 /* Compute the length of the string past the second nul. */
75 A (*(&a[0][0] + 0) + 5, 0);
76 A (*(&a[0][0] + 1) + 10, 0);
77 A (*(&a[0][0] + 2) + 14, 0);
79 int i0 = 0;
80 int i1 = i0 + 1;
81 int i2 = i1 + 1;
82 int i3 = i2 + 1;
83 int i4 = i3 + 1;
84 int i5 = i4 + 1;
86 A (*(&a[0][0] + i0), 1);
87 A (*(&a[0][0] + i1), 3);
88 A (*(&a[0][0] + i2), 5);
90 A (*(&a[0][1] - i1), 1);
91 A (*(&a[0][1] + i0), 3);
92 A (*(&a[0][1] + i1), 5);
94 A (*(&a[0][2] - i2), 1);
95 A (*(&a[0][2] - i1), 3);
96 A (*(&a[0][2] + i0), 5);
98 A (*(&a[1][0] + i0), 7);
99 A (*(&a[1][0] + i1), 9);
100 A (*(&a[1][0] + i2), 11);
102 A (*(&a[1][1] - i1), 7);
103 A (*(&a[1][1] + i0), 9);
104 A (*(&a[1][1] + i1), 11);
106 A (*(&a[1][2] - i2), 7);
107 A (*(&a[1][2] - i1), 9);
108 A (*(&a[1][2] - i0), 11);
111 A (*(&a[i0][i0] + i0), 1);
112 A (*(&a[i0][i0] + i1), 3);
113 A (*(&a[i0][i0] + i2), 5);
115 A (*(&a[i0][i1] - i1), 1);
116 A (*(&a[i0][i1] + i0), 3);
117 A (*(&a[i0][i1] + i1), 5);
119 A (*(&a[i0][i2] - i2), 1);
120 A (*(&a[i0][i2] - i1), 3);
121 A (*(&a[i0][i2] + i0), 5);
123 A (*(&a[i1][i0] + i0), 7);
124 A (*(&a[i1][i0] + i1), 9);
125 A (*(&a[i1][i0] + i2), 11);
127 A (*(&a[i1][i1] - i1), 7);
128 A (*(&a[i1][i1] + i0), 9);
129 A (*(&a[i1][i1] + i1), 11);
131 A (*(&a[i1][i2] - i2), 7);
132 A (*(&a[i1][i2] - i1), 9);
133 A (*(&a[i1][i2] - i0), 11);
136 A (*(&a[i0][i0] + v0), 1);
137 A (*(&a[i0][i0] + v1), 3);
138 A (*(&a[i0][i0] + v2), 5);
140 A (*(&a[i0][i1] - v1), 1);
141 A (*(&a[i0][i1] + v0), 3);
142 A (*(&a[i0][i1] + v1), 5);
144 A (*(&a[i0][i2] - v2), 1);
145 A (*(&a[i0][i2] - v1), 3);
146 A (*(&a[i0][i2] + v0), 5);
148 A (*(&a[i1][i0] + v0), 7);
149 A (*(&a[i1][i0] + v1), 9);
150 A (*(&a[i1][i0] + v2), 11);
152 A (*(&a[i1][i1] - v1), 7);
153 A (*(&a[i1][i1] + v0), 9);
154 A (*(&a[i1][i1] + v1), 11);
156 A (*(&a[i1][i2] - v2), 7);
157 A (*(&a[i1][i2] - v1), 9);
158 A (*(&a[i1][i2] - v0), 11);
161 A (*(&a[i0][i0] + v0) + i1, 0);
162 A (*(&a[i0][i0] + v1) + i2, 1);
163 A (*(&a[i0][i0] + v2) + i3, 2);
165 A (*(&a[i0][i1] - v1) + v1, 0);
166 A (*(&a[i0][i1] + v0) + v3, 0);
167 A (*(&a[i0][i1] + v1) + v5, 0);
169 A (*(&a[i0][v1] - i1) + i1, 0);
170 A (*(&a[i0][v1] + i0) + i3, 0);
171 A (*(&a[i0][v1] + i1) + i5, 0);
172 #endif
175 static const A3_28* const pa0 = &a[0];
176 static const A3_28* const pa1 = &a[1];
178 static const A3_28* const paa[] = { &a[0], &a[1] };
180 /* Verify that strlen() involving pointers and arrays of pointers
181 to array arguments computes the correct result. */
183 void test_ptr_array (void)
185 int i0 = 0;
186 int i1 = i0 + 1;
187 int i2 = i1 + 1;
188 int i3 = i2 + 1;
190 A (*((*pa0) + i0), 1);
191 A (*((*pa0) + i1), 3);
192 A (*((*pa0) + i2), 5);
194 A (*(pa0[0] + i0), 1);
195 A (*(pa0[0] + i1), 3);
196 A (*(pa0[0] + i2), 5);
198 A ((*pa0)[i0] + i1, 0);
199 A ((*pa0)[i1] + i2, 1);
200 A ((*pa0)[i2] + i3, 2);
202 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
203 A (*((*pa1) + i0), 7);
204 A (*((*pa1) + i1), 9);
205 A (*((*pa1) + i2), 11);
207 A (*(pa1[0] + i0), 7);
208 A (*(pa1[0] + i1), 9);
209 A (*(pa1[0] + i2), 11);
211 A ((*pa1)[i0] + i1, 6);
212 A ((*pa1)[i1] + i2, 7);
213 A ((*pa1)[i2] + i3, 8);
215 A (*(*(paa[0]) + i0), 1);
216 A (*(*(paa[0]) + i1), 3);
217 A (*(*(paa[0]) + i2), 5);
219 A (*(*(paa[1]) + i0), 7);
220 A (*(*(paa[1]) + i1), 9);
221 A (*(*(paa[1]) + i2), 11);
222 #if 0 // Bug #2987
223 A (*(*(paa[1]) - i1), 5);
224 A (*(*(paa[1]) - i2), 3);
225 A (*(*(paa[1]) - i3), 1);
226 #endif
227 A (*(*(paa[0]) + i0) + i1, 0);
228 A (*(*(paa[0]) + i1) + i2, 1);
229 A (*(*(paa[0]) + i2) + i3, 2);
230 #endif
233 void
234 testTortureExecute (void)
236 test_array_ptr ();
238 test_ptr_array ();