PR c++/92001 - missing -Wclass-memaccess with array as first argument to memset
authorMartin Sebor <msebor@redhat.com>
Tue, 8 Oct 2019 22:12:54 +0000 (22:12 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 8 Oct 2019 22:12:54 +0000 (16:12 -0600)
gcc/cp/ChangeLog:

PR c++/92001
* call.c (maybe_warn_class_memaccess): Handle arrays.

gcc/testsuite/ChangeLog:

PR c++/92001
* g++.dg/Wclass-memaccess-5.C: New test.

From-SVN: r276725

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/Wclass-memaccess-5.C [new file with mode: 0644]

index 90cab94e88ea5ffa6536b68486ab1e0868f76fb2..0e8d9301bfda9d492889151e653d3bdd1b3f8793 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-08  Martin Sebor  <msebor@redhat.com>
+
+       PR c++/92001
+       * call.c (maybe_warn_class_memaccess): Handle arrays.
+
 2019-10-07  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place.
index 6c9acac4614d27fec215be22d3a09dc921815518..4ed424f3a6c8ce1a0ddab8851987cca6c23b3d54 100644 (file)
@@ -8911,7 +8911,9 @@ maybe_warn_class_memaccess (location_t loc, tree fndecl,
   unsigned srcidx = !dstidx;
 
   tree dest = (*args)[dstidx];
-  if (!TREE_TYPE (dest) || !INDIRECT_TYPE_P (TREE_TYPE (dest)))
+  if (!TREE_TYPE (dest)
+      || (TREE_CODE (TREE_TYPE (dest)) != ARRAY_TYPE
+         && !INDIRECT_TYPE_P (TREE_TYPE (dest))))
     return;
 
   tree srctype = NULL_TREE;
index d9d73dbd308feff20ef101d5e1faf42453266616..3f189e31719e6da7f2cab7b573e57cfb19c6ad58 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-08  Martin Sebor  <msebor@redhat.com>
+
+       PR c++/92001
+       * g++.dg/Wclass-memaccess-5.C: New test.
+
 2019-10-08  Dmitrij Pochepko <dmitrij.pochepko@bell-sw.com>
 
        PR tree-optimization/90836
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-5.C b/gcc/testsuite/g++.dg/Wclass-memaccess-5.C
new file mode 100644 (file)
index 0000000..d0fffea
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR c++/92001 - missing -Wclass-memaccess with array as first argument
+   to memset
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+extern "C" void* memset (void*, int, __SIZE_TYPE__);
+
+struct S { S (); };
+
+void test_array_access (S *p, S (*pa)[2], S (&r)[3])
+{
+  S a[1];
+  memset (a, 0, sizeof a);        // { dg-warning "-Wclass-memaccess" }
+
+  memset (*pa, 0, sizeof *pa);    // { dg-warning "-Wclass-memaccess" }
+
+  memset (r, 0, sizeof r);        // { dg-warning "-Wclass-memaccess" }
+}