Hi Mikael! Am 04.03.23 um 14:56 schrieb Mikael Morin: > I have found the time finally.  It's not as bad as it seemed.  See below. > >> diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc >> index eec0314cf4c..72d8c6f1c14 100644 >> --- a/gcc/fortran/decl.cc >> +++ b/gcc/fortran/decl.cc >> +      sym->attr.pointer = CLASS_DATA(sym)->attr.class_pointer; >> +      sym->attr.allocatable = CLASS_DATA(sym)->attr.allocatable; >> +      sym->attr.dimension = CLASS_DATA(sym)->attr.dimension; >> +      sym->attr.codimension = CLASS_DATA(sym)->attr.codimension; >> +      if (as && CLASS_DATA (sym)->as) >> +    sym->as = gfc_copy_array_spec (CLASS_DATA (sym)->as); > > Here the condition on 'CLASS_DATA(sym)->as' makes obviously sense, but I > don't see why there is also a condition on 'as'. > > For example, if the array spec has been previously set on the class > container's first component, and there is no array spec information in > the current statement (i.e. as == NULL), sym->as will remain NULL, and a > non-array class container will be built in gfc_build_class_symbol below. Very good catch! Indeed, this fixes the testcase variations. >> @@ -8807,6 +8785,27 @@ attr_decl1 (void) >>        goto cleanup; >>      } >> >> +  if (sym->ts.type == BT_CLASS && sym->ts.u.derived->attr.is_class >> +      && !as && !current_attr.pointer && !current_attr.allocatable >> +      && !current_attr.external) >> +    { >> +      sym->attr.pointer = 0; >> +      sym->attr.allocatable = 0; >> +      sym->attr.dimension = 0; >> +      sym->attr.codimension = 0; > >> +      gfc_free_array_spec (sym->as); > sym->as should probably be reset to NULL here. Done. > Maybe both calls to gfc_free_array_spec here and to gfc_copy_array_spec > above can be avoided by doing a simple pointer copy? I tried that, but this produced a crash with a double-free. The attached revised version uses the above proven changes, and extends the new testcase class_74.f90 by variations of the failures remaining with version 1 so that different codepaths are tested. Regtested again on x86_64-pc-linux-gnu. Any further comments? Thanks for your very helpful review! Harald