From d470060d06c45592514858b0a4c87bd71cd91c9b Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 8 Oct 2019 22:12:54 +0000 Subject: [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. From-SVN: r276725 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/Wclass-memaccess-5.C | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/Wclass-memaccess-5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 90cab94e88e..0e8d9301bfd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-10-08 Martin Sebor + + PR c++/92001 + * call.c (maybe_warn_class_memaccess): Handle arrays. + 2019-10-07 Paolo Carlini * call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 6c9acac4614..4ed424f3a6c 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9d73dbd308..3f189e31719 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-08 Martin Sebor + + PR c++/92001 + * g++.dg/Wclass-memaccess-5.C: New test. + 2019-10-08 Dmitrij Pochepko 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 index 00000000000..d0fffead56d --- /dev/null +++ b/gcc/testsuite/g++.dg/Wclass-memaccess-5.C @@ -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" } +} -- 2.30.2