diff mbox series

handle arrays in -Wclass-memaccess (PR 92001)

Message ID 0e38b0b4-a4f8-1ce2-510a-79e3643ff2c4@gmail.com
State New
Headers show
Series handle arrays in -Wclass-memaccess (PR 92001) | expand

Commit Message

Martin Sebor Oct. 8, 2019, 12:56 a.m. UTC
-Wclass-memaccess doesn't trigger for access to arrays of
objects whose type it's designed to trigger for.  It looks
to me like a simple oversight in maybe_warn_class_memaccess.
Attached is a trivial patch to correct it tested on
x86_64-linux.

Martin

Comments

Jason Merrill Oct. 8, 2019, 9:11 p.m. UTC | #1
On 10/7/19 8:56 PM, Martin Sebor wrote:
> -Wclass-memaccess doesn't trigger for access to arrays of
> objects whose type it's designed to trigger for.  It looks
> to me like a simple oversight in maybe_warn_class_memaccess.
> Attached is a trivial patch to correct it tested on
> x86_64-linux.

OK, thanks.

Jason
diff mbox series

Patch

PR c++/92001 - missing -Wclass-memaccess with array as first argument to memset

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.

Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 276657)
+++ gcc/cp/call.c	(working copy)
@@ -8910,7 +8910,9 @@  maybe_warn_class_memaccess (location_t loc, tree f
   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: gcc/testsuite/g++.dg/Wclass-memaccess-5.C
===================================================================
--- gcc/testsuite/g++.dg/Wclass-memaccess-5.C	(nonexistent)
+++ gcc/testsuite/g++.dg/Wclass-memaccess-5.C	(working copy)
@@ -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" }
+}