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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |pault at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The ICE occurs when invoking gfc_get_derived_type with codimen==1 and

(gdb) p derived->name
$11 = 0x7ffff78f76e0 "__vtype_surfaces_interface_Package"

(gdb) p c->name
$14 = 0x7ffff78e1710 "_extends"

as token == NULL for:
          snprintf (caf_name, GFC_MAX_SYMBOL_LEN, "_caf_%s", c->name);
          token = gfc_find_component (derived, caf_name, true, true, NULL);
          gcc_assert (token);

However, if one puts everything into a single file: while gfc_get_derived_type
gets invoked for __vtype_surfaces_interface_Package more than once, it never
gets invoked (for those) with 'codimen=1'. (It does so only for surfaces and
__class_surfaces_interface_Package_a).


In the ICE case, one has in the same function (gfc_get_derived_type) the code:

      if ((!c->attr.pointer && !c->attr.proc_pointer
          && !same_alloc_type)
          || c->ts.u.derived->backend_decl == NULL)
        {
          int local_codim = c->attr.codimension ? c->as->corank: codimen;
          c->ts.u.derived->backend_decl = gfc_get_derived_type
(c->ts.u.derived,
                                                                local_codim);
        }

where derived->name == __class_surfaces_interface_Package_a and c->name ==
'_vptr' – local_codim is 1 as the argument 'codim' is 1.


 * * *

The following patch – which more looks like a band aid – fixes the compilation:

diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 0a749d6e0a0..062fdf3608e 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -2667,6 +2667,8 @@ gfc_get_derived_type (gfc_symbol * derived, int codimen)
          || c->ts.u.derived->backend_decl == NULL)
        {
          int local_codim = c->attr.codimension ? c->as->corank: codimen;
+         if (derived->attr.is_class && strcmp (c->name, "_vptr") == 0)
+           local_codim = 0;
          c->ts.u.derived->backend_decl = gfc_get_derived_type
(c->ts.u.derived,
                                                                local_codim);
        }

 * * *

The code was added at this location with commit r256065 on 2018-01-01 for PR
83076. I think before it did not ICE, but I don't think it was right, either.

Reply via email to