From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2214 invoked by alias); 1 Feb 2018 17:42:30 -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 2202 invoked by uid 89); 1 Feb 2018 17:42:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=martins, Martins, His X-HELO: mail-ot0-f175.google.com Received: from mail-ot0-f175.google.com (HELO mail-ot0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Feb 2018 17:42:28 +0000 Received: by mail-ot0-f175.google.com with SMTP id a2so6315822otf.2 for ; Thu, 01 Feb 2018 09:42:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=2nbCyhGx/cOGiTnyuRUX3VTzHcUGMo3w757FeDeK7VE=; b=Qi7gXwZqrQ7dV/CPRbmQ4pL5Z9EjlOBljSidKDeZpYyafmkH5zwrhpqRx06nl2Ta8O i9dUvzgpARG0viabFa57Qw3zCrBKnVETlMgdnrbPPIRi8pGpaFHVOzM/977k7GVW3I0w Z3cxzzKbp3YonpCYgpE+2iBFGEXQJSAJRUJp3pb3EplOTadEZja6RG/zxRpPHOFqeQgG 3sVj6Noo8SugAPd2X8Iyc+PN6Koxr0lq05yK92DFYhe91ztZRXgybqUZf6pLXjANUDwI VTfktPGMzIOKCANux0znkS/4Pfni4MYb54BI22t+o1czbRI1QsV2V/IF4dStW+khXb9c ipIQ== X-Gm-Message-State: AKwxyte1u/PWBdzUpTAC18XqEPhx9PkS2Gdm6i3V0iIiWlUG2gT5csir 3lYWGBnXhzWqQg5zs0o61s7SwXPWl1PgGH4JtJ71Vg== X-Google-Smtp-Source: AH8x224POWKk53NqTROm5/MyUts8cUPJSLBHIGYlNHoET0Smpc6RW9C2hEtoaegxUa6kWwHvzNDqCghxcOQL/dlbLHU= X-Received: by 10.157.37.89 with SMTP id j25mr10538708otd.345.1517506946561; Thu, 01 Feb 2018 09:42:26 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.33.106 with HTTP; Thu, 1 Feb 2018 09:42:26 -0800 (PST) In-Reply-To: References: <9a52975c-c720-f42f-3564-7b69e361487d@redhat.com> From: Aldy Hernandez Date: Thu, 01 Feb 2018 17:42:00 -0000 Message-ID: Subject: Re: [PR tree-optimization/84047] missing -Warray-bounds on an out-of-bounds index To: Richard Biener Cc: Jakub Jelinek , Martin Sebor , gcc-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00062.txt.bz2 Since my patch isn't the easy one liner I wanted it to be, perhaps we should concentrate on Martin's patch, which is more robust, and has testcases to boot! His patch from last week also fixes a couple other PRs. Richard, would this be acceptable? That is, could you or Jakub review Martin's all-encompassing patch? If so, I'll drop mine. Also, could someone pontificate on whether we want to fix -Warray-bounds regressions for this release cycle? Thanks. On Wed, Jan 31, 2018 at 6:05 AM, Richard Biener wrote: > On Tue, Jan 30, 2018 at 11:11 PM, Aldy Hernandez wrote: >> Hi! >> >> [Note: Jakub has mentioned that missing -Warray-bounds regressions should be >> punted to GCC 9. I think this particular one is easy pickings, but if this >> and/or the rest of the -Warray-bounds regressions should be marked as GCC 9 >> material, please let me know so we can adjust all relevant PRs.] >> >> This is a -Warray-bounds regression that happens because the IL now has an >> MEM_REF instead on ARRAY_REF. >> >> Previously we had an ARRAY_REF we could diagnose: >> >> D.2720_5 = "12345678"[1073741824]; >> >> But now this is represented as: >> >> _1 = MEM[(const char *)"12345678" + 1073741824B]; >> >> I think we can just allow check_array_bounds() to handle MEM_REF's and >> everything should just work. >> >> The attached patch fixes both regressions mentioned in the PR. >> >> Tested on x86-64 Linux. >> >> OK? > > This doesn't look correct. You lump MEM_REF handling together with > ADDR_EXPR handling but for the above case you want to diagnose > _dereferences_ not address-taking. > > For the dereference case you need to amend the ARRAY_REF case, for example > via > > Index: gcc/tree-vrp.c > =================================================================== > --- gcc/tree-vrp.c (revision 257181) > +++ gcc/tree-vrp.c (working copy) > @@ -5012,6 +5012,13 @@ check_array_bounds (tree *tp, int *walk_ > if (TREE_CODE (t) == ARRAY_REF) > vrp_prop->check_array_ref (location, t, false /*ignore_off_by_one*/); > > + else if (TREE_CODE (t) == MEM_REF > + && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR > + && TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) == STRING_CST) > + { > + call factored part of check_array_ref passing in STRING_CST and offset > + } > + > else if (TREE_CODE (t) == ADDR_EXPR) > { > vrp_prop->search_for_addr_array (t, location); > > note your patch will fail to warn for "1"[1] because taking that > address is valid but not > dereferencing it. > > Richard.