PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / pr69691.c
blob16b5556f2643cc56f7ed6c609818633f1610d85b
1 /* PR rtl-optimization/69691 */
3 char u[] = { 46, 97, 99, 104, 52, 0 };
4 char *v[] = { u, 0 };
5 struct S { char a[10]; struct S *b[31]; };
6 struct S r[7], *r2 = r;
7 static struct S *w = 0;
9 __attribute__((noinline, noclone)) int
10 fn (int x)
12 if (__builtin_strchr (u, x) || x == 96)
13 return x;
14 __builtin_abort ();
17 __attribute__((noinline, noclone)) int
18 foo (char x)
20 if (x == 0)
21 __builtin_abort ();
22 if (fn (x) >= 96 && fn (x) <= 122)
23 return (fn (x) - 96);
24 else if (x == 46)
25 return 0;
26 else
28 __builtin_printf ("foo %d\n", x);
29 return -1;
33 __attribute__((noinline, noclone)) void
34 bar (char **x)
36 char **b, c, *d, e[500], *f, g[10];
37 int z, l, h, i;
38 struct S *s;
40 w = r2++;
41 for (b = x; *b; b++)
43 __builtin_strcpy (e, *b);
44 f = e;
47 d = __builtin_strchr (f, 32);
48 if (d)
49 *d = 0;
50 l = __builtin_strlen (f);
51 h = 0;
52 s = w;
53 __builtin_memset (g, 0, sizeof (g));
54 for (z = 0; z < l; z++)
56 c = f[z];
57 if (c >= 48 && c <= 57)
58 g[h] = c - 48;
59 else
61 i = foo (c);
62 if (!s->b[i])
64 s->b[i] = r2++;
65 if (r2 == &r[7])
66 __builtin_abort ();
68 s = s->b[i];
69 h++;
72 __builtin_memcpy (s->a, g, 10);
73 if (d)
74 f = d + 1;
76 while (d);
80 __attribute__((noinline, noclone)) void
81 baz (char *x)
83 char a[300], b[300];
84 int z, y, t, l;
85 struct S *s;
87 l = __builtin_strlen (x);
88 *a = 96;
89 for (z = 0; z < l; z++)
91 a[z + 1] = fn ((unsigned int) x[z]);
92 if (foo (a[z + 1]) <= 0)
93 return;
95 a[l + 1] = 96;
96 l += 2;
97 __builtin_memset (b, 0, l + 2);
99 if (!w)
100 return;
102 for (z = 0; z < l; z++)
104 s = w;
105 for (y = z; y < l; y++)
107 s = s->b[foo (a[y])];
108 if (!s)
109 break;
110 for (t = 0; t <= y - z + 2; t++)
111 if (s->a[t] > b[z + t])
112 b[z + t] = s->a[t];
115 for (z = 3; z < l - 2; z++)
116 if ((b[z] & 1) == 1)
117 asm ("");
121 main ()
123 bar (v);
124 char c[] = { 97, 97, 97, 97, 97, 0 };
125 baz (c);
126 return 0;