https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66337
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |documentation --- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> --- I agree that changing the alignment of all members of type double to 8 regardless of the option would not be correct (apologies if what I said suggested otherwise). What is unexpected is the __alignof__ result for the first member, for at least three reasons: 1) The first member cannot be aligned on a less restrictive boundary than the containing struct. The XLC result makes more, and more closely reflects the ABI requirements (see the RISC System/6000 alignment rules below). 2) It is at odds with the GCC documentation of __alignof__ which says: "If the operand of __alignof__ is an lvalue rather than a type, its value is the required alignment for its type, taking into account any minimum alignment specified with GCC's __attribute__ extension..." The sentence implies that the __alignof__ result for a double member of a struct declared without any __attribute__ extension should be __alignof__(double), which is 8 regardless of -malign-power. 3) The result (or rather the fact that the -malign-power option affects the alignment of struct and union members, not types) is contradicted by the GCC documentation of the option which specifically says it affects the alignment of types (it doesn't mention struct members at all): "On AIX, 32-bit Darwin, and 64-bit PowerPC GNU/Linux, the option -malign-natural overrides the ABI-defined alignment of larger types, such as floating-point doubles, on their natural size-based boundary." If changing __alignof__ to match XLC is not desirable or practical (I haven't looked into the implementation in enough detail to have a sense of how feasible it might be), I think the the manual would benefit from being clarified in two ways: 1) The description of __alignof__ should allow for the compiler adjusting the alignment of struct members as if by applying __attribute__ aligned "behind the scenes." Perhaps by rewording the sentence quoted in (2) above along these lines: "If the operand of __alignof__ is an lvalue rather than a type, its value is the required alignment for its type, taking into account any minimum alignment either explicitly specified using attribute aligned or equivalent, or for struct members, implicitly applied as required by the target ABI..." 2) The description of the -malign-power option could also stand to be corrected to refer to struct and union members and not to types. Something similar to what the XLC manual says about -qalign=power: "Uses the RISC System/6000 alignment rules. This is the default." and about -qalign=natural: "Structure members are mapped to their natural boundaries. This has the same effect as the power suboption, except that it also applies alignment rules to double and long double members that are not the first member of a structure or union." The RISC System/6000 alignment rules are described in Appendix H. RISC System/6000 Alignment Rules of C for AIX User's Guide (e.g., http://www-01.ibm.com/software/awdtools/caix/downloads/caix50.pdf). They state: "On the RISC System/6000 system, if a double is the first member of a struct, it is 8-byte (doubleword) aligned. If a long double is the first member of a struct, it is 16-byte aligned."