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

--- Comment #32 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> 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.

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