http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48124
Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|52080 | --- Comment #9 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-02-01 12:34:55 UTC --- Simpler patch I am going to test. Let's hope the wreckage adjust_address does to the to_rtx MEM (apart from setting its mode) is harmless. Index: expr.c =================================================================== --- expr.c (revision 183791) +++ expr.c (working copy) @@ -4705,6 +4705,21 @@ expand_assignment (tree to, tree from, b to_rtx = adjust_address (to_rtx, mode1, 0); else if (GET_MODE (to_rtx) == VOIDmode) to_rtx = adjust_address (to_rtx, BLKmode, 0); + /* If the alignment of tem is larger than its size and we + are performing a bitfield access limit the mode we use + for the access to make sure we do not access the decl + beyond its end. See PR48124. */ + else if (GET_MODE (to_rtx) == BLKmode + && mode1 == VOIDmode + && DECL_P (tem) + && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST + && TREE_INT_CST_LOW (DECL_SIZE (tem)) % DECL_ALIGN (tem)) + { + mode1 = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (tem)) + % DECL_ALIGN (tem), + MODE_INT, 0); + to_rtx = adjust_address (to_rtx, mode1, 0); + } } if (offset != 0)