From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74173 invoked by alias); 21 Jun 2017 00:54:30 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 74053 invoked by uid 89); 21 Jun 2017 00:54:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*M:194, belt X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Jun 2017 00:54:28 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC5124E4D0; Wed, 21 Jun 2017 00:54:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EC5124E4D0 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dmalcolm@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EC5124E4D0 Received: from ovpn-116-74.phx2.redhat.com (ovpn-116-74.phx2.redhat.com [10.3.116.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 586276DACE; Wed, 21 Jun 2017 00:54:26 +0000 (UTC) Message-ID: <1498006465.7551.194.camel@redhat.com> Subject: Re: [committed] Fix -Werror=class-memaccess failures in jit testsuite (PR jit/81144) From: David Malcolm To: Martin Sebor , gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: msebor@redhat.com Date: Sun, 01 Jan 2017 00:00:00 -0000 In-Reply-To: <95b93bd9-6940-6a10-d55f-92e61bbb872e@gmail.com> References: <1497993952-49602-1-git-send-email-dmalcolm@redhat.com> <95b93bd9-6940-6a10-d55f-92e61bbb872e@gmail.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 21 Jun 2017 00:54:27 +0000 (UTC) X-IsSubscribed: yes X-SW-Source: 2017-q2/txt/msg00004.txt.bz2 On Tue, 2017-06-20 at 17:15 -0600, Martin Sebor wrote: > On 06/20/2017 03:25 PM, David Malcolm wrote: > > 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? Thanks for the info. > -Wclass-memaccess is issued because struct quadratic_test contains > members of classes that define a default ctor to initialize their > private members. > The premise behind the warning is that objects > of types with user-defined default and copy ctors should be > initialized by making use of their ctors, and those with private > data members manipulated via member functions rather than by > directly modifying their raw representation. Using memset to > bypass the default ctor doesn't begin the lifetime of an object, > can violate invariants set up by it, and using it to overwrite > private members breaks encapsulation. Examples of especially > insidious errors include overwriting const data, references, or > pointer to data members for which zero-initialization isn't > the same as clearing their bytes. If I'm reading my code correctly, all of the default ctors of all of the members of this struct are "merely" initializing the pointer they wrap to NULL. So the ctors are initializing everything to NULL, and then the memset redundant re-init's everything to 0 bits (I guess I was going for a "belt and braces" approach to ensure that things are initialized). > The warning runs early on in the C++ front end and has no knowledge > of either the effects of the type's ctors, dtor, and copy assignment > operator, or whether the raw memory function is called in lieu of > initializing an object (e.g., in storage obtained from malloc or > operator new), or as a shortcut to zero out its members, or when > zeroing them out happens to be safe and doesn't actually do any > of those bad things I mentioned above. Aha: so at the place where the warning runs it's not possible to access the ctors and tell that they're assigning NULL everywhere? Might it be possible to convert the warning to work in a two-phase way where it first gathers up a vec of suspicious-looking modifications, and then flushes them later, filtering against ctor information when it has the latter? (so that we don't have to warn for this case at -Wall?) Alternatively maybe this is PEBCAK at my end; if so, maybe a case for adding this to the changes.html page? (and maybe adding some notes on workarounds there, and/or to invoke.texi?) > > That said, I'm sorry (and a little surprised) that I missed these > errors in my tests. I thought I had all the languages covered by > using > > --enable-languages=all,ada,c,c++,fortran,go,lto,objc,obj-c++ > > but I guess jit still isn't implied by all, even after Nathan's > recent change to it. Let me add jit to my script (IIRC, I once > had it there but it was causing some trouble and I took it out.) Reading r248454 (aka 01b4453cde8f1871495955298043d9fb589e4a36), it looks like "jit" is only included in "all" if you also pass --enable-host-shared Presumably that's what happened. Bother. Thanks; hope this is constructive. Dave