From patchwork Tue Nov 26 07:57:01 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: 294243 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 DAA432C00B1 for ; Tue, 26 Nov 2013 18:57:35 +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:content-type; q=dns; s=default; b=JZrqaik0ZTIKor8PkbRCK+izeLnbpLCXuuaShwFZYRf bt1W0E30rMVG/G+q+M/hVhdMPSc5J8b9Ax/XtEGAHBw1IVCPGzxaKsvW1jI4bKmf Tol1R4GxmMu4sjNxEUPWpj4l+mtYf1HCIudm5YOErNC6haM0YAeSoS2WpXbN/TVM = 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:content-type; s=default; bh=I7CyyikRwPLfGsrIYj9r0Wd51lw=; b=vTgmX+HKlAVk7E6ox rfN09KU7MG7uxGpuWHjXdEuHN/bIjaZpScVvnT8zu+glzJlTcO/UNOYi9XrYH1kP yKKIlMbwfrCB3m8g/gkwtv76U2iF/bihMpEeEEdHo2grBgOnuWNrHD/ReAVnODM7 GP2FJ76pIeqwb8rTnvFSwGT4GA= Received: (qmail 4765 invoked by alias); 26 Nov 2013 07:57:25 -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 4749 invoked by uid 89); 26 Nov 2013 07:57:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_50, 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, 26 Nov 2013 07:57:22 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VlDW5-0000rX-TY from Tom_deVries@mentor.com ; Mon, 25 Nov 2013 23:57:05 -0800 Received: from SVR-IES-FEM-03.mgc.mentorg.com ([137.202.0.108]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 25 Nov 2013 23:57:05 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.2.247.3; Tue, 26 Nov 2013 07:57:04 +0000 Message-ID: <5294544D.60506@mentor.com> Date: Tue, 26 Nov 2013 08:57:01 +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: Jason Merrill CC: , Marc Glisse Subject: [PATCH] Don't create out-of-bounds BIT_FIELD_REFs Jason, This patch prevents creating out-of-bounds BIT_FIELD_REFs in 3 locations. It fixes a SIGSEGV (triggered by gimple_fold_indirect_ref_1) in simplify_bitfield_ref. I've added an assert to detect the problematic BIT_FIELD_REF there. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom 2013-11-26 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. * gimple-fold.c (gimple_fold_indirect_ref): Same. * tree-ssa-forwprop.c (simplify_bitfield_ref): Assert that BIT_FIELD_REF is not out-of-bounds. * g++.dg/pr59037.C: New testcase. * gcc.dg/pr59037.c: Same. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 316834c..71daaa2 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9117,7 +9117,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 f91673d..0926626 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -16719,7 +16719,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/gimple-fold.c b/gcc/gimple-fold.c index 2902e69..7e9ba65 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3418,7 +3418,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/g++.dg/pr59037.C b/gcc/testsuite/g++.dg/pr59037.C new file mode 100644 index 0000000..fae13c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/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]; +} diff --git a/gcc/testsuite/gcc.dg/pr59037.c b/gcc/testsuite/gcc.dg/pr59037.c new file mode 100644 index 0000000..ba3a8ba --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr59037.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -std=gnu99" } */ + +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]; +} diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 6e6d115..5d685ef 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -3118,6 +3118,7 @@ simplify_bitfield_ref (gimple_stmt_iterator *gsi) if (TREE_CODE (m) != VECTOR_CST) return false; nelts = VECTOR_CST_NELTS (m); + gcc_assert (idx < nelts); idx = TREE_INT_CST_LOW (VECTOR_CST_ELT (m, idx)); idx %= 2 * nelts; if (idx < nelts)