From patchwork Thu Sep 2 15:35:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Zhang X-Patchwork-Id: 63497 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 03981B7186 for ; Fri, 3 Sep 2010 01:36:06 +1000 (EST) Received: (qmail 30959 invoked by alias); 2 Sep 2010 15:36:00 -0000 Received: (qmail 30942 invoked by uid 22791); 2 Sep 2010 15:35:58 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Sep 2010 15:35:21 +0000 Received: (qmail 1365 invoked from network); 2 Sep 2010 15:35:19 -0000 Received: from unknown (HELO ?192.168.1.106?) (jie@127.0.0.2) by mail.codesourcery.com with ESMTPA; 2 Sep 2010 15:35:19 -0000 Message-ID: <4C7FC42E.10208@codesourcery.com> Date: Thu, 02 Sep 2010 23:35:10 +0800 From: Jie Zhang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100821 Icedove/3.1.2 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: Default to -fstrict-volatile-bitfields for ARM EABI 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 -fstrict-volatile-bitfields should also be default for ARM EABI. This patch does it. I also copied volatile-bitfields-1.c and volatile-bitfields-2.c from i386 target subdirectory and tweaked for ARM. For gcc.target/arm/volatile-bitfields-3.c, we need the change of stor-layout.c in this patch. Tested for arm-none-eabi. There are some regressions for gcc.c-torture/execute/20010518-2.c. When compile the test, gcc reports the warning and note: 20010518-2.c: In function 'main': 20010518-2.c:34:21: warning: mis-aligned access used for structure member [-fstrict-volatile-bitfields] 20010518-2.c:34:21: note: When a volatile object spans multiple type-sized locations, the compiler must choose between using a single mis-aligned access to preserve the volatility, or using multiple aligned accesses to avoid runtime faults. This code may fail at runtime if the hardware does not allow this access. So I think this test should be disabled for all targets which default to -fstrict-volatile-bitfields. If this is what we should do, I will update my patch to disable it for all such targets. Any comments? Thanks, * stor-layout.c (layout_decl): Use the field's type to determine the mode and keep DECL_BIT_FIELD for a volatile bit-field. * config/arm/arm.c (arm_override_options): Default to -fstrict-volatile-bitfields. testsuite/ * gcc.target/arm/volatile-bitfields-1.c: New test. * gcc.target/arm/volatile-bitfields-2.c: New test. * gcc.target/arm/volatile-bitfields-3.c: New test. Index: testsuite/gcc.target/arm/volatile-bitfields-1.c =================================================================== --- testsuite/gcc.target/arm/volatile-bitfields-1.c (revision 0) +++ testsuite/gcc.target/arm/volatile-bitfields-1.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile { target arm*-*-eabi* } } */ +/* { dg-options "-O2" } */ + +typedef struct { + char a:1; + char b:7; + int c; +} BitStruct; + +volatile BitStruct bits; + +int foo () +{ + return bits.b; +} + +/* { dg-final { scan-assembler "ldrb\[\\t \]+.*,\[\\t \]*\\\[.*\\\]" } } */ Index: testsuite/gcc.target/arm/volatile-bitfields-2.c =================================================================== --- testsuite/gcc.target/arm/volatile-bitfields-2.c (revision 0) +++ testsuite/gcc.target/arm/volatile-bitfields-2.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile { target arm*-*-eabi* } } */ +/* { dg-options "-O2" } */ + +typedef struct { + volatile unsigned long a:8; + volatile unsigned long b:8; + volatile unsigned long c:16; +} BitStruct; + +BitStruct bits; + +unsigned long foo () +{ + return bits.b; +} + +/* { dg-final { scan-assembler "ldr\[\\t \]+.*,\[\\t \]*\\\[.*\\\]" } } */ Index: testsuite/gcc.target/arm/volatile-bitfields-3.c =================================================================== --- testsuite/gcc.target/arm/volatile-bitfields-3.c (revision 0) +++ testsuite/gcc.target/arm/volatile-bitfields-3.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile { target arm*-*-eabi* } } */ +/* { dg-options "-O2" } */ + +typedef struct { + volatile unsigned long a:8; + volatile unsigned long b:8; + volatile unsigned long c:16; +} BitStruct; + +BitStruct bits; + +unsigned long foo () +{ + return bits.c; +} + +/* { dg-final { scan-assembler "ldr\[\\t \]+.*,\[\\t \]*\\\[.*\\\]" } } */ Index: stor-layout.c =================================================================== --- stor-layout.c (revision 163756) +++ stor-layout.c (working copy) @@ -591,11 +591,14 @@ layout_decl (tree decl, unsigned int kno } /* See if we can use an ordinary integer mode for a bit-field. - Conditions are: a fixed size that is correct for another mode - and occupying a complete byte or bytes on proper boundary. */ + 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. */ if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST - && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT) + && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT + && !(TREE_THIS_VOLATILE (decl) + && flag_strict_volatile_bitfields > 0)) { enum machine_mode xmode = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1); Index: config/arm/arm.c =================================================================== --- config/arm/arm.c (revision 163756) +++ config/arm/arm.c (working copy) @@ -1916,6 +1916,10 @@ arm_override_options (void) calculation, which is 2 instructions. */ set_param_value ("gcse-unrestricted-cost", 2); + /* ARM EABI defaults to strict volatile bitfields. */ + if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0) + flag_strict_volatile_bitfields = 1; + /* Register global variables with the garbage collector. */ arm_add_gc_roots (); }