------- Comment #33 from mark at codesourcery dot com  2006-01-19 16:59 -------
Subject: Re:  [3.4/4.0/4.1/4.2 Regression] bitfield
 layout change (regression?)

matz at suse dot de wrote:
> ------- Comment #32 from matz at suse dot de  2006-01-19 14:44 -------
> Mark, I agree that it's saner when both structures (with #pragma pack and
> attribute packed) have the same length of 8 on i686 and x86_64 (because
> the bitfield was declared 'int' in difference to 'long' for instance).
> 
> Then I have a question to clarify if I understood correctly: by remembering
> the original maximum_field_alignment and using that for zero-sized bitfields
> you want to use the absolute first, default, m_f_a, or the one last set
> before the innermost #pragma pack?  Consider an example like so, and lets
> assume the initial max field alignment was 4:
> 
> mfa == 4
> #pragma pack(2)         // 1  mfa == 2
> #pragma pack(1)         // 2  mfa == 1
> #pragma pack()          // 3  mfa == 4
> #pragma pack (push,2)   // 4  mfa == 2
> #pragma pack (push,1)   // 5  mfa == 1
> #pragma pop             // 6  mfa == 2
> #pragma pop             // 7  mfa == 4
> 
> With what would you constrain the alignment of a zero sized bitfield
> at each of the seven points?  

I'm suggesting that a zero-width bitfield have the same alignment
influence at all 7 points.  In your example, mfa would be effectively
four at all 7 points.

> What if the initial mfa is 0 (i.e. not set)?

Then, it should be zero at all seven points, meaning that a zero-width
bitfield of type T would force alignment to whatever alignment a field
of type T would have.

> Should -fpack-struct=... (which influences the initial mfa) influence
> that constraint too, or not?

That's harder, but I think it should.  The point is basically that,
independent of #pragma pack, a zero-width bitfield should give you the
alignment it would give you oustide of the #pragma packs.

> My opinion is, that at each of the seven points above we should constrain
> with the initial mfa (i.e. 4 in the example above), as adjusted by
> the -fpack-struct command line option.

Good, we agree!

> Another point: If we make the structure with attribute packed on both x86 and
> x86-64 be eight long (to agree with the behaviour of using pragma), then we
> do add another variant unfortunately.  In pre 3.4 that structure was 12 on
> x86-64 (which I think was an actual error).

That's unfortunate, but given that things are moving around, I think we
should go for maximum sanity.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22275

Reply via email to