From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70129 invoked by alias); 15 Jan 2019 11:08:01 -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 70117 invoked by uid 89); 15 Jan 2019 11:08:00 -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=delaying, sk:msebor, H*RU:209.85.208.193, Hx-spam-relays-external:209.85.208.193 X-HELO: mail-lj1-f193.google.com Received: from mail-lj1-f193.google.com (HELO mail-lj1-f193.google.com) (209.85.208.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Jan 2019 11:07:59 +0000 Received: by mail-lj1-f193.google.com with SMTP id n18-v6so1941822lji.7 for ; Tue, 15 Jan 2019 03:07:58 -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=78O6OBFn1SMVdKv1NwBeZi/PD1NNElj4zAkUUdYqo/Q=; b=QO+XVSNWoUKUif+VUm9rWA476mGeiNRcfQCRjcyWqciKIr7Eg3QrrUxhFnaqBJL76Y g2DfODpqx7BnGXI7bV7EIF3JRladPtrHIdslmNXp5aIFcYKV6w1VVMWLo2jRczkGt0Zc kxFMyh3zlPVeZv7ylVIVSavg/i4KVFzuOzVt+TZYSU4FZhrR+7djgGMh0V6ShaDws/Jo 7Eu7dJnnPjyWjv/kf2n0OkABZFWJYEAr9uM+KrB86au1Rfiu71ZhP5CuTm6boaYAb6yq mqSZtEYQGi/nEfXSk61gDQSD4zd30ynN4fPL/BO5kAKvaVzHrvju8eL2RbDI/gEYHRsp yEXg== MIME-Version: 1.0 References: <37e931ad-17de-552e-8c96-854233884e6a@gmail.com> In-Reply-To: <37e931ad-17de-552e-8c96-854233884e6a@gmail.com> From: Richard Biener Date: Tue, 15 Jan 2019 11:08:00 -0000 Message-ID: Subject: Re: [PATCH] avoid issuing -Warray-bounds during folding (PR 88800) To: Martin Sebor Cc: "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00831.txt.bz2 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? If we think delaying/disablign the folding is the way to go the patch looks OK. Richard. > > Martin