https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53037

nsz at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nsz at gcc dot gnu.org

--- Comment #38 from nsz at gcc dot gnu.org ---
(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.
> 

i don't quite understand this reasoning, i would
not expect the internal STRICT_ALIGNMENT setting
to change how types behave (e.g. it might mean
some code errors out, but the semantics of packed
and aligned attributes are not changed).

> > 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.
> 

i don't see this on arm/sparc, instead i see wrong
alignment given:

struct __attribute__ ((aligned (8))) S8 { char a[8]; };
struct __attribute__ ((packed)) S1 { struct S8 s8; };

char a[_Alignof(struct S8)] = {0};
char b[_Alignof(struct S1)] = {0};

compiles into a size 8 array for a and size 1 array for b,
so _Alignof is inconsistent, which i'd expect to be an
error (or warning at least).

> So I think that the absence of warning is correct on strict-alignment
> platforms and that, if you want to make the tests portable, then you must
> use structures whose rounded size is not a power of 2 or is larger than 128
> bits, so that they don't get a scalar mode.

Reply via email to