Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/tree-ssa/strncat.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
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 | |
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 | |
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 } |