https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53037
--- Comment #33 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Eric Botcazou from comment #32) > > Sparc defines STRICT_ALIGNMENT which leads to > > > > unsigned mode_align = GET_MODE_ALIGNMENT (TYPE_MODE (type)); > > > > /* Don't override a larger alignment requirement coming from a user > > alignment of one of the fields. */ > > if (mode_align >= TYPE_ALIGN (type)) > > { > > SET_TYPE_ALIGN (type, mode_align); > > TYPE_USER_ALIGN (type) = 0; > > } > > > > so __attribute__ ((packed)) is basically ignored on Sparc. > > I don't think that's correct. Simply, on strict-alignment targets, you > cannot have an aggregate type less aligned than its scalar mode, if any; for > other targets, that's only true for scalar types. But you can have an > aggregate type with alignment 1 if it has BLKmode. > > > diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c > > index 3028d55773a..6dd605810ac 100644 > > --- a/gcc/stor-layout.c > > +++ b/gcc/stor-layout.c > > @@ -1784,7 +1784,7 @@ finalize_type_size (tree type) > > > > /* Don't override a larger alignment requirement coming from a user > > alignment of one of the fields. */ > > - if (mode_align >= TYPE_ALIGN (type)) > > + if (mode_align > TYPE_ALIGN (type)) > > { > > SET_TYPE_ALIGN (type, mode_align); > > TYPE_USER_ALIGN (type) = 0; > > > > works with cross compiler. > > The existing code works as intended: if the alignment given by the mode is > larger than or equal to the type's alignment, then this alignment given by > the mode becomes the natural alignment and TYPE_USER_ALIGN becomes > obsolete/wrong. We should add a testcase to show there is a difference in generated code on Sparc.