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

Mikael Morin <mikael at gcc dot gnu.org> changed:

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

--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> ---
> diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
> index adf392cec6f..c10484ff636 100644
> --- a/gcc/fortran/trans.cc
> +++ b/gcc/fortran/trans.cc
> @@ -524,8 +524,13 @@ gfc_build_array_ref (tree base, tree offset, tree decl,
>        span = gfc_vptr_size_get (vptr);
>  
>        /* Check if this is an unlimited polymorphic object carrying a 
> character
> -      payload. In this case, the 'len' field is non-zero.  */
> -      if (decl && GFC_CLASS_TYPE_P (TREE_TYPE (decl)))
> +      payload. In this case, the 'len' field is non-zero.  The class
> +      container type does not always carry GFC_CLASS_TYPE_P, but its
> +      canonical type does.  */
> +      if (decl
> +       && (GFC_CLASS_TYPE_P (TREE_TYPE (decl))
> +           || (TYPE_CANONICAL (TREE_TYPE (decl))
> +               && GFC_CLASS_TYPE_P (TYPE_CANONICAL (TREE_TYPE (decl))))))
>       span = gfc_resize_class_size_with_len (NULL, decl, span);
>      }
>    else if (decl)

We should try to have the GFC_CLASS_TYPE_P set on the type directly, otherwise
we'll have to duplicate this condition everywhere the flag is used.

gfc_typenode_for_spec has:

    case BT_DERIVED:
    case BT_CLASS:
      basetype = gfc_get_derived_type (spec->u.derived, codim);

      if (spec->type == BT_CLASS)
        GFC_CLASS_TYPE_P (basetype) = 1;

The generation of class descriptors as additional symbols has its downsides,
but here it could help us as it makes polymorphic derived types (i.e.
class(...)) use a separate symbol different from regular derived types.  So
gfc_get_derived_type in the snippet above could return a type with the
GFC_CLASS_TYPE_P flag already set. I think it would be set basically when the
derived type symbol has the is_class attribute.

Reply via email to