]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorJoey Ye <joey.ye@arm.com>
Thu, 29 Mar 2012 02:15:29 +0000 (02:15 +0000)
committerJoey Ye <jye2@gcc.gnu.org>
Thu, 29 Mar 2012 02:15:29 +0000 (02:15 +0000)
2012-03-28  Joey Ye  <joey.ye@arm.com>

Backported from mainline
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-22  Joey Ye  <joey.ye@arm.com>

* toplev.c (process_options): Fix typo.

testcases:

Backported from mainline
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-26  Joey Ye  <joey.ye@arm.com>

PR middle-end/51200
* gcc.dg/volatile-bitfields-2.c: New test.

From-SVN: r185944

13 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.dg/volatile-bitfields-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/volatile-bitfields-4.c [new file with mode: 0644]
gcc/toplev.c

index 4b4c1257513e8ed59968b12b67f9cfc86e712447..d0d0236433271723082f676ea67116f576850b8f 100644 (file)
@@ -1,3 +1,26 @@
+2012-03-28  Joey Ye  <joey.ye@arm.com>
+
+       Backported from mainline
+       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-22  Joey Ye  <joey.ye@arm.com>
+
+       * toplev.c (process_options): Fix typo.
+
 2012-03-28  Martin Jambor  <mjambor@suse.cz>
 
        Backported from mainline
index 49c2a75bdbc5dd1dfbf8a10088fac658add57247..a5edf04b9ed6f6bbd3b2361ecd51515ca78f4e0c 100644 (file)
@@ -2005,7 +2005,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 834fc992fc1fe7e0166175629875023d8010694b..55acfff5c0b9ce93e0838eeadc803536e937609f 100644 (file)
@@ -416,7 +416,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 83bf86c2071f1a0e2eb6bfe553b9e09721d73a57..9b4a5a95c1852c26bc41f80a0c96a82202c9d05e 100644 (file)
@@ -447,7 +447,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 a2d48abd29614869d5af68736d80c61f4c49963d..392e2ff80393e3263ec4fe4c45ac8a3fe8eaf0c8 100644 (file)
@@ -2348,7 +2348,7 @@ static void
 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 ee80028e5bd2560fc958b7ba3817ec9a3e7e602f..6ac593e839e13d043fffb7763b2ceaa9dcdfdddd 100644 (file)
@@ -1018,7 +1018,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 0ccdd2e00dba43d3c2a4cfb28e5c6acc196e59fc..83ecc039abf09cdbb4774977141d11235e20ec4c 100644 (file)
@@ -5971,6 +5971,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 0396c8cdd3d0c258eb01f96c54f8987fb00aa1ee..4e7454d3aea832240005873f2fe983fa99e33165 100644 (file)
@@ -660,12 +660,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 e93779ede0f0065e443f3d821994bde379bdb13f..9dcfc25b8891744e26d6777921d38764a6a9e413 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-28  Joey Ye  <joey.ye@arm.com>
+
+       Backported from mainline
+       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-26  Joey Ye  <joey.ye@arm.com>
+
+       PR middle-end/51200
+       * gcc.dg/volatile-bitfields-2.c: New test.
+
 2012-03-28  Martin Jambor  <mjambor@suse.cz>
 
        Backported from mainline
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.dg/volatile-bitfields-2.c b/gcc/testsuite/gcc.dg/volatile-bitfields-2.c
new file mode 100644 (file)
index 0000000..a57cd74
--- /dev/null
@@ -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;
+}
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 64af11200e9f2ac0fa7cb2ae03b78229714e3831..2b0f06d5679361f458887a88cbe9a3377d825601 100644 (file)
@@ -1326,6 +1326,13 @@ process_options (void)
           "and -ftree-loop-linear)");
 #endif
 
+  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)