diff options
author | Martin Sebor <msebor@redhat.com> | 2018-12-11 01:22:08 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-12-10 18:22:08 -0700 |
commit | 1486eb791fce1b48d24075e281afd09864713e52 (patch) | |
tree | 67f9b03a71809c4fd08239f8335cf2235efe5765 | |
parent | 03da9b757be0d4b2b1770c10f7e6f68d286a01da (diff) | |
download | gcc-1486eb791fce1b48d24075e281afd09864713e52.zip gcc-1486eb791fce1b48d24075e281afd09864713e52.tar.gz gcc-1486eb791fce1b48d24075e281afd09864713e52.tar.bz2 |
PR tree-optimization/86196 - Bogus -Wrestrict on memcpy between array elements at unequal indices
gcc/ChangeLog:
PR tree-optimization/86196
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use
base size only of arrays.
gcc/testsuite/ChangeLog:
PR tree-optimization/86196
* gcc.dg/Wrestrict-18.c: New test.
From-SVN: r266967
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/gimple-ssa-warn-restrict.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wrestrict-18.c | 37 |
4 files changed, 59 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1a274b4..14c52ad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-12-10 Martin Sebor <msebor@redhat.com> + + PR tree-optimization/86196 + * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use + base size only of arrays. + 2018-12-10 Segher Boessenkool <segher@kernel.crashing.org> * config.gcc (Obsolete configurations): Delete powerpc*-*-*spe*. diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index 035fbf8..d47f73f 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -272,15 +272,16 @@ builtin_memref::builtin_memref (tree expr, tree size) offset_int maxoff = maxobjsize; tree basetype = TREE_TYPE (base); - if (TREE_CODE (basetype) == ARRAY_TYPE - && ref - && array_at_struct_end_p (ref)) - ; /* Use the maximum possible offset for last member arrays. */ - else if (tree basesize = TYPE_SIZE_UNIT (basetype)) - if (TREE_CODE (basesize) == INTEGER_CST) - /* Size could be non-constant for a variable-length type such - as a struct with a VLA member (a GCC extension). */ - maxoff = wi::to_offset (basesize); + if (TREE_CODE (basetype) == ARRAY_TYPE) + { + if (ref && array_at_struct_end_p (ref)) + ; /* Use the maximum possible offset for last member arrays. */ + else if (tree basesize = TYPE_SIZE_UNIT (basetype)) + if (TREE_CODE (basesize) == INTEGER_CST) + /* Size could be non-constant for a variable-length type such + as a struct with a VLA member (a GCC extension). */ + maxoff = wi::to_offset (basesize); + } if (offrange[0] >= 0) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 60f4eba..414ecd3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-12-10 Martin Sebor <msebor@redhat.com> + + PR tree-optimization/86196 + * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use + base size only of arrays. + 2018-12-10 Uros Bizjak <ubizjak@gmail.com> * gcc.dg/sinatan-1.c: Use dg-add-options ieee. diff --git a/gcc/testsuite/gcc.dg/Wrestrict-18.c b/gcc/testsuite/gcc.dg/Wrestrict-18.c new file mode 100644 index 0000000..dbad956 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wrestrict-18.c @@ -0,0 +1,37 @@ +/* PR tree-optimization/86196 - Bogus -Wrestrict on memcpy between array + elements at unequal indices + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +typedef __SIZE_TYPE__ size_t; + +extern void* memcpy (void*, const void*, size_t); + +struct S +{ + int n; + void * p; +}; + +/* Test case submitted in the PR. */ + +void pr86196_c0 (struct S * a, size_t n) +{ + for (size_t i = 0, j = 0; i != n; ++i) + { + if (a[i].n == 0) + { + if (i != j) + memcpy (&a[j], &a[i], sizeof (struct S)); /* { dg-bogus "\\\[-Wrestrict" } */ + ++j; + } + } +} + +/* Reduced test case. */ + +void pr86196_c1 (struct S *a, int i, int j) +{ + if (i != j) + memcpy (&a[j], &a[i], sizeof (struct S)); /* { dg-bogus "\\\[-Wrestrict" } */ +} |