From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123573 invoked by alias); 8 Feb 2018 10:38:45 -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 123564 invoked by uid 89); 8 Feb 2018 10:38:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=amend, liner, Martins, His X-HELO: mail-lf0-f43.google.com Received: from mail-lf0-f43.google.com (HELO mail-lf0-f43.google.com) (209.85.215.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Feb 2018 10:38:42 +0000 Received: by mail-lf0-f43.google.com with SMTP id q17so5696844lfa.9 for ; Thu, 08 Feb 2018 02:38:42 -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=vhs0jKFzqisj5TW9VRul0BW4gtIRJ5wB7StOtNXuHoM=; b=SC15zBCRbAJ5+sEyLIbi/3Z9F1aU/VsxAMdZMqnbRGZKcXu/wAR3GHQViNOG274/+n AfzVSweRJZGOB5kskffkog/oM7ClyvJDA3k3YnSdMuWLcZMso+nvdG2k1v6ixYIp80AV LRneE144kZClQa2CA7peEV23svmOLRhAm2hF/zu9b/0SZZiDaWhgizyc9iyFSUy6zmK5 Xif20b4WdkrE479JeGFme5YThfcj6unMdLB4SXIwdkxzB3O9En4AVZfT8ILN2mlYvIzs XsP8Igo1VOfK9nfgEP/xg79dVkVFe0kzO2FvLlYrphRTqyu4squThohzY8du87Fj1RJ6 IAVw== X-Gm-Message-State: APf1xPDOS82itvjmjfukExKDO9dIGmotBsBZUNjk8mHjhuq23CZN55hS o79k4bAlzwNlZZYfJxFBaYS5DuMxhuTidT8SPS4= X-Google-Smtp-Source: AH8x224iolnKgS9ROLxFsQhDqIzeTCZXgyQjfXV8jFlbOjs0HF+jyxRJDNK1l9J1N7aUY9MJGgyI5b1o5H9J+VWozNU= X-Received: by 10.25.215.72 with SMTP id o69mr170211lfg.103.1518086320489; Thu, 08 Feb 2018 02:38:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.46.51.21 with HTTP; Thu, 8 Feb 2018 02:38:40 -0800 (PST) In-Reply-To: References: <9a52975c-c720-f42f-3564-7b69e361487d@redhat.com> From: Richard Biener Date: Thu, 08 Feb 2018 10:38:00 -0000 Message-ID: Subject: Re: [PR tree-optimization/84047] missing -Warray-bounds on an out-of-bounds index To: Aldy Hernandez Cc: Jakub Jelinek , Martin Sebor , gcc-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00396.txt.bz2 On Thu, Feb 1, 2018 at 6:42 PM, Aldy Hernandez wrote: > 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. Sorry, no - this one looks way too complicated. > Also, could someone pontificate on whether we want to fix > -Warray-bounds regressions for this release cycle? Remove bogus ones? Yes. Add "missing ones"? No. Richard. > 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.