From patchwork Thu Dec 15 08:02:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Ye X-Patchwork-Id: 131531 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]) by ozlabs.org (Postfix) with SMTP id D695B1007D6 for ; Thu, 15 Dec 2011 19:02:44 +1100 (EST) Received: (qmail 9893 invoked by alias); 15 Dec 2011 08:02:39 -0000 Received: (qmail 9871 invoked by uid 22791); 15 Dec 2011 08:02:36 -0000 X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-fx0-f47.google.com (HELO mail-fx0-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Dec 2011 08:02:23 +0000 Received: by faaa20 with SMTP id a20so2041081faa.20 for ; Thu, 15 Dec 2011 00:02:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.104.41 with SMTP id gb9mr3938615wib.9.1323936141602; Thu, 15 Dec 2011 00:02:21 -0800 (PST) Received: by 10.227.121.129 with HTTP; Thu, 15 Dec 2011 00:02:21 -0800 (PST) In-Reply-To: References: <4EBD4BCB.4080807@codesourcery.com> <4ED50901.8090300@codesourcery.com> Date: Thu, 15 Dec 2011 16:02:21 +0800 Message-ID: Subject: Re: Continue strict-volatile-bitfields fixes From: Ye Joey To: gcc-patches , "Schmidt, Bernd" , richard.guenther@gmail.com X-IsSubscribed: yes 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 Ping, PR middle-end/51200 Tailored from Bernd's, and added target independent test case. Now it is a pure middle-end fix. OK for trunk and 4.6? Bernd Schmidt gcc/ * expr.c (store_field): Avoid a direct store if the mode is larger than the size of the bit field. * stor-layout.c (layout_decl): If flag_strict_volatile_bitfields, treat non-volatile bit fields like volatile ones. * toplev.c (process_options): Disallow combination of -fstrict-volatile-bitfields and ABI versions less than 2. gcc/testsuite/ * gcc.target/arm/volatile-bitfields-4.c: New test. * c-c++-common/abi-bf.c: New test. Joey Ye * gcc.dg/volatile-bitfields-2.c: New test. * g++.dg/abi/bitfield12.C: no-strict-volatile-bitfields. Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 182353) +++ gcc/toplev.c (working copy) @@ -1330,6 +1330,13 @@ flag_ira_region = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED; + if (flag_strict_volatile_bitfields > 0 && !abi_version_at_least (2)) + { + warning (0, "-fstrict-volatile-bitfields disabled; " + "it is incompatible with ABI versions < 2"); + flag_strict_volatile_bitfields = 0; + } + /* Unrolling all loops implies that standard loop unrolling must also be done. */ if (flag_unroll_all_loops) Index: gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c =================================================================== --- gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c (revision 0) +++ gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c (revision 0) @@ -0,0 +1,30 @@ +/* { dg-require-effective-target arm_eabi } */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-times "ldr\[\\t \]+\[^\n\]*,\[\\t \]*\\\[\[^\n\]*\\\]" 2 } } */ +/* { dg-final { scan-assembler-times "str\[\\t \]+\[^\n\]*,\[\\t \]*\\\[\[^\n\]*\\\]" 2 } } */ +/* { dg-final { scan-assembler-not "strb" } } */ + +struct thing { + unsigned a: 8; + unsigned b: 8; + unsigned c: 8; + unsigned d: 8; +}; + +struct thing2 { + volatile unsigned a: 8; + volatile unsigned b: 8; + volatile unsigned c: 8; + volatile unsigned d: 8; +}; + +void test1(volatile struct thing *t) +{ + t->a = 5; +} + +void test2(struct thing2 *t) +{ + t->a = 5; +} Index: gcc/testsuite/gcc.dg/volatile-bitfields-2.c =================================================================== --- gcc/testsuite/gcc.dg/volatile-bitfields-2.c (revision 0) +++ gcc/testsuite/gcc.dg/volatile-bitfields-2.c (revision 0) @@ -0,0 +1,15 @@ +/* { dg-do run } */ +/* { dg-options "-fstrict-volatile-bitfields" } */ + +extern void abort(void); +struct thing { + volatile unsigned short a: 8; + volatile unsigned short b: 8; +} t = {1,2}; + +int main() +{ + t.a = 3; + if (t.a !=3 || t.b !=2) abort(); + return 0; +} Index: gcc/testsuite/g++.dg/abi/bitfield12.C =================================================================== --- gcc/testsuite/g++.dg/abi/bitfield12.C (revision 182353) +++ gcc/testsuite/g++.dg/abi/bitfield12.C (working copy) @@ -1,4 +1,4 @@ -// { dg-options "-Wabi -fabi-version=1" } +// { dg-options "-Wabi -fabi-version=1 -fno-strict-volatile-bitfields" } struct S { // { dg-warning "ABI" } char c : 1024; // { dg-warning "width" } Index: gcc/testsuite/c-c++-common/abi-bf.c =================================================================== --- gcc/testsuite/c-c++-common/abi-bf.c (revision 0) +++ gcc/testsuite/c-c++-common/abi-bf.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-warning "incompatible" } */ +/* { dg-do compile } */ +/* { dg-options "-fstrict-volatile-bitfields -fabi-version=1" } */ Index: gcc/expr.c =================================================================== --- gcc/expr.c (revision 182353) +++ gcc/expr.c (working copy) @@ -6327,6 +6327,8 @@ || bitpos % GET_MODE_ALIGNMENT (mode)) && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))) || (bitpos % BITS_PER_UNIT != 0))) + || (bitsize >= 0 && mode != BLKmode + && GET_MODE_BITSIZE (mode) > bitsize) /* If the RHS and field are a constant size and the size of the RHS isn't the same size as the bitfield, we must use bitfield operations. */ Index: gcc/stor-layout.c =================================================================== --- gcc/stor-layout.c (revision 182353) +++ gcc/stor-layout.c (working copy) @@ -622,12 +622,13 @@ /* See if we can use an ordinary integer mode for a bit-field. Conditions are: a fixed size that is correct for another mode, occupying a complete byte or bytes on proper boundary, - and not volatile or not -fstrict-volatile-bitfields. */ + and not -fstrict-volatile-bitfields. If the latter is set, + we unfortunately can't check TREE_THIS_VOLATILE, as a cast + may make a volatile object later. */ if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT - && !(TREE_THIS_VOLATILE (decl) - && flag_strict_volatile_bitfields > 0)) + && flag_strict_volatile_bitfields <= 0) { enum machine_mode xmode = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);