struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strlen-3.c
blob4ca4f34b15cfbee2741147d05f38ff62a2b6758a
1 /*
2 strlen-3.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 a wrong strlen folding
10 starting with r262522
11 Exercise strlen() with a multi-dimensional array of strings with
12 embedded nuls. */
14 extern size_t strlen (const char*);
16 static const char a[2][3][9] = {
17 { "1", "1\0002" },
18 { "12\0003", "123\0004" }
21 volatile int v0 = 0;
22 volatile int v1 = 1;
23 volatile int v2 = 2;
24 volatile int v3 = 3;
25 volatile int v4 = 4;
26 volatile int v5 = 5;
27 volatile int v6 = 6;
28 volatile int v7 = 7;
30 void test_array_ref (void)
32 int i0 = 0;
33 int i1 = i0 + 1;
34 int i2 = i1 + 1;
35 int i3 = i2 + 1;
36 int i4 = i3 + 1;
37 int i5 = i4 + 1;
38 int i6 = i5 + 1;
39 int i7 = i6 + 1;
41 ASSERT (strlen (a[0][0]) == 1);
42 ASSERT (strlen (a[0][1]) == 1);
44 ASSERT (strlen (a[1][0]) == 2);
45 ASSERT (strlen (a[1][1]) == 3);
47 ASSERT (strlen (&a[0][0][0]) == 1);
48 ASSERT (strlen (&a[0][1][0]) == 1);
50 ASSERT (strlen (&a[1][0][0]) == 2);
51 ASSERT (strlen (&a[1][1][0]) == 3);
53 ASSERT (strlen (&a[0][0][0] + 1) == 0);
54 ASSERT (strlen (&a[0][1][0] + 1) == 0);
55 ASSERT (strlen (&a[0][1][0] + 2) == 1);
56 ASSERT (strlen (&a[0][1][0] + 3) == 0);
57 ASSERT (strlen (&a[0][1][0] + 7) == 0);
59 ASSERT (strlen (&a[1][0][0] + 1) == 1);
60 ASSERT (strlen (&a[1][1][0] + 1) == 2);
61 ASSERT (strlen (&a[1][1][0] + 2) == 1);
62 ASSERT (strlen (&a[1][1][0] + 7) == 0);
64 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of code memory
65 ASSERT (strlen (a[i0][i0]) == 1);
66 ASSERT (strlen (a[i0][i1]) == 1);
68 ASSERT (strlen (a[i1][i0]) == 2);
69 ASSERT (strlen (a[i1][i1]) == 3);
71 ASSERT (strlen (&a[i0][i0][i0]) == 1);
72 ASSERT (strlen (&a[i0][i1][i0]) == 1);
73 ASSERT (strlen (&a[i0][i1][i1]) == 0);
74 ASSERT (strlen (&a[i0][i1][i2]) == 1);
75 ASSERT (strlen (&a[i0][i1][i3]) == 0);
76 ASSERT (strlen (&a[i0][i1][i3]) == 0);
78 ASSERT (strlen (&a[i1][i0][i0]) == 2);
79 ASSERT (strlen (&a[i1][i1][i0]) == 3);
80 ASSERT (strlen (&a[i1][i1][i1]) == 2);
81 ASSERT (strlen (&a[i1][i1][i2]) == 1);
82 ASSERT (strlen (&a[i1][i1][i3]) == 0);
83 ASSERT (strlen (&a[i1][i1][i4]) == 1);
84 ASSERT (strlen (&a[i1][i1][i5]) == 0);
85 ASSERT (strlen (&a[i1][i1][i6]) == 0);
86 ASSERT (strlen (&a[i1][i1][i7]) == 0);
88 ASSERT (strlen (&a[i0][i0][i0] + i1) == 0);
89 ASSERT (strlen (&a[i0][i1][i0] + i1) == 0);
90 ASSERT (strlen (&a[i0][i1][i0] + i7) == 0);
92 ASSERT (strlen (&a[i1][i0][i0] + i1) == 1);
93 ASSERT (strlen (&a[i1][i1][i0] + i1) == 2);
94 ASSERT (strlen (&a[i1][i1][i0] + i2) == 1);
95 ASSERT (strlen (&a[i1][i1][i0] + i3) == 0);
96 ASSERT (strlen (&a[i1][i1][i0] + i4) == 1);
97 ASSERT (strlen (&a[i1][i1][i0] + i5) == 0);
98 ASSERT (strlen (&a[i1][i1][i0] + i6) == 0);
99 ASSERT (strlen (&a[i1][i1][i0] + i7) == 0);
102 ASSERT (strlen (a[i0][i0]) == 1);
103 ASSERT (strlen (a[i0][i1]) == 1);
105 ASSERT (strlen (a[i1][i0]) == 2);
106 ASSERT (strlen (a[i1][i1]) == 3);
108 ASSERT (strlen (&a[i0][i0][i0]) == 1);
109 ASSERT (strlen (&a[i0][i1][i0]) == 1);
111 ASSERT (strlen (&a[i1][i0][i0]) == 2);
112 ASSERT (strlen (&a[i1][i1][i0]) == 3);
114 ASSERT (strlen (&a[i0][i0][i0] + v1) == 0);
115 ASSERT (strlen (&a[i0][i0][i0] + v2) == 0);
116 ASSERT (strlen (&a[i0][i0][i0] + v7) == 0);
118 ASSERT (strlen (&a[i0][i1][i0] + v1) == 0);
119 ASSERT (strlen (&a[i0][i1][i0] + v2) == 1);
120 ASSERT (strlen (&a[i0][i1][i0] + v3) == 0);
122 ASSERT (strlen (&a[i1][i0][i0] + v1) == 1);
123 ASSERT (strlen (&a[i1][i1][i0] + v1) == 2);
124 ASSERT (strlen (&a[i1][i1][i0] + v2) == 1);
125 ASSERT (strlen (&a[i1][i1][i0] + v3) == 0);
126 ASSERT (strlen (&a[i1][i1][i0] + v4) == 1);
127 ASSERT (strlen (&a[i1][i1][i0] + v5) == 0);
128 ASSERT (strlen (&a[i1][i1][i0] + v6) == 0);
129 ASSERT (strlen (&a[i1][i1][i0] + v7) == 0);
130 #endif
133 void
134 testTortureExecute (void)
136 test_array_ref ();