From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128147 invoked by alias); 20 Jun 2017 23:15:22 -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 127859 invoked by uid 89); 20 Jun 2017 23:15:16 -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=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=lieu X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS 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: mail-qt0-f175.google.com Received: from mail-qt0-f175.google.com (HELO mail-qt0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Jun 2017 23:15:03 +0000 Received: by mail-qt0-f175.google.com with SMTP id f92so6347921qtb.2; Tue, 20 Jun 2017 16:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=xvqIEwRk5dtBtDsmF7XGSzDhVIZg92xhE/FhbW0gwyk=; b=Bzk6RBq7v2lohClb79L5QlFPKM5YiSCHfvsd4g+CS5w04UwVnjAjtqmXUaXmHNQeR3 BPbJCIjYwK7uHLxv+ZbkzzlD0rGvqvxF4QRKhag9gRfIcdCUnNn7E/5zMlp8nfan2vvD NHIFZLCpq2j2i8BlT6L6jLA8vmLVDRmKzc7sFfbzG5FMTOTQtV3Sc7Oj5uM820vF0Is8 nuE5/HK1/U5vDBDTkALnlv8SKVQGlGgoDQ39zqOBYGUU/U1gUGssDRf8Ek3HdNaMujve S6/4Nwj+mgiiDqhUR9cSTBB3tVvHkBGYz2cXjWrLbhqd4UzY6zpjyTstOV3f/MgmPZm7 po5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=xvqIEwRk5dtBtDsmF7XGSzDhVIZg92xhE/FhbW0gwyk=; b=rie6XVufM6oMIJTEyfrpcRUaDgdwNmNoPQ8BoV96/qCJ3iUSEDv882Uo/qv+F9Wjdz DbS5nbaH2w0Q5yYyofy3Q8hZRU5UzDifpOu8bsxhzwh1emStyvkxAgBEmh8EHUPKOqJY F8GAAuFCKHCQychedFrRXiQoQF0hN+E7G17AB1Y7Loi+AtobcZUWeS91BEM0c3+MvEl1 VYqUI56UJDBvemIXUjE0F4FXkXtJHeDoD/FlCwmT8O7SXRKseTdQ1m0DbhAFJLQTMll6 JGI6zl5UvRF3SoL1EMZX8WYx6realvz9UJuMtSMVKJJc/oxcRuHrhB6t+biCeK8pb3vR 4JuQ== X-Gm-Message-State: AKS2vOw40N8pbFAb6ZXHPmUAf5PnJekjqcQ0PBAOHLJPoav6xWERjPXJ rhcXr0h31UQwag== X-Received: by 10.237.38.193 with SMTP id q59mr35239175qtd.69.1498000501414; Tue, 20 Jun 2017 16:15:01 -0700 (PDT) Received: from localhost.localdomain (184-96-144-212.hlrn.qwest.net. [184.96.144.212]) by smtp.gmail.com with ESMTPSA id i30sm9916652qtc.19.2017.06.20.16.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 16:15:01 -0700 (PDT) Subject: Re: [committed] Fix -Werror=class-memaccess failures in jit testsuite (PR jit/81144) To: David Malcolm , gcc-patches@gcc.gnu.org, jit@gcc.gnu.org References: <1497993952-49602-1-git-send-email-dmalcolm@redhat.com> Cc: msebor@redhat.com From: Martin Sebor Message-ID: <95b93bd9-6940-6a10-d55f-92e61bbb872e@gmail.com> Date: Sun, 01 Jan 2017 00:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1497993952-49602-1-git-send-email-dmalcolm@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2017-q2/txt/msg00003.txt.bz2 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? -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. 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. 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.) Martin