This patch fixes a couple of failures of the form:

  error: 'void* memset(void*, int, size_t)' clearing an object of non-trivial
    type 'struct quadratic_test'; use assignment or value-initialization
    instead [-Werror=class-memaccess]
  note: 'struct quadratic_test' declared here
  cc1plus: all warnings being treated as errors

seen within the jit testsuite, by using zero-initialization instead
of memset.

(presumably introduced by r249234 aka a324786b4ded9047d05463b4bce9d238b6c6b3ef)

Successfully tested on x86_64-pc-linux-gnu; takes jit.sum from:
  # of expected passes            9211
  # of unexpected failures        2
to:
  # of expected passes            9349

Martin: it's unclear to me what the benefit of the warning is for these
cases.  AIUI, it's complaining because the code is calling
the default ctor for struct quadratic_test, and then that object is
being clobbered by the memset.
But if I'm reading things right, the default ctor for this struct
zero-initializes all fields.  Can't the compiler simply optimize away
the redundant memset, and not issue a warning?

gcc/testsuite/ChangeLog:
        PR jit/81144
        * jit.dg/test-operator-overloading.cc (make_test_quadratic): Replace
        memset call with zero-initialization.
        * jit.dg/test-quadratic.cc (make_test_quadratic): Likewise.
---
 gcc/testsuite/jit.dg/test-operator-overloading.cc | 3 +--
 gcc/testsuite/jit.dg/test-quadratic.cc            | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/jit.dg/test-operator-overloading.cc 
b/gcc/testsuite/jit.dg/test-operator-overloading.cc
index cbb1e98..f57b3fc 100644
--- a/gcc/testsuite/jit.dg/test-operator-overloading.cc
+++ b/gcc/testsuite/jit.dg/test-operator-overloading.cc
@@ -272,8 +272,7 @@ make_test_quadratic (quadratic_test &testcase)
 void
 create_code (gcc_jit_context *ctxt, void *user_data)
 {
-  struct quadratic_test testcase;
-  memset (&testcase, 0, sizeof (testcase));
+  struct quadratic_test testcase = {};
   testcase.ctxt = ctxt;
   make_types (testcase);
   make_sqrt (testcase);
diff --git a/gcc/testsuite/jit.dg/test-quadratic.cc 
b/gcc/testsuite/jit.dg/test-quadratic.cc
index f347669..61b5cdd 100644
--- a/gcc/testsuite/jit.dg/test-quadratic.cc
+++ b/gcc/testsuite/jit.dg/test-quadratic.cc
@@ -328,8 +328,7 @@ make_test_quadratic (quadratic_test &testcase)
 void
 create_code (gcc_jit_context *ctxt, void *user_data)
 {
-  struct quadratic_test testcase;
-  memset (&testcase, 0, sizeof (testcase));
+  struct quadratic_test testcase = {};
   testcase.ctxt = ctxt;
   make_types (testcase);
   make_sqrt (testcase);
-- 
1.8.5.3

Reply via email to