[Patch, Fortran] PR 43199 - Handle class%component references when reading .mod files
Janus Weil
jaydub66@googlemail.com
Sun Feb 28 18:20:00 GMT 2010
Hi Tobias,
> this patch prevents an ICE when handling class%component in
> find_array_spec. The problem is that with CLASS(type) one has
> effectively another layer around type, i.e. kind of
>
> TYPE class.type
> type(type) :: data
>
> and one needs to accommodate for this extra layer. I think the attached
> patch correctly handles this.
Yes, in principle I think your patch is ok. For reasons of clarity I
would perhaps prefer the following version:
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 157120)
+++ gcc/fortran/resolve.c (working copy)
@@ -4005,7 +4005,11 @@ find_array_spec (gfc_expr *e)
case REF_COMPONENT:
if (derived == NULL)
- derived = e->symtree->n.sym->ts.u.derived;
+ {
+ derived = e->symtree->n.sym->ts.u.derived;
+ if (derived->attr.is_class)
+ derived = derived->components->ts.u.derived;
+ }
c = derived->components;
Moreover, a few lines further in find_array_spec, there is another
occasion where 'derived' is being set. Probably one also needs to
modify that one for CLASS components, maybe like this:
@@ -4015,6 +4019,8 @@ find_array_spec (gfc_expr *e)
/* Track the sequence of component references. */
if (c->ts.type == BT_DERIVED)
derived = c->ts.u.derived;
+ else if (c->ts.type == BT_CLASS)
+ derived = c->ts.u.derived->components->ts.u.derived;
break;
}
I haven't tried creating a test case which fails without this addition
(but maybe it would be good to include one in the patch).
> PS: I marked the test as "dg-do compile" but one can also use "run";
> what do you prefer?
dg-do compile is fine with me.
Cheers,
Janus
More information about the Gcc-patches
mailing list