union unaligned { void *ptr; } __attribute__((__packed__)); void *foo (void *p) { return (((union unaligned *) p)->ptr); } is compiled to an aligned word access on sh64-*. 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
*** Bug 27943 has been marked as a duplicate of this bug. ***
Since you're using the MS abi then for sh64 you'll need to dig up where I'm doing something wrong.
It seems that r114364 adds the extra alignment for non bit-field fields always for the ms_bitfield_layout_p case. It looks the packed attribute should be taken into account, though I'm unsure whether it's the way of ms_bitfield or not. How does this look? --- 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
Well, I suppose the question is whether or not I'm doing something wrong here. The alignment should be added unilaterally (as far as I can tell from the documents that I included in the documentation). Part of the question is what happens with the packed attribute? I've not seen any part of an abi document that includes that. I'm perfectly willing to include your patch in - it shouldn't affect anything else.
I also couldn't find any document refering to it. My patch is just a guess from the behavior for nonzero-size bitfield with the packed attribute appeared in the last 3 lines of my patch. I'd like to send my patch to gcc-patch to get comments for our abi question.
Sure. Sounds good. As I said, the ABI stuff I've seen (and helped write) don't take packed into account anywhere :)
Subject: Bug number PR 27942 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00569.html
Subject: Bug 27942 Author: kkojima Date: Sun Jun 11 23:09:58 2006 New Revision: 114552 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114552 Log: PR middle-end/27942 * stor-layout.c (update_alignment_for_field): Don't add extra alignment for packed non-bitfield fields in ms_bitfield_layout_p code. * gcc.dg/attr-ms_struct-packed1.c: New. Added: trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c Modified: trunk/gcc/ChangeLog trunk/gcc/stor-layout.c trunk/gcc/testsuite/ChangeLog
Fixed.