expr.c (store_field): Avoid a direct store if the mode is larger than the size of...
authorBernd Schmidt <bernds@codesourcery.com>
Tue, 20 Dec 2011 16:46:22 +0000 (16:46 +0000)
committerBernd Schmidt <bernds@gcc.gnu.org>
Tue, 20 Dec 2011 16:46:22 +0000 (16:46 +0000)
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.
* config/arm/arm.c (arm_option_override): Don't enable
flag_strict_volatile_bitfields if the ABI version is less than 2.
* config/h8300/h8300.c (h8300_option_override): Likewise.
* config/rx/rx.c (rx_option_override): Likewise.
* config/m32c/m32c.c (m32c_option_override): Likewise.
* config/sh/sh.c (sh_option_override): Likewise.

gcc/testsuite/
* gcc.target/arm/volatile-bitfields-4.c: New test.
* c-c++-common/abi-bf.c: New test.

From-SVN: r182545

12 files changed:
gcc/ChangeLog
gcc/config/arm/arm.c
gcc/config/h8300/h8300.c
gcc/config/m32c/m32c.c
gcc/config/rx/rx.c
gcc/config/sh/sh.c
gcc/expr.c
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/abi-bf.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c [new file with mode: 0644]
gcc/toplev.c

index 2dd1cc00b259debaf7f7684cccac6e0a561b7816..dc47ebeece08fbb6c12b1fafcca1815eab0d72ea 100644 (file)
@@ -1,3 +1,19 @@
+2011-12-20  Bernd Schmidt  <bernds@codesourcery.com>
+
+       PR middle-end/51200
+       * 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.
+       * config/arm/arm.c (arm_option_override): Don't enable
+       flag_strict_volatile_bitfields if the ABI version is less than 2.
+       * config/h8300/h8300.c (h8300_option_override): Likewise.
+       * config/rx/rx.c (rx_option_override): Likewise.
+       * config/m32c/m32c.c (m32c_option_override): Likewise.
+       * config/sh/sh.c (sh_option_override): Likewise.
+
 2011-12-20  Richard Guenther  <rguenther@suse.de>
 
        PR lto/46796
index 3d3c4523c756353841c4f920a337d3286feaf686..b6d619ee7386a7155ae7bce7d239e1ea9bd7baf6 100644 (file)
@@ -1989,7 +1989,8 @@ arm_option_override (void)
                           global_options_set.x_param_values);
 
   /* ARM EABI defaults to strict volatile bitfields.  */
-  if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0)
+  if (TARGET_AAPCS_BASED && flag_strict_volatile_bitfields < 0
+      && abi_version_at_least(2))
     flag_strict_volatile_bitfields = 1;
 
   /* Enable sw prefetching at -O3 for CPUS that have prefetch, and we have deemed
index c5603934372558285cb2091bea3572a78c968eb2..3911cd4dda45b77210fe6785f8f13ddb8ddd19d1 100644 (file)
@@ -409,7 +409,7 @@ h8300_option_override (void)
     }
 
   /* This target defaults to strict volatile bitfields.  */
-  if (flag_strict_volatile_bitfields < 0)
+  if (flag_strict_volatile_bitfields < 0 && abi_version_at_least(2))
     flag_strict_volatile_bitfields = 1;
 }
 
index 04f690506098fffc1669a62fb4b5343e4b08d63c..d86a618b02828186b0dfccc02821b1302e3ebb84 100644 (file)
@@ -417,7 +417,7 @@ m32c_option_override (void)
     flag_ivopts = 0;
 
   /* This target defaults to strict volatile bitfields.  */
-  if (flag_strict_volatile_bitfields < 0)
+  if (flag_strict_volatile_bitfields < 0 && abi_version_at_least(2))
     flag_strict_volatile_bitfields = 1;
 
   /* r8c/m16c have no 16-bit indirect call, so thunks are involved.
index c9720eb3e155713fe040955281ffb0998ad520a1..4a73285b3389ddffa08e02b0a260deaf373208ab 100644 (file)
@@ -2571,7 +2571,7 @@ rx_option_override (void)
     }
 
   /* This target defaults to strict volatile bitfields.  */
-  if (flag_strict_volatile_bitfields < 0)
+  if (flag_strict_volatile_bitfields < 0 && abi_version_at_least(2))
     flag_strict_volatile_bitfields = 1;
 
   rx_override_options_after_change ();
index b9834fb5c9f2a57dc1ce8e9ca164d0543fee440e..1b289ad29d30e0866a288a60842d6a5061f684cf 100644 (file)
@@ -842,7 +842,7 @@ sh_option_override (void)
     sh_fix_range (sh_fixed_range_str);
 
   /* This target defaults to strict volatile bitfields.  */
-  if (flag_strict_volatile_bitfields < 0)
+  if (flag_strict_volatile_bitfields < 0 && abi_version_at_least(2))
     flag_strict_volatile_bitfields = 1;
 }
 \f
index aa78468a96be92b854327e28bea6063600696a70..5747a1709ee9607d39eac713baf1efc1fb922bcc 100644 (file)
@@ -6327,6 +6327,8 @@ store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
                || 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 359541e02df98a52c2d85c4558bc4374a4bfd8e0..35320c2fad9ad936b4210ab7bfc2662afa446605 100644 (file)
@@ -622,12 +622,13 @@ layout_decl (tree decl, unsigned int known_align)
          /* 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);
index 0f947a944f02b7ab001314c24deeee9ba88b53e3..8cb5093cb64faffb750fee53c9832aa742e95fff 100644 (file)
@@ -1,3 +1,9 @@
+2011-12-20  Bernd Schmidt  <bernds@codesourcery.com>
+
+       PR middle-end/51200
+       * gcc.target/arm/volatile-bitfields-4.c: New test.
+       * c-c++-common/abi-bf.c: New test.
+
 2011-12-20  Dodji Seketeli  <dodji@redhat.com>
 
        PR debug/49951
diff --git a/gcc/testsuite/c-c++-common/abi-bf.c b/gcc/testsuite/c-c++-common/abi-bf.c
new file mode 100644 (file)
index 0000000..05b8986
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-warning "incompatible" } */
+/* { dg-do compile } */
+/* { dg-options "-fstrict-volatile-bitfields -fabi-version=1" } */
diff --git a/gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c b/gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c
new file mode 100644 (file)
index 0000000..805dab1
--- /dev/null
@@ -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 766aa9917c325067f3a6f37435e1f3098054cb6c..efce98fa30fa5d898cd94fc1de4384ca74c19115 100644 (file)
@@ -1330,6 +1330,13 @@ process_options (void)
     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-bitfield 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)