]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorDoug Kwan <dougkwan@google.com>
Thu, 22 Dec 2011 19:36:46 +0000 (19:36 +0000)
committerDJ Delorie <dj@gcc.gnu.org>
Thu, 22 Dec 2011 19:36:46 +0000 (14:36 -0500)
2011-12-22  Doug Kwan  <dougkwan@google.com>

Backport from mainline
2011-03-23  Julian Brown  <julian@codesourcery.com>

* expr.c (expand_expr_real_1): Only use BLKmode for volatile
accesses which are not naturally aligned.

2011-11-20  Joey Ye  <joey.ye@arm.com>

* expr.c (expand_expr_real_1): Correctly handle strict volatile
bitfield loads smaller than mode size.

2011-12-22  Doug Kwan  <dougkwan@google.com>

Backport from mainline
2011-11-20  Joey Ye  <joey.ye@arm.com>

* gcc.dg/volatile-bitfields-1.c: New.

From-SVN: r182635

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/volatile-bitfields-1.c [new file with mode: 0644]

index 9135dcfeea6b6cbd005ab9afb72b9e0592ec02f4..02d2aa5916ada476f5bfac6cf52acd99a1166304 100644 (file)
@@ -1,3 +1,16 @@
+2011-12-22  Doug Kwan  <dougkwan@google.com>
+
+       Backport from mainline
+       2011-03-23  Julian Brown  <julian@codesourcery.com>
+
+       * expr.c (expand_expr_real_1): Only use BLKmode for volatile
+       accesses which are not naturally aligned.
+
+       2011-11-20  Joey Ye  <joey.ye@arm.com>
+
+       * expr.c (expand_expr_real_1): Correctly handle strict volatile
+       bitfield loads smaller than mode size.
+
 2011-12-21  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/51643
index c4a00aa3f7806432066eea94d6c13d6ef84bac60..6bf9f2489dab4a31f29cc932c52559e2f3ae491c 100644 (file)
@@ -9189,8 +9189,16 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
                && modifier != EXPAND_CONST_ADDRESS
                && modifier != EXPAND_INITIALIZER)
            /* If the field is volatile, we always want an aligned
-              access.  */
-           || (volatilep && flag_strict_volatile_bitfields > 0)
+              access.  Do this in following two situations:
+              1. the access is not already naturally
+              aligned, otherwise "normal" (non-bitfield) volatile fields
+              become non-addressable.
+              2. the bitsize is narrower than the access size. Need
+              to extract bitfields from the access.  */
+           || (volatilep && flag_strict_volatile_bitfields > 0
+               && (bitpos % GET_MODE_ALIGNMENT (mode) != 0 
+                   || (mode1 != BLKmode
+                       && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)))
            /* If the field isn't aligned enough to fetch as a memref,
               fetch it as a bit field.  */
            || (mode1 != BLKmode
index 86ca26fccf479eddc7b87c5a5a97300f0b74ca13..24bdfd04928833d64ee0d5bccaa0d8bdce3097be 100644 (file)
@@ -1,3 +1,10 @@
+2011-12-22  Doug Kwan  <dougkwan@google.com>
+
+       Backport from mainline
+       2011-11-20  Joey Ye  <joey.ye@arm.com>
+
+       * gcc.dg/volatile-bitfields-1.c: New.
+
 2011-12-21  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/51643
diff --git a/gcc/testsuite/gcc.dg/volatile-bitfields-1.c b/gcc/testsuite/gcc.dg/volatile-bitfields-1.c
new file mode 100644 (file)
index 0000000..6adda27
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-options "-fstrict-volatile-bitfields" } */
+/* { dg-do run } */
+
+extern int puts(const char *);
+extern void abort(void) __attribute__((noreturn));
+
+typedef struct {
+  volatile unsigned short a:8, b:8;
+} BitStruct;
+
+BitStruct bits = {1, 2};
+
+void check(int i, int j)
+{
+  if (i != 1 || j != 2) puts("FAIL"), abort();
+}
+
+int main ()
+{
+  check(bits.a, bits.b);
+
+  return 0;
+}