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



--- Comment #4 from Andreas Kasberger <kasberger at heidenhain dot de> 
2012-11-26 07:21:51 UTC ---

(In reply to comment #2)

> Hmm, it seems that for ms-bitfields the default-field-alignment overrides all

> field-local alignments.  I wouldn't assume that __attribute__((packed)) is

> directly related to this issue, but of course it is close to it.  For the

> packed-case the issue seems to be that it isn't used for the fields, but for

> the last element in struct/union.

> 

> Btw the testcase works nice, if you use in front a #pragma pack(4).



I was also noticing the option f-pack-struct=4 will let the example running

fine.



Hmm....the option -mno-align-double is doing the alignment on one word boundary





(In reply to comment #3)

> It is not working with gcc 4.6.2 or 4.7. I tried an old compiler gcc 3.4.3 and

> the behavior was correct(In reply to comment #1)

> > Possibly related to PR52991 (-mms-bitfields breaks attribute((packed))).

> 

> I tested both versions as well and same behavior

> I tried an old compiler gcc 3.4.3 and the behavior was correct.



(In reply to comment #2)

> Hmm, it seems that for ms-bitfields the default-field-alignment overrides all

> field-local alignments.  I wouldn't assume that __attribute__((packed)) is

> directly related to this issue, but of course it is close to it.  For the

> packed-case the issue seems to be that it isn't used for the fields, but for

> the last element in struct/union.

> 

> Btw the testcase works nice, if you use in front a #pragma pack(4).





Yes, you are are right. I noticed that a -fpack-struct=4 doing it correctly. 



Hmm... -mno-align-double documentation says

-malign-double

-mno-align-double

Control whether GCC aligns double, long double, and long long variables on a

two word boundary or a one word boundary. Aligning double variables on a two

word boundary will produce code that runs somewhat faster on a Pentium at the

expense of more memory.



So what I understand is that -mno-align-double will do the boundary on one word

boundary.



-fpack-struct=4 documentation says

-fpack-struct[=n]

Without a value specified, pack all structure members together without holes.

When a value is specified (which must be a small power of two), pack structure

members according to this value, representing the maximum alignment (that is,

objects with default alignment requirements larger than this are output

potentially unaligned at the next fitting location.



In this case this would mean I would do the alignment on a double word

boundary.



The ms compiler option /zp4 will also do the alignment on double word boundary.

documentation:

The command-line option /Zp (Struct Member Alignment) sets the packsize to n,

in which n can be 1, 2, 4, 8, or 16, and in which 8 is the default.



Now I'm totally confused.



I will try to find out more and come back

Reply via email to