[Bug target/66337] __alignof__(s.d) incorrect for a double member with -malign-power
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Feb 19 03:35:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66337
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thank you for the background. I agree that the __alignof__ operator doesn't
seem to be returning the correct result in this case. Based on the GCC manual,
I would expect __alignof__(member) to evaluate to the alignment of the member's
type, or 8 in this case, not 4.
After some debugging I believe the reduced alignment is due to the definition
of the ADJUST_FIELD_ALIGN macro in config/rs6000/linux64.h. Testing shows even
though the double field alignment is set to 32 bits the overall layout of the
struct (e.g., adjacent fields and padding between them) respects the 64-bit
double alignment. I don't know enough of the history to guess why it's done
this way but this is what I found in commit logs:
/* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */
#undef ADJUST_FIELD_ALIGN
#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
(rs6000_special_adjust_field_align_p ((FIELD), (COMPUTED)) \
? 128 \
: (TARGET_64BIT \
&& TARGET_ALIGN_NATURAL == 0 \
&& TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \
? MIN ((COMPUTED), 32) \
: (COMPUTED))
The comment under it explains why the struct containing the double field is
doubleword aligned:
/* PowerPC64 Linux increases natural record alignment to doubleword if
the first field is an FP double, only if in power alignment mode. */
The ADJUST_FIELD_ALIGN macro was introduced into the rs6000 back end in r56135
with the following comment:
/* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints. */
More information about the Gcc-bugs
mailing list