This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Packed union doesn't make the unaligned magic on ms_bitfield
- From: Kaz Kojima <kkojima at rr dot iij4u dot or dot jp>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 09 Jun 2006 08:02:58 +0900 (JST)
- Subject: Packed union doesn't make the unaligned magic on ms_bitfield
Hi,
This is a question rather than a real patch. Sorry for this.
PR 27943 is a wrong-code problem found on sh64-*. The code snippet
union unaligned
{
void *ptr;
} __attribute__((__packed__));
void *foo (void *p)
{
return (((union unaligned *) p)->ptr);
}
reduced from unwind-pe.h:read_encoded_value_with_base is compiled
to an aligned word access on sh64-* which uses ms_bitfiled layout.
It was compiled to an unaligned access before the patch:
r114364 | echristo | 2006-06-05 04:50:48 +0900 (Mon, 05 Jun 2006) | 17 lines
which adds the extra alignment for non bit-field fields always for
the ms_bitfield_layout_p case. The question is whether the packed
attribute should be taken into account or not in this situation.
The attached patch is just my guess to handle non-bitfields and
nonzero-size bitfields in same way with the packed attribute and
it restores the old behavior for sh64-*.
But how should it be handled? Eric and I can't find any abi stuff
about it.
Regards,
kaz
--
*stor-layout.c (update_alignment_for_field): Don't add extra
alignment for packed non-bitfield fields in ms_bitfield_layout_p
code.
diff -uprN ORIG/trunk/gcc/stor-layout.c LOCAL/trunk/gcc/stor-layout.c
--- ORIG/trunk/gcc/stor-layout.c 2006-06-06 10:02:03.000000000 +0900
+++ LOCAL/trunk/gcc/stor-layout.c 2006-06-07 23:16:01.000000000 +0900
@@ -693,7 +693,7 @@ update_alignment_for_field (record_layou
the type, except that for zero-size bitfields this only
applies if there was an immediately prior, nonzero-size
bitfield. (That's the way it is, experimentally.) */
- if (!is_bitfield
+ if ((!is_bitfield && !DECL_PACKED (field))
|| (!integer_zerop (DECL_SIZE (field))
? !DECL_PACKED (field)
: (rli->prev_field