From patchwork Tue Dec 3 13:38:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 296200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1135B2C009A for ; Wed, 4 Dec 2013 00:39:01 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=WO+lR5P39ZHJpQwfK btAbl6QRmz+V/d0HDR5CfCstUZUNqrbOMyBFaN4IZdEnjnZ9/X5MI70/2i+LOuRy J9SE5y+Fww//Pqfg7RZWL7Gzzh2eZ1H6BLFDIXv/T5ifa4ZfgeX7qU5s0jVQJDlo wndJFfcUwPuN34O755nBeS2PE8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=hqH5IKkK1rJCx6c9sefdM0f LGpE=; b=YNZAIqyfLN8ZDEhvXcer7JPTt9/4fd7Tm2NrOiUBkZyv+PDdFVDVP0J 4jH3708SgTk3QVVvBMjKYt1zZPBCseXVcYb9gvrYoSmJub1imzHkpES5xKrM1LIf z5VVjPiQqRtin06VcIJOpu/fIUqNN17OMtYuljv76RBV+ZynSaEY= Received: (qmail 26004 invoked by alias); 3 Dec 2013 13:38:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25992 invoked by uid 89); 3 Dec 2013 13:38:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RDNS_NONE, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2013 13:38:45 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VnqBH-0003OF-D7 from Tom_deVries@mentor.com ; Tue, 03 Dec 2013 05:38:27 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 3 Dec 2013 05:38:27 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Tue, 3 Dec 2013 13:38:25 +0000 Message-ID: <529DDECD.3090701@mentor.com> Date: Tue, 3 Dec 2013 14:38:21 +0100 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Jakub Jelinek CC: Jeff Law , Richard Biener , Jason Merrill , GCC Patches , Marc Glisse Subject: Re: [PATCH] Don't create out-of-bounds BIT_FIELD_REFs References: <5294544D.60506@mentor.com> <52950E33.3080209@mentor.com> <52958F35.3050403@redhat.com> <52967EFF.5060302@mentor.com> <20131203124942.GX892@tucnak.redhat.com> In-Reply-To: <20131203124942.GX892@tucnak.redhat.com> On 03-12-13 13:49, Jakub Jelinek wrote: > On Thu, Nov 28, 2013 at 12:23:43AM +0100, Tom de Vries wrote: >> Committed to trunk. >> >> Also ok for 4.8 branch? It's a 4.8/4.9 regression. > > Ok, but I guess you need to adjust your patch for 4.8 (tree_to_* > and tree_fits_* to host_integerp/tree_low_cst), so please make sure > you test it before commiting. > Jakub, Richard B. already ok'ed the patch, but with the checking bit left out. The functions you mention were in that checking bit. I've tested and committed attached patch. Thanks, - Tom > Jakub > 2013-11-27 Tom de Vries Marc Glisse PR middle-end/59037 * semantics.c (cxx_fold_indirect_ref): Don't create out-of-bounds BIT_FIELD_REF. * fold-const.c (fold_indirect_ref_1): Don't create out-of-bounds BIT_FIELD_REF. * gimplify.c (gimple_fold_indirect_ref): Same. * c-c++-common/pr59037.c: New testcase. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 571fc7c..e7e2034 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7543,7 +7543,7 @@ cxx_fold_indirect_ref (location_t loc, tree type, tree op0, bool *empty_base) unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; tree index = bitsize_int (indexi); - if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (op00type)) + if (offset / part_widthi < TYPE_VECTOR_SUBPARTS (op00type)) return fold_build3_loc (loc, BIT_FIELD_REF, type, op00, part_width, index); diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f666429..7433686 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -16595,7 +16595,7 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0) unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; tree index = bitsize_int (indexi); - if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (op00type)) + if (offset / part_widthi < TYPE_VECTOR_SUBPARTS (op00type)) return fold_build3_loc (loc, BIT_FIELD_REF, type, op00, part_width, index); diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e711928..1f1deb8 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4369,7 +4369,7 @@ gimple_fold_indirect_ref (tree t) unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; tree index = bitsize_int (indexi); if (offset / part_widthi - <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (addrtype))) + < TYPE_VECTOR_SUBPARTS (TREE_TYPE (addrtype))) return fold_build3 (BIT_FIELD_REF, type, TREE_OPERAND (addr, 0), part_width, index); } diff --git a/gcc/testsuite/c-c++-common/pr59037.c b/gcc/testsuite/c-c++-common/pr59037.c new file mode 100644 index 0000000..fae13c2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr59037.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +typedef int v4si __attribute__ ((vector_size (16))); + +int +main (int argc, char** argv) +{ + v4si x = {0,1,2,3}; + x = (v4si) {(x)[3], (x)[2], (x)[1], (x)[0]}; + return x[4]; +}