This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch c/c++]: Fix for PR c/52991 issue about ignored packed-attribute for ms-structure-layout


On Wed, Dec 12, 2012 at 4:11 PM, Richard Henderson <rth@redhat.com> wrote:
> On 12/12/2012 02:57 AM, Richard Biener wrote:
>> That looks wrong.  Having both TYPE_PACKED and TYPE_ALIGN != BITS_PER_UNIT
>> is inconsistent, so this part of the patch should not be necessary.
>
> No, that is the only way to give a 4 byte int 2 byte alignment:
> use both packed and aligned attributes.
>
> struct S {
>   char x;
>   int y;
> };
>
> struct T {
>   char x;
>   int y __attribute__((aligned(2)));
> };
>
> struct U {
>   char x;
>   int y __attribute__((packed, aligned(2)));
> };
>
> int s_y = __builtin_offsetof(struct S, y);
> int t_y = __builtin_offsetof(struct T, y);
> int u_y = __builtin_offsetof(struct U, y);

But the patch changes it for the RECORD_TYPE case and

struct T __attribute__((packed,aligned(2))) {
   char x;
   short s;
   char y;
   short a;
};
struct T x;

doesn't work as I would have expected (giving x.x and x.a 2-byte alignment).

In fact, the type attribute docs for 'packed' only say that fields are packed,
not that alignment of the type itself is affected (and 'aligned' is not specifed
in the docs for types at all it seems).

Richard.

>
> r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]