This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: PATCH to layout_decl for middle-end/27945
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 18 Feb 2008 08:21:25 +0100
- Subject: Re: RFC: PATCH to layout_decl for middle-end/27945
- References: <46E6AF20.7000008@redhat.com> <46E86053.9020105@redhat.com> <46E8BB02.1090607@redhat.com>
> I think a simpler change would be to just select between
>
> DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
>
> and
>
> if (known_align)
> DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), known_align);
>
> for packing, based on a langhook.
I've changed my mind about this stuff and now think that the alignment
promotion is best done in the Ada front-end, more precisely Gigi.
However a change is still needed in layout_decl, something like:
* stor-layout.c (layout_decl): Do not bump the alignment of a
bit-field to more than byte alignment if it is packed.
--
Eric Botcazou
Index: stor-layout.c
===================================================================
--- stor-layout.c (revision 132377)
+++ stor-layout.c (working copy)
@@ -388,13 +388,13 @@ layout_decl (tree decl, unsigned int kno
{
enum machine_mode xmode
= mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
+ unsigned int xalign = GET_MODE_ALIGNMENT (xmode);
if (xmode != BLKmode
- && (known_align == 0
- || known_align >= GET_MODE_ALIGNMENT (xmode)))
+ && !(xalign > BITS_PER_UNIT && DECL_PACKED (decl))
+ && (known_align == 0 || known_align >= xalign))
{
- DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
- DECL_ALIGN (decl));
+ DECL_ALIGN (decl) = MAX (xalign, DECL_ALIGN (decl));
DECL_MODE (decl) = xmode;
DECL_BIT_FIELD (decl) = 0;
}