[C++ PATCH] Fix alignment handling in build_cplus_array_type/cp_build_qualified_type_real (PR c++/65690)

Jakub Jelinek jakub@redhat.com
Thu Apr 9 09:39:00 GMT 2015


On Wed, Apr 08, 2015 at 12:02:39PM +0200, Jakub Jelinek wrote:
> The included (first) patch has been successfully bootstrapped/regtested on
> x86_64-linux and i686-linux, the attached patch not, but I can
> bootstrap/regtest it if you prefer it.

The attached version unfortunately regresses pr60226.c
typedef int __attribute__ ((aligned (1 << 28))) int28;
int28 foo[4] = {}; /* { dg-error "alignment of array elements is greater than element size" } */
error is not reported then.  But the first version with the layout_type call
in there works.

> @@ -1057,21 +1064,23 @@ cp_build_qualified_type_real (tree type,
>  	 should be equivalent to those in check_qualified_type.  */
>        for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
>  	if (TREE_TYPE (t) == element_type
> -	    && TYPE_NAME (t) == TYPE_NAME (type)
> -	    && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
> -	    && attribute_list_equal (TYPE_ATTRIBUTES (t),
> -				     TYPE_ATTRIBUTES (type)))
> +	    && check_base_type (t, type))

So, would instead of this change adding
  && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (type)
  && (!TYPE_USER_ALIGN (t) || TYPE_ALIGN (t) == TYPE_ALIGN (type))
to the conditional work for you?
Or supposedly no change at all, as the attributes would be either in
TYPE_ATTRIBUTES, or on TYPE_DECL, but then it would be covered by
the TYPE_NAME comparison.

>  	  break;
>  
>        if (!t)
>  	{
>  	  t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
>  
> -	  /* Keep the typedef name.  */
> -	  if (TYPE_NAME (t) != TYPE_NAME (type))
> +	  /* Keep the typedef name, context and alignment.  */
> +	  if (TYPE_NAME (t) != TYPE_NAME (type)
> +	      || TYPE_CONTEXT (t) != TYPE_CONTEXT (type)
> +	      || TYPE_ALIGN (t) != TYPE_ALIGN (type))

Then supposedly similar change to the above one (the TYPE_USER_ALIGN stuff).

	Jakub



More information about the Gcc-patches mailing list