From: Doug Kwan Date: Thu, 22 Dec 2011 19:36:46 +0000 (+0000) Subject: backport: [multiple changes] X-Git-Tag: releases/gcc-4.6.3~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38854abd48e66ac1819063b0513db184be9e560f;p=thirdparty%2Fgcc.git backport: [multiple changes] 2011-12-22 Doug Kwan Backport from mainline 2011-03-23 Julian Brown * expr.c (expand_expr_real_1): Only use BLKmode for volatile accesses which are not naturally aligned. 2011-11-20 Joey Ye * expr.c (expand_expr_real_1): Correctly handle strict volatile bitfield loads smaller than mode size. 2011-12-22 Doug Kwan Backport from mainline 2011-11-20 Joey Ye * gcc.dg/volatile-bitfields-1.c: New. From-SVN: r182635 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9135dcfeea6b..02d2aa5916ad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2011-12-22 Doug Kwan + + Backport from mainline + 2011-03-23 Julian Brown + + * expr.c (expand_expr_real_1): Only use BLKmode for volatile + accesses which are not naturally aligned. + + 2011-11-20 Joey Ye + + * expr.c (expand_expr_real_1): Correctly handle strict volatile + bitfield loads smaller than mode size. + 2011-12-21 Richard Earnshaw PR target/51643 diff --git a/gcc/expr.c b/gcc/expr.c index c4a00aa3f780..6bf9f2489dab 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 86ca26fccf47..24bdfd049288 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-12-22 Doug Kwan + + Backport from mainline + 2011-11-20 Joey Ye + + * gcc.dg/volatile-bitfields-1.c: New. + 2011-12-21 Richard Earnshaw 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 index 000000000000..6adda27fea4c --- /dev/null +++ b/gcc/testsuite/gcc.dg/volatile-bitfields-1.c @@ -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; +}