[backport from ARM/embedded-4_6-branch, fix PR51200 yet another strict volatile bitfields bug for ARM ] From: "Joey Ye" To: Subject: [arm-embedded] Fix restrict volatile bitfield List-Archive: Committed to ARM/embedded-4_6-branch Partly apply restrict volatile bitfield fix from bernd. 2010-12-02 Bernd Schmidt * 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. testsuite: 2011-11-23 Joey Ye * g++.dg/abi/bitfield12.C: Add option -fno-strict-volatile-bitfields. --- gcc-4.6.2/gcc/expr.c.~1~ 2011-08-10 11:17:32.000000000 +0200 +++ gcc-4.6.2/gcc/expr.c 2011-12-10 16:08:44.000000000 +0100 @@ -5861,6 +5861,8 @@ store_field (rtx target, HOST_WIDE_INT b || 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. */ --- gcc-4.6.2/gcc/stor-layout.c.~1~ 2011-04-05 16:34:51.000000000 +0200 +++ gcc-4.6.2/gcc/stor-layout.c 2011-12-10 16:08:44.000000000 +0100 @@ -660,12 +660,13 @@ 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, 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); --- gcc-4.6.2/gcc/testsuite/g++.dg/abi/bitfield12.C.~1~ 2003-09-15 02:27:16.000000000 +0200 +++ gcc-4.6.2/gcc/testsuite/g++.dg/abi/bitfield12.C 2011-12-10 16:08:44.000000000 +0100 @@ -1,4 +1,4 @@ -// { dg-options "-Wabi -fabi-version=1" } +// { dg-options "-Wabi -fabi-version=1 -fno-strict-volatile-bitfields" } struct S { // { dg-warning "ABI" } char c : 1024; // { dg-warning "width" }