------- Comment #20 from rguenther at suse dot de  2009-05-06 21:02 -------
Subject: Re:  [4.5 Regression] Revision 146817 caused
 unaligned access in gcc.dg/torture/pr26565.c

On Wed, 6 May 2009, matz at gcc dot gnu dot org wrote:

> ------- Comment #19 from matz at gcc dot gnu dot org  2009-05-06 20:39 -------
> Something like this implements option 1.  It's probably hopelessly inefficient
> (always generating a new type for each packed field), and wrong, and generally
> just a bad idea, but it does fix the testcase, execute.exp still works and
> bootstrap is already in the target libs :)
> And it only deals with packed fields, not those having an aligned() attribute.
> 
> Index: c-common.c
> ===================================================================
> --- c-common.c  (Revision 147187)
> +++ c-common.c  (Arbeitskopie)
> @@ -5813,6 +5813,18 @@ c_init_attributes (void)
>  #undef DEF_ATTR_TREE_LIST
>  }
> 
> +static tree
> +get_aligned_type (tree t, int align)
> +{
> +  tree ret;
> +  if (TYPE_PACKED (t))
> +    return t;

Walking the type variants and searching for what we now build would
fix the inefficiency.  And of course this function needs a comment ;)

> +  ret = build_variant_type_copy (t);
> +  TYPE_ALIGN (ret) = align * BITS_PER_UNIT;
> +  TYPE_USER_ALIGN (ret) = 1;

It seems that only ever place_field looks at this flag.  How
is the effect of setting it here?

Overall I like this patch.

Richard.

> +  return ret;
> +}
> +
>  /* Attribute handlers common to C front ends.  */
> 
>  /* Handle a "packed" attribute; arguments as in
> @@ -5837,7 +5849,10 @@ handle_packed_attribute (tree *node, tre
>                  "%qE attribute ignored for field of type %qT",
>                  name, TREE_TYPE (*node));
>        else
> -       DECL_PACKED (*node) = 1;
> +       {
> +         DECL_PACKED (*node) = 1;
> +         TREE_TYPE (*node) = get_aligned_type (TREE_TYPE (*node), 1);
> +       }
>      }
>    /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
>       used for DECL_REGISTER.  It wouldn't mean anything anyway.
> 
> 
> 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39954

Reply via email to