From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16210 invoked by alias); 17 Jan 2019 07:48:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 15941 invoked by uid 89); 17 Jan 2019 07:48:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-lj1-f194.google.com Received: from mail-lj1-f194.google.com (HELO mail-lj1-f194.google.com) (209.85.208.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Jan 2019 07:48:25 +0000 Received: by mail-lj1-f194.google.com with SMTP id s5-v6so7679641ljd.12 for ; Wed, 16 Jan 2019 23:48:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aPY7IvZ/T1MVtkfstvFvYSrb0zitFY11C4dvO840AaM=; b=cAmT6YEInp2ndTjywoYmIdyUW8nJU4ypaplXx69wPLVzl+q6zPAJPaeubqqsB86Z2y g+EOWV1xLDk9nUljRmgo6c/5auLsITEkgUGq8fh2PFIX+RaDv+93v2fi+ux7bhg3U6X5 61kO/KPkdIuv4OPyelrgXnhDAZOWrrYdNDcZPVPnvYCW13BhZ/wU4A3lcqOo4C9d7Eeq wYEF6ZV7hgShd/LBUtTnEMtbKhmp137N5AjmLRCx7jnu+H1x1YU4rbGAsn66T/qrJ0T7 2q431t2pAUSPq8RYaHvTnmE6tsvnFYRBALloZAMAFL+Tm02wtceDBBdfshnB4VN+KlAl gnCA== MIME-Version: 1.0 References: <37e931ad-17de-552e-8c96-854233884e6a@gmail.com> <76eda7b0-f5d6-9312-63ea-a344949689e6@gmail.com> <7c0a5eb6-05de-1593-87d4-7944ce968e06@redhat.com> <88fa8db6-c4f6-9c01-f93b-5dd2d4b96b48@gmail.com> In-Reply-To: <88fa8db6-c4f6-9c01-f93b-5dd2d4b96b48@gmail.com> From: Richard Biener Date: Thu, 17 Jan 2019 07:48:00 -0000 Message-ID: Subject: Re: [PATCH] avoid issuing -Warray-bounds during folding (PR 88800) To: Martin Sebor Cc: Jeff Law , "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00984.txt.bz2 On Thu, Jan 17, 2019 at 2:51 AM Martin Sebor wrote: > > On 1/16/19 6:14 PM, Jeff Law wrote: > > On 1/15/19 8:21 AM, Martin Sebor wrote: > >> On 1/15/19 4:07 AM, Richard Biener wrote: > >>> On Tue, Jan 15, 2019 at 1:08 AM Martin Sebor wrote: > >>>> > >>>> The gimple_fold_builtin_memory_op() function folds calls to memcpy > >>>> and similar to MEM_REF when the size of the copy is a small power > >>>> of 2, but it does so without considering whether the copy might > >>>> write (or read) past the end of one of the objects. To detect > >>>> these kinds of errors (and help distinguish them from -Westrict) > >>>> the folder calls into the wrestrict pass and lets it diagnose them. > >>>> Unfortunately, that can lead to false positives for even some fairly > >>>> straightforward code that is ultimately found to be unreachable. > >>>> PR 88800 is a report of one such problem. > >>>> > >>>> To avoid these false positives the attached patch adjusts > >>>> the function to avoid issuing -Warray-bounds for out-of-bounds > >>>> calls to memcpy et al. Instead, the patch disables the folding > >>>> of such invalid calls (and only those). Those that are not > >>>> eliminated during DCE or other subsequent passes are eventually > >>>> diagnosed by the wrestrict pass. > >>>> > >>>> Since this change required removing the dependency of the detection > >>>> on the warning options (originally done as a micro-optimization to > >>>> avoid spending compile-time cycles on something that wasn't needed) > >>>> the patch also adds tests to verify that code generation is not > >>>> affected as a result of warnings being enabled or disabled. With > >>>> the patch as is, the invalid memcpy calls end up emitted (currently > >>>> they are folded into equally invalid MEM_REFs). At some point, > >>>> I'd like us to consider whether they should be replaced with traps > >>>> (possibly under the control of as has been proposed a number of > >>>> times in the past. If/when that's done, these tests will need to > >>>> be adjusted to look for traps instead. > >>>> > >>>> Tested on x86_64-linux. > >>> > >>> I've said in the past that I feel delaying of folding is wrong. > >>> > >>> To understand, the PR is about emitting a warning for out-of-bound > >>> accesses in a dead code region? > >> > >> Yes. I am keeping in my mind your preference of not delaying > >> the folding of valid code. > >> > >>> > >>> If we think delaying/disablign the folding is the way to go the > >>> patch looks OK. > >> > >> I do, at least for now. I'm taking this as your approval to commit > >> the patch (please let me know if you didn't mean it that way). > > Note we are in stage4, so we're supposed to be addressing regression > > bugfixes and documentation issues. > > > > So I think Richi needs to be explicit about whether or not he wants > > this in gcc-9 or if it should defer to gcc-10. > > > > I have no technical objections to the patch and would easily ack it in > > stage1 or stage3. > > The warning is a regression introduced in GCC 8. I was just about > to commit the fix so please let me know if I should hold off until > stage 1. As it fixes a regression it is fine now - I also like the cleaning up of the helper function to work independently of the -W* state. Richard. > Martin