2012/12/12 Richard Biener <richard.guent...@gmail.com>:
> On Wed, Dec 12, 2012 at 4:11 PM, Richard Henderson <r...@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.

Hmm, I see the attribute aligned explicit mention for types.  See 5.33
Specifying Attributes of Types.
Well, the case to combine aligned and packed attribute seems indeed
not to be explicit mentioned.  Nevertheless documention tells for
packed-attribute for types "This attribute, attached to `struct' or
`union' type definition, specifies that each member of the structure
or union is placed to minimize the memory required.", which implies -
I might be wrong here - that an alignment of 1 is active by default.
So to put those two attributes wiithin one attribute doesn't make
sense, as either the aligned or the packed have to be interpreted.  To
specify within a packed-struct-type for a sepcific variable a special
alignment - as shown in Rth's testcase - makes sense and seems to be
covered by the docs.

Regards,
Kai

Reply via email to