Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-32.c
blob08eb6bc2b082f4048cd57e8633fb900c4ea8cc59
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-strlen" } */
4 #include "strlenopt.h"
6 char temp[30];
7 volatile int v;
9 size_t __attribute__ ((noinline, noclone))
10 f1 (void)
12 char a[30];
13 v += 1;
14 memcpy (a, "1234567", 7);
15 memcpy (a + 7, "89abcdefg", 9);
16 memcpy (a + 16, "h", 2);
17 return strlen (a); // This strlen should be optimized into 17.
20 size_t __attribute__ ((noinline, noclone))
21 f2 (char *a)
23 v += 2;
24 memcpy (a, "1234567", 7);
25 memcpy (a + 7, "89abcdefg", 9);
26 memcpy (a + 16, "h", 2);
27 return strlen (a); // This strlen should be optimized into 17.
30 size_t __attribute__ ((noinline, noclone))
31 f3 (void)
33 char a[30];
34 v += 3;
35 a[0] = '1';
36 memcpy (a + 1, "2345678", 8);
37 return strlen (a); // This strlen should be optimized into 8.
40 size_t __attribute__ ((noinline, noclone))
41 f4 (char *a)
43 v += 4;
44 a[0] = '1';
45 memcpy (a + 1, "2345678", 8);
46 return strlen (a); // This strlen should be optimized into 8.
49 size_t __attribute__ ((noinline, noclone))
50 f5 (void)
52 char a[30];
53 v += 5;
54 a[0] = '1';
55 a[1] = '2';
56 a[2] = '3';
57 memcpy (a + 3, "456", 3);
58 a[6] = '7';
59 a[7] = 0;
60 return strlen (a); // This strlen should be optimized into 7.
63 size_t __attribute__ ((noinline, noclone))
64 f6 (char *a)
66 v += 6;
67 a[0] = '1';
68 a[1] = '2';
69 a[2] = '3';
70 memcpy (a + 3, "456", 3);
71 a[6] = '7';
72 a[7] = 0;
73 return strlen (a); // This strlen should be optimized into 7.
76 size_t __attribute__ ((noinline, noclone))
77 f7 (void)
79 char a[30];
80 v += 7;
81 strcpy (a, "abcde");
82 int len1 = strlen (a);
83 a[2] = '_';
84 int len2 = strlen (a);
85 return len1 + len2; // This should be optimized into 10.
88 size_t __attribute__ ((noinline, noclone))
89 f8 (char *a)
91 v += 8;
92 strcpy (a, "abcde");
93 int len1 = strlen (a);
94 a[2] = '_';
95 int len2 = strlen (a);
96 return len1 + len2; // This should be optimized into 10.
99 size_t __attribute__ ((noinline, noclone))
100 f9 (char b)
102 char a[30];
103 v += 9;
104 strcpy (a, "foo.bar");
105 a[4] = b;
106 a[3] = 0;
107 return strlen (a); // This should be optimized into 3.
110 size_t __attribute__ ((noinline, noclone))
111 f10 (char *a, char b)
113 v += 10;
114 strcpy (a, "foo.bar");
115 a[4] = b;
116 a[3] = 0;
117 return strlen (a); // This should be optimized into 3.
120 size_t __attribute__ ((noinline, noclone))
121 f11 (void)
123 char a[30];
124 v += 11;
125 strcpy (temp, "123456");
126 memcpy (a, temp, 7);
127 return strlen (a); // This should be optimized into 6.
130 size_t __attribute__ ((noinline, noclone))
131 f12 (char *a)
133 v += 12;
134 strcpy (temp, "123456");
135 memcpy (a, temp, 7);
136 return strlen (a); // This should be optimized into 6.
139 size_t __attribute__ ((noinline, noclone))
140 f13 (void)
142 char a[30];
143 v += 13;
144 strcpy (temp, "1234567");
145 memcpy (a, temp, 7);
146 a[7] = 0;
147 return strlen (a); // This should be optimized into 7.
150 size_t __attribute__ ((noinline, noclone))
151 f14 (char *a)
153 v += 14;
154 strcpy (temp, "1234567");
155 memcpy (a, temp, 7);
156 a[7] = 0;
157 return strlen (a); // This should be optimized into 7.
160 size_t __attribute__ ((noinline, noclone))
161 f15 (void)
163 char a[30];
164 v += 15;
165 strcpy (temp, "12345679");
166 memcpy (a, temp, 7);
167 a[7] = 0;
168 return strlen (a); // This should be optimized into 7.
171 size_t __attribute__ ((noinline, noclone))
172 f16 (char *a)
174 v += 16;
175 strcpy (temp, "123456789");
176 memcpy (a, temp, 7);
177 a[7] = 0;
178 return strlen (a); // This should be optimized into 7.
182 main ()
184 char a[30];
185 if (f1 () != 17 || f2 (a) != 17 || f3 () != 8 || f4 (a) != 8
186 || f5 () != 7 || f6 (a) != 7 || f7 () != 10 || f8 (a) != 10
187 || f9 ('_') != 3 || f10 (a, '_') != 3 || f11 () != 6 || f12 (a) != 6
188 || f13 () != 7 || f14 (a) != 7 || f15 () != 7 || f16 (a) != 7)
189 abort ();
190 return 0;
193 /* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } */