This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, middle end] Fix PR 35496, wrong alignment of MS bitfield layout for DImode types
- From: Uros Bizjak <ubizjak at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: dominiq at lps dot ens dot fr, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Mon, 10 Mar 2008 22:42:38 +0100
- Subject: [PATCH, middle end] Fix PR 35496, wrong alignment of MS bitfield layout for DImode types
Hello!
H.J.'s patch to align DImode values to 4 bytes exposed a problem with MS
bitfields, where it is assumed, that the alignment of underlying types
is always set to their natural alignment (8 bytes for DImode).
Attached patch corrects this assumption by aligning underlying type of a
MS bitfield to the largest of either the natural alignment of the type
or its default alignment. According to the comment above the patched
section, all these complications were figured out experimentally, so we
now leave the layout of a MS bitfield as it was before H.J.'s patch.
Since all this functionality is checked by relevant tests in the
testsuite, this patch fixes a couple of introduced regressions on
i686-apple-darwin.
2008-03-10 Uros Bizjak <ubizjak@gmail.com>
PR target/35496
* stor-layout.c (update_alignment_for_field): Set minimum alignment
of the underlying type of a MS bitfield layout to the natural
alignment of the type.
Patch was bootstrapped and regression tested by Dominique on
i686-apple-darwin [1]. OK for 4.4?
[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35496#c20
Uros.
Index: stor-layout.c
===================================================================
--- stor-layout.c (revision 133091)
+++ stor-layout.c (working copy)
@@ -699,6 +699,9 @@ update_alignment_for_field (record_layou
&& ! integer_zerop (DECL_SIZE (rli->prev_field)))))
{
unsigned int type_align = TYPE_ALIGN (type);
+ unsigned int type_size
+ = tree_low_cst (TYPE_SIZE (type), 1);
+ type_align = MAX (type_align, type_size);
type_align = MAX (type_align, desired_align);
if (maximum_field_alignment != 0)
type_align = MIN (type_align, maximum_field_alignment);