Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / strncat.c
blob9b8cf238297e8947f35090f013ae6b7c9f56a4d4
1 /* PR tree-optimization/83075 - Invalid strncpy optimization */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -Wstringop-overflow" } */
5 typedef __SIZE_TYPE__ size_t;
7 __attribute__((noipa)) size_t
8 foo (char *p, char *q, size_t *r)
10 size_t n0 = __builtin_strlen (p);
11 __builtin_strncat (q, p, n0); /* { dg-warning "specified bound depends on the length" } */
12 size_t n1 = __builtin_strlen (p);
13 *r = n0;
14 return n1;
17 int
18 main ()
20 char a[8] = "";
21 __builtin_strcpy (a, "123");
22 size_t n0 = __builtin_strlen (a);
23 __builtin_strncat (a + 3, a, n0); /* { dg-warning "specified bound depends on the length" } */
24 size_t n1 = __builtin_strlen (a);
25 if (n1 == n0)
26 __builtin_abort ();
27 a[6] = '7';
28 __builtin_strcpy (a, "456");
29 size_t n2;
30 if (foo (a, a + 3, &n2) != 6 || n2 != 3)
31 __builtin_abort ();
32 if (__builtin_memcmp (a, "456456\0", sizeof "456456\0"))
33 __builtin_abort ();
34 return 0;