struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strlen-2.c
blobe9ac16f50590861db1d977862ff83d70b994af31
1 /*
2 strlen-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #include <stddef.h>
9 /* PR tree-optimization/86532 - Wrong code due to ASSERT wrong strlen folding */
11 extern size_t strlen (const char*);
13 static const char a[2][3] = { "1", "12" };
14 static const char b[2][2][5] = { { "1", "12" }, { "123", "1234" } };
16 volatile int v0 = 0;
17 volatile int v1 = 1;
18 volatile int v2 = 2;
20 void test_array_ref_2_3 (void)
22 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !(defined(__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
23 ASSERT (strlen (a[v0]) == 1);
24 ASSERT (strlen (&a[v0][v0]) == 1);
25 ASSERT (strlen (&a[0][v0]) == 1);
26 ASSERT (strlen (&a[v0][0]) == 1);
28 ASSERT (strlen (a[v1]) == 2);
29 ASSERT (strlen (&a[v1][0]) == 2);
30 ASSERT (strlen (&a[1][v0]) == 2);
31 ASSERT (strlen (&a[v1][v0]) == 2);
33 ASSERT (strlen (&a[v1][1]) == 1);
34 ASSERT (strlen (&a[v1][1]) == 1);
36 ASSERT (strlen (&a[v1][2]) == 0);
37 ASSERT (strlen (&a[v1][v2]) == 0);
39 int i0 = 0;
40 int i1 = i0 + 1;
41 int i2 = i1 + 1;
43 ASSERT (strlen (a[v0]) == 1);
44 ASSERT (strlen (&a[v0][v0]) == 1);
45 ASSERT (strlen (&a[i0][v0]) == 1);
46 ASSERT (strlen (&a[v0][i0]) == 1);
48 ASSERT (strlen (a[v1]) == 2);
49 ASSERT (strlen (&a[v1][i0]) == 2);
50 ASSERT (strlen (&a[i1][v0]) == 2);
51 ASSERT (strlen (&a[v1][v0]) == 2);
53 ASSERT (strlen (&a[v1][i1]) == 1);
54 ASSERT (strlen (&a[v1][i1]) == 1);
56 ASSERT (strlen (&a[v1][i2]) == 0);
57 ASSERT (strlen (&a[v1][v2]) == 0);
58 #endif
61 void test_array_off_2_3 (void)
63 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !(defined(__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
64 ASSERT (strlen (a[0] + 0) == 1);
65 ASSERT (strlen (a[0] + v0) == 1);
66 ASSERT (strlen (a[v0] + 0) == 1);
67 ASSERT (strlen (a[v0] + v0) == 1);
69 ASSERT (strlen (a[v1] + 0) == 2);
70 ASSERT (strlen (a[1] + v0) == 2);
71 ASSERT (strlen (a[v1] + 0) == 2);
72 ASSERT (strlen (a[v1] + v0) == 2);
74 ASSERT (strlen (a[v1] + 1) == 1);
75 ASSERT (strlen (a[v1] + v1) == 1);
77 ASSERT (strlen (a[v1] + 2) == 0);
78 ASSERT (strlen (a[v1] + v2) == 0);
80 int i0 = 0;
81 int i1 = i0 + 1;
82 int i2 = i1 + 1;
84 ASSERT (strlen (a[i0] + i0) == 1);
85 ASSERT (strlen (a[i0] + v0) == 1);
86 ASSERT (strlen (a[v0] + i0) == 1);
87 ASSERT (strlen (a[v0] + v0) == 1);
89 ASSERT (strlen (a[v1] + i0) == 2);
90 ASSERT (strlen (a[i1] + v0) == 2);
91 ASSERT (strlen (a[v1] + i0) == 2);
92 ASSERT (strlen (a[v1] + v0) == 2);
94 ASSERT (strlen (a[v1] + i1) == 1);
95 ASSERT (strlen (a[v1] + v1) == 1);
97 ASSERT (strlen (a[v1] + i2) == 0);
98 ASSERT (strlen (a[v1] + v2) == 0);
99 #endif
102 void test_array_ref_2_2_5 (void)
104 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of code memory
105 ASSERT (strlen (b[0][v0]) == 1);
106 ASSERT (strlen (b[v0][0]) == 1);
108 ASSERT (strlen (&b[0][0][v0]) == 1);
109 ASSERT (strlen (&b[0][v0][0]) == 1);
110 ASSERT (strlen (&b[v0][0][0]) == 1);
112 ASSERT (strlen (&b[0][v0][v0]) == 1);
113 ASSERT (strlen (&b[v0][0][v0]) == 1);
114 ASSERT (strlen (&b[v0][v0][0]) == 1);
116 ASSERT (strlen (b[0][v1]) == 2);
117 ASSERT (strlen (b[v1][0]) == 3);
119 ASSERT (strlen (&b[0][0][v1]) == 0);
120 ASSERT (strlen (&b[0][v1][0]) == 2);
121 ASSERT (strlen (&b[v0][0][0]) == 1);
123 ASSERT (strlen (&b[0][v0][v0]) == 1);
124 ASSERT (strlen (&b[v0][0][v0]) == 1);
125 ASSERT (strlen (&b[v0][v0][0]) == 1);
127 ASSERT (strlen (&b[0][v1][v1]) == 1);
128 ASSERT (strlen (&b[v1][0][v1]) == 2);
129 ASSERT (strlen (&b[v1][v1][0]) == 4);
130 ASSERT (strlen (&b[v1][v1][1]) == 3);
131 ASSERT (strlen (&b[v1][v1][2]) == 2);
133 int i0 = 0;
134 int i1 = i0 + 1;
135 int i2 = i1 + 1;
137 ASSERT (strlen (b[i0][v0]) == 1);
138 ASSERT (strlen (b[v0][i0]) == 1);
140 ASSERT (strlen (&b[i0][i0][v0]) == 1);
141 ASSERT (strlen (&b[i0][v0][i0]) == 1);
142 ASSERT (strlen (&b[v0][i0][i0]) == 1);
144 ASSERT (strlen (&b[i0][v0][v0]) == 1);
145 ASSERT (strlen (&b[v0][i0][v0]) == 1);
146 ASSERT (strlen (&b[v0][v0][i0]) == 1);
148 ASSERT (strlen (b[i0][v1]) == 2);
149 ASSERT (strlen (b[v1][i0]) == 3);
151 ASSERT (strlen (&b[i0][i0][v1]) == 0);
152 ASSERT (strlen (&b[i0][v1][i0]) == 2);
153 ASSERT (strlen (&b[v0][i0][i0]) == 1);
155 ASSERT (strlen (&b[i0][v0][v0]) == 1);
156 ASSERT (strlen (&b[v0][i0][v0]) == 1);
157 ASSERT (strlen (&b[v0][v0][i0]) == 1);
159 ASSERT (strlen (&b[i0][v1][v1]) == 1);
160 ASSERT (strlen (&b[v1][i0][v1]) == 2);
161 ASSERT (strlen (&b[v1][v1][i0]) == 4);
162 ASSERT (strlen (&b[v1][v1][i1]) == 3);
163 ASSERT (strlen (&b[v1][v1][i2]) == 2);
164 #endif
167 void test_array_off_2_2_5 (void)
169 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of code memory
170 ASSERT (strlen (b[0][0] + v0) == 1);
171 ASSERT (strlen (b[0][v0] + v0) == 1);
172 ASSERT (strlen (b[v0][0] + v0) == 1);
173 ASSERT (strlen (b[v0][v0] + v0) == 1);
175 ASSERT (strlen (b[0][0] + v1) == 0);
176 ASSERT (strlen (b[0][v1] + 0) == 2);
177 ASSERT (strlen (b[v0][0] + 0) == 1);
179 ASSERT (strlen (b[0][v0] + v0) == 1);
180 ASSERT (strlen (b[v0][0] + v0) == 1);
181 ASSERT (strlen (b[v0][v0] + 0) == 1);
183 ASSERT (strlen (b[0][v1] + v1) == 1);
184 ASSERT (strlen (b[v1][0] + v1) == 2);
185 ASSERT (strlen (b[v1][v1] + 0) == 4);
186 ASSERT (strlen (b[v1][v1] + 1) == 3);
187 ASSERT (strlen (b[v1][v1] + 2) == 2);
189 int i0 = 0;
190 int i1 = i0 + 1;
191 int i2 = i1 + 1;
193 ASSERT (strlen (b[i0][i0] + v0) == 1);
194 ASSERT (strlen (b[i0][v0] + v0) == 1);
195 ASSERT (strlen (b[v0][i0] + v0) == 1);
196 ASSERT (strlen (b[v0][v0] + v0) == 1);
198 ASSERT (strlen (b[i0][i0] + v1) == 0);
199 ASSERT (strlen (b[i0][v1] + i0) == 2);
200 ASSERT (strlen (b[v0][i0] + i0) == 1);
202 ASSERT (strlen (b[i0][v0] + v0) == 1);
203 ASSERT (strlen (b[v0][i0] + v0) == 1);
204 ASSERT (strlen (b[v0][v0] + i0) == 1);
206 ASSERT (strlen (b[i0][v1] + v1) == 1);
207 ASSERT (strlen (b[v1][i0] + v1) == 2);
208 ASSERT (strlen (b[v1][v1] + i0) == 4);
209 ASSERT (strlen (b[v1][v1] + i1) == 3);
210 ASSERT (strlen (b[v1][v1] + i2) == 2);
211 #endif
214 void
215 testTortureExecute (void)
217 test_array_ref_2_3 ();
218 test_array_off_2_3 ();
220 test_array_ref_2_2_5 ();
221 test_array_off_2_2_5 ();