From patchwork Wed Nov 23 10:26:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 83626 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp2559465qge; Wed, 23 Nov 2016 02:29:10 -0800 (PST) X-Received: by 10.99.141.193 with SMTP id z184mr4004209pgd.23.1479896950667; Wed, 23 Nov 2016 02:29:10 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j69si33073051pfk.19.2016.11.23.02.29.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2016 02:29:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442343-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-442343-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442343-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=iz5M9sqd4rsgvLddot7GjG4jLeSqX+FkLA+K63pIewJ87maBWN ZudKjK9MQKCEEtbj2uZjsWW0/YFU2ps8dmz6dIhggZbb4MsM+T4dbrQPHYaM/qda NRVpor/aZurK53PMTSLb40tZAoaezUnmLYiGxNiSLNnf5quLONqXLG37M= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=ObKwQSlru263lPGisX0ZwANFH5k=; b=L0Ny3km+eJJD2yNEcek0 yRQHEGUa2d3DuZ78jFlhvp761Hm3D7Zhks4I+Bu25RvvLz8l/EVYRNUmIUSracYc JyB6LH1BrqCBnNt7bo+uhvH0nb694/1xieFxbo3JzLS7hbJ0nnY2DCqt4rnipvPX 6trQJrgzCKSbiNdpbKnwpXA= Received: (qmail 8502 invoked by alias); 23 Nov 2016 10:28:56 -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 8469 invoked by uid 89); 23 Nov 2016 10:28:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:int_siz, 80, 7, const_tree X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Nov 2016 10:28:45 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 09DDBAB03; Wed, 23 Nov 2016 10:28:42 +0000 (UTC) To: GCC Patches Cc: Jakub Jelinek From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Fill bitregion_{start, end} in store_constructor (PR, tree-optimization/78428). Message-ID: <22d70b27-ddad-6410-3c59-1e630d3d7d55@suse.cz> Date: Wed, 23 Nov 2016 11:26:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Following patch fixes situation where we do a store to a bitfield which is at boundary of a record. This leads to usage of wider store, leading to overwriting a following memory location. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Apart from that, the reported test-case in PR works on x86_64-linux-gnu. Ready to be installed? Martin >From 69961d69e551d9abe31eb7946d5211b99bbe1479 Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 22 Nov 2016 10:15:42 +0100 Subject: [PATCH] Fill bitregion_{start,end} in store_constructor (PR tree-optimization/78428). gcc/testsuite/ChangeLog: 2016-11-22 Martin Liska Jakub Jelinek PR tree-optimization/78428 * gcc.dg/tree-ssa/pr78428.c: New test. gcc/ChangeLog: 2016-11-22 Martin Liska Jakub Jelinek PR tree-optimization/78428 * expr.c (store_constructor_field): Add new arguments. (store_constructor): Fill up store_constructor_field for FIELD_DECL of a store_constructor_fielductor. --- gcc/expr.c | 26 ++++++++++++++++++-------- gcc/testsuite/gcc.dg/tree-ssa/pr78428.c | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr78428.c diff --git a/gcc/expr.c b/gcc/expr.c index fe752fb..50bc7c5 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -80,7 +80,8 @@ static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int); static rtx_insn *compress_float_constant (rtx, rtx); static rtx get_subtarget (rtx); static void store_constructor_field (rtx, unsigned HOST_WIDE_INT, - HOST_WIDE_INT, machine_mode, + HOST_WIDE_INT, unsigned HOST_WIDE_INT, + unsigned HOST_WIDE_INT, machine_mode, tree, int, alias_set_type, bool); static void store_constructor (tree, rtx, int, HOST_WIDE_INT, bool); static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, @@ -6077,7 +6078,10 @@ all_zeros_p (const_tree exp) static void store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize, - HOST_WIDE_INT bitpos, machine_mode mode, + HOST_WIDE_INT bitpos, + unsigned HOST_WIDE_INT bitregion_start, + unsigned HOST_WIDE_INT bitregion_end, + machine_mode mode, tree exp, int cleared, alias_set_type alias_set, bool reverse) { @@ -6112,8 +6116,8 @@ store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize, reverse); } else - store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false, - reverse); + store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode, + exp, alias_set, false, reverse); } @@ -6148,6 +6152,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size, { tree type = TREE_TYPE (exp); HOST_WIDE_INT exp_size = int_size_in_bytes (type); + HOST_WIDE_INT bitregion_end + = exp_size == -1 ? 0 : exp_size * BITS_PER_UNIT - 1; switch (TREE_CODE (type)) { @@ -6308,7 +6314,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size, MEM_KEEP_ALIAS_SET_P (to_rtx) = 1; } - store_constructor_field (to_rtx, bitsize, bitpos, mode, + store_constructor_field (to_rtx, bitsize, bitpos, + 0, bitregion_end, mode, value, cleared, get_alias_set (TREE_TYPE (field)), reverse); @@ -6468,7 +6475,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size, } store_constructor_field - (target, bitsize, bitpos, mode, value, cleared, + (target, bitsize, bitpos, 0, bitregion_end, + mode, value, cleared, get_alias_set (elttype), reverse); } } @@ -6571,7 +6579,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size, target = copy_rtx (target); MEM_KEEP_ALIAS_SET_P (target) = 1; } - store_constructor_field (target, bitsize, bitpos, mode, value, + store_constructor_field (target, bitsize, bitpos, 0, + bitregion_end, mode, value, cleared, get_alias_set (elttype), reverse); } @@ -6705,7 +6714,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size, ? TYPE_MODE (TREE_TYPE (value)) : eltmode; bitpos = eltpos * elt_size; - store_constructor_field (target, bitsize, bitpos, value_mode, + store_constructor_field (target, bitsize, bitpos, 0, + bitregion_end, value_mode, value, cleared, alias, reverse); } } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c new file mode 100644 index 0000000..3a9b99c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c @@ -0,0 +1,27 @@ +/* PR tree-optimization/78428. */ +/* { dg-options "-O2" } */ +/* { dg-do run } */ + +struct S0 +{ + int f2; + int f3:16; + int f4:18; +} ; + +int a = 5; +struct S0 b = { 3, 0, 0 }; +static struct S0 global[2] = { { 77, 0, 78 }, { 77, 0, 78 } }; + +int main () +{ + volatile struct S0 *j; + for (; a;) + { + __builtin_printf ("", b.f2); + j = &b; + *j = global[1]; + a--; + } + return 0; +} -- 2.10.2