http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47601
--- Comment #21 from janus at gcc dot gnu.org 2011-05-28 15:23:22 UTC --- Improved patch, makes the original test case work: Index: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (revision 174380) +++ gcc/fortran/module.c (working copy) @@ -2356,14 +2356,10 @@ mio_component_ref (gfc_component **cp, gfc_symbol if (sym->components != NULL && p->u.pointer == NULL) { /* Symbol already loaded, so search by name. */ - for (q = sym->components; q; q = q->next) - if (strcmp (q->name, name) == 0) - break; + q = gfc_find_component (sym, name, true, true); - if (q == NULL) - gfc_internal_error ("mio_component_ref(): Component not found"); - - associate_integer_pointer (p, q); + if (q) + associate_integer_pointer (p, q); } /* Make sure this symbol will eventually be loaded. */ Index: gcc/fortran/symbol.c =================================================================== --- gcc/fortran/symbol.c (revision 174380) +++ gcc/fortran/symbol.c (working copy) @@ -1996,14 +1996,11 @@ gfc_find_component (gfc_symbol *sym, const char *n { gfc_component *p; - if (name == NULL) + if (name == NULL || sym == NULL) return NULL; - + sym = gfc_use_derived (sym); - if (sym == NULL) - return NULL; - for (p = sym->components; p; p = p->next) if (strcmp (p->name, name) == 0) break;