1 /* PR tree-optimization/83075 - Invalid strncpy optimization */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -Wstringop-overflow" } */
4 
5 typedef __SIZE_TYPE__ size_t;
6 
7 __attribute__((noipa)) size_t
foo(char * p,char * q,size_t * r)8 foo (char *p, char *q, size_t *r)
9 {
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;
15 }
16 
17 int
main()18 main ()
19 {
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;
35 }
36