From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74362 invoked by alias); 30 Jan 2018 22:11:47 -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 74344 invoked by uid 89); 30 Jan 2018 22:11:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=Hx-languages-length:2633 X-HELO: mail-qk0-f175.google.com Received: from mail-qk0-f175.google.com (HELO mail-qk0-f175.google.com) (209.85.220.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Jan 2018 22:11:45 +0000 Received: by mail-qk0-f175.google.com with SMTP id d18so12228911qke.7 for ; Tue, 30 Jan 2018 14:11:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=FaBPV2Y8gVu8osP/C0SNmerzujdXYSYGYO8cx4Sz4Xc=; b=AbPI29vdR2ScKLVZ/jl3EkXOqiHDIXx1S5dMRmzQ0t3udcDIdjzuXyBfkl0Y31WLhF kKwtI07JHtcl0XUE+TV9EihXW8LstnwEUs2fjvIJTWSRKt9J2natgMtiZ5659xBKtjJ8 1broJ/gNQ18IR1Zcf+XjMuQwCUs7LN24lVdAgyt54hBu3CxohW9zRbERq9e3VdYYeh/X wGPp4Ml+QhbmqXhIGNnj0wy5GDnwWZMs1oS/zw9T2uOW/5nuyFkF5EdJ82HCuJgsPKI8 0xQEXsg8JfHciYD+zt5q2bIHwNCTAETh7jPxHotm7L4+txTDa55m5NVCODWYfph0Ocxr b0iQ== X-Gm-Message-State: AKwxytcpxfjBAJHxyzqTKGuzPuRByZBApFpRy58almgaSSNI6fJ3Q4hL VGaHLcJVJi/cWAnugaODjZbrar/5WnY= X-Google-Smtp-Source: AH8x226i1aBU7g36qjWO/ld7Gy+yphC/19rH23USqWCsm0zPavByMPxczYpEbS4oKUFAdBk3N5+qEw== X-Received: by 10.55.116.68 with SMTP id p65mr26067412qkc.230.1517350303902; Tue, 30 Jan 2018 14:11:43 -0800 (PST) Received: from abulafia.quesejoda.com ([172.56.42.210]) by smtp.gmail.com with ESMTPSA id v190sm9852210qkb.90.2018.01.30.14.11.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jan 2018 14:11:43 -0800 (PST) To: Richard Biener Cc: Jakub Jelinek , Martin Sebor , gcc-patches From: Aldy Hernandez Subject: [PR tree-optimization/84047] missing -Warray-bounds on an out-of-bounds index Message-ID: <9a52975c-c720-f42f-3564-7b69e361487d@redhat.com> Date: Tue, 30 Jan 2018 22:43:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------812243798A7E3531652F3AC7" X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg02391.txt.bz2 This is a multi-part message in MIME format. --------------812243798A7E3531652F3AC7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 783 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? --------------812243798A7E3531652F3AC7 Content-Type: text/x-patch; name="curr.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="curr.patch" Content-length: 1881 gcc/ PR tree-optimization/84047 * tree-vrp.c (search_for_addr_array): Handle ADDR_EXPRs. (check_array_bounds): Same. diff --git a/gcc/testsuite/gcc.dg/pr84047.c b/gcc/testsuite/gcc.dg/pr84047.c new file mode 100644 index 00000000000..9f9c6ca4a9e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84047.c @@ -0,0 +1,18 @@ +/* { dg-compile } */ +/* { dg-options "-O2 -Warray-bounds" } */ + +int f (void) +{ + const char *s = "12345678"; + int i = 1U << 30; + return s[i]; /* { dg-warning "array bounds" } */ +} + +char a[8]; + +int g (void) +{ + const char *s = a + 4; + int i = 8; + return s[i]; /* { dg-warning "array bounds" } */ +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 3af81f70872..07d39bab8a4 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4922,14 +4922,15 @@ void vrp_prop::search_for_addr_array (tree t, location_t location) { /* Check each ARRAY_REFs in the reference chain. */ - do - { - if (TREE_CODE (t) == ARRAY_REF) - check_array_ref (location, t, true /*ignore_off_by_one*/); + if (TREE_CODE (t) == ADDR_EXPR) + do + { + if (TREE_CODE (t) == ARRAY_REF) + check_array_ref (location, t, true /*ignore_off_by_one*/); - t = TREE_OPERAND (t, 0); - } - while (handled_component_p (t)); + t = TREE_OPERAND (t, 0); + } + while (handled_component_p (t)); if (TREE_CODE (t) == MEM_REF && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR @@ -5012,7 +5013,9 @@ check_array_bounds (tree *tp, int *walk_subtree, void *data) if (TREE_CODE (t) == ARRAY_REF) vrp_prop->check_array_ref (location, t, false /*ignore_off_by_one*/); - else if (TREE_CODE (t) == ADDR_EXPR) + else if (TREE_CODE (t) == ADDR_EXPR + /* Handle (MEM_REF (ADDR_EXPR STRING_CST) INTEGER_CST). */ + || TREE_CODE (t) == MEM_REF) { vrp_prop->search_for_addr_array (t, location); *walk_subtree = FALSE; --------------812243798A7E3531652F3AC7--