]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/86196 - Bogus -Wrestrict on memcpy between array elements at...
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Dec 2018 01:22:08 +0000 (01:22 +0000)
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Dec 2018 01:22:08 +0000 (01:22 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@266967 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimple-ssa-warn-restrict.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wrestrict-18.c [new file with mode: 0644]

index 1a274b4e237ab6d93632630252062a94077079fc..14c52ad64bec43ef731ec281d3aef4bf522bb70b 100644 (file)
@@ -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*.
index 035fbf88c116e2e681d46c59b900fe2d254aa6d9..d47f73f7be65bd603d62cc33f058213a9729a5a6 100644 (file)
@@ -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)
     {
index 60f4ebafc3af15609acb4450c72c2fd96db9a19b..414ecd3c74f60582515b2f86ff4fc4a908a775b3 100644 (file)
@@ -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 (file)
index 0000000..dbad956
--- /dev/null
@@ -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" } */
+}