diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-12-08 00:55:18 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-12-08 00:55:18 +0100 |
commit | 9b6c97373a0ca04b5888a1c4ca6519c94388da50 (patch) | |
tree | 3df943309df2540a9af1e2dc0cd7ef3408202d85 | |
parent | 38b28c6eb28463feadfc7e18d553f8f2327a2219 (diff) | |
download | gcc-9b6c97373a0ca04b5888a1c4ca6519c94388da50.zip gcc-9b6c97373a0ca04b5888a1c4ca6519c94388da50.tar.gz gcc-9b6c97373a0ca04b5888a1c4ca6519c94388da50.tar.bz2 |
re PR tree-optimization/83075 (Invalid strncpy optimization)
PR tree-optimization/83075
* gcc.dg/tree-ssa/strncpy-2.c: Use size_t instead of unsigned, add
separate function with noipa attribute to also verify behavior when
optimizers don't know the sizes and aliasing, verify resulting sizes
and array content. Add -Wstringop-overflow to dg-options.
* gcc.dg/tree-ssa/strncat.c: Likewise.
From-SVN: r255485
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/strncat.c | 40 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/strncpy-2.c | 40 |
3 files changed, 65 insertions, 24 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f8e837..d4cb0d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-12-08 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/83075 + * gcc.dg/tree-ssa/strncpy-2.c: Use size_t instead of unsigned, add + separate function with noipa attribute to also verify behavior when + optimizers don't know the sizes and aliasing, verify resulting sizes + and array content. Add -Wstringop-overflow to dg-options. + * gcc.dg/tree-ssa/strncat.c: Likewise. + 2017-12-07 Thomas Preud'homme <thomas.preudhomme@arm.com> * lib/target-supports.exp (check_effective_target_fstack_protector): diff --git a/gcc/testsuite/gcc.dg/tree-ssa/strncat.c b/gcc/testsuite/gcc.dg/tree-ssa/strncat.c index 93a60c8..9b8cf23 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/strncat.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/strncat.c @@ -1,19 +1,35 @@ -/* PR tree-optimization/83075 - Invalid strncpy optimization - { dg-do run } - { dg-options "-O2 -Wno-stringop-overflow" } */ +/* PR tree-optimization/83075 - Invalid strncpy optimization */ +/* { dg-do run } */ +/* { dg-options "-O2 -Wstringop-overflow" } */ -int main (void) +typedef __SIZE_TYPE__ size_t; + +__attribute__((noipa)) size_t +foo (char *p, char *q, size_t *r) { - char a[8] = ""; + size_t n0 = __builtin_strlen (p); + __builtin_strncat (q, p, n0); /* { dg-warning "specified bound depends on the length" } */ + size_t n1 = __builtin_strlen (p); + *r = n0; + return n1; +} +int +main () +{ + char a[8] = ""; __builtin_strcpy (a, "123"); - - unsigned n0 = __builtin_strlen (a); - - __builtin_strncat (a + 3, a, n0); - - unsigned n1 = __builtin_strlen (a); - + size_t n0 = __builtin_strlen (a); + __builtin_strncat (a + 3, a, n0); /* { dg-warning "specified bound depends on the length" } */ + size_t n1 = __builtin_strlen (a); if (n1 == n0) __builtin_abort (); + a[6] = '7'; + __builtin_strcpy (a, "456"); + size_t n2; + if (foo (a, a + 3, &n2) != 6 || n2 != 3) + __builtin_abort (); + if (__builtin_memcmp (a, "456456\0", sizeof "456456\0")) + __builtin_abort (); + return 0; } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/strncpy-2.c b/gcc/testsuite/gcc.dg/tree-ssa/strncpy-2.c index 42203d5..2ef9cd6 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/strncpy-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/strncpy-2.c @@ -1,19 +1,35 @@ -/* PR tree-optimization/83075 - Invalid strncpy optimization - { dg-do run } - { dg-options "-O2 -Wno-stringop-overflow" } */ +/* PR tree-optimization/83075 - Invalid strncpy optimization */ +/* { dg-do run } */ +/* { dg-options "-O2 -Wstringop-overflow" } */ -int main (void) +typedef __SIZE_TYPE__ size_t; + +__attribute__((noipa)) size_t +foo (char *p, char *q, size_t *r) { - char a[8] = ""; + size_t n0 = __builtin_strlen (p); + __builtin_strncpy (q, p, n0); /* { dg-warning "specified bound depends on the length" } */ + size_t n1 = __builtin_strlen (p); + *r = n0; + return n1; +} +int +main () +{ + char a[8] = ""; __builtin_strcpy (a, "123"); - - unsigned n0 = __builtin_strlen (a); - - __builtin_strncpy (a + 3, a, n0); - - unsigned n1 = __builtin_strlen (a); - + size_t n0 = __builtin_strlen (a); + __builtin_strncpy (a + 3, a, n0); /* { dg-warning "specified bound depends on the length" } */ + size_t n1 = __builtin_strlen (a); if (n1 == n0) __builtin_abort (); + a[6] = '7'; + __builtin_strcpy (a, "456"); + size_t n2; + if (foo (a, a + 3, &n2) != 7 || n2 != 3) + __builtin_abort (); + if (__builtin_memcmp (a, "4564567", sizeof "4564567")) + __builtin_abort (); + return 0; } |