Thank you for the review, with this patch I get some ICEs during the regstest with:
gfortran.dg/coarray/poly_run_3.f90 gfortran.dg/elemental_optional_args_5.f03 gfortran.dg/select_type_26.f03 gfortran.dg/select_type_27.f03 gfortran.dg/class_48.f90 gfortran.dg/class_allocate_10.f03 gfortran.dg/class_allocate_8.f03 gfortran.dg/class_array_1.f03 gfortran.dg/class_array_2.f03 gfortran.dg/assumed_type_2.f90 gfortran.dg/class_array_9.f03 gfortran.dg/coarray_lib_alloc_2.f90 I've debugged only the first 2 and the problem seems to be related with "tmp = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, se.expr, build_int_cst (TREE_TYPE (se.expr), 0)); " in trans-stmt.c at line 5376. The ICE message is the following: $ gcc/bin/gfortran -c elemental_optional_args_5.f03 elemental_optional_args_5.f03: In function ‘MAIN__’: elemental_optional_args_5.f03:220:0: internal compiler error: in build_int_cst_wide, at tree.c:1219 deallocate (taa, tpa, caa, cpa) ^ Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. 2012/6/10 Tobias Burnus <bur...@net-b.de>: > Alessandro Fanfarillo wrote: >> >> with the priceless support of Tobias I've almost realized the patch >> for this PR. In attachment there's the second draft. During the >> regression test I have only one error with select_type_4.f90. The >> problem is in the destroy_list subroutine when it checks >> associated(node) after the first deallocate(node). > > > --- gcc/fortran/trans-stmt.c (revisione 188002) > +++ gcc/fortran/trans-stmt.c (copia locale) > @@ -5341,7 +5341,12 @@ gfc_trans_deallocate (gfc_code *code) > for (al = code->ext.alloc.list; al != NULL; al = al->next) > { > - gfc_expr *expr = gfc_copy_expr (al->expr); > + gfc_expr *expr; > + gfc_expr *ppc; > + gfc_code *ppc_code; > + gfc_actual_arglist *actual; > + expr = gfc_copy_expr (al->expr); > + ppc = gfc_copy_expr (expr); > ... > + if (expr->symtree->n.sym->ts.type == BT_CLASS) > > > I'd prefer: > > gfc_expr *ppc = NULL; > ... > if (expr->ts.type == BT_CLASS) > ppc = gfc_copy_expr (expr); > ... > if (ppc) > ... > > Namely: Only copy the expression if needed. > > Additionally, the check "if (expr->symtree->n.sym->ts.type == BT_CLASS)" is > wrong. For instance, for > type(t) :: x > deallocate(x%class) > it won't trigger, but it should. > > Actually, I think a cleaner version would be: > > if (al->expr->ts.type == BT_CLASS) > { > gfc_expr *ppc; > ppc = gfc_copy_expr (al->expr); > > * * * > > Furthermore, I think you call _free + free for the same component for: > > type t > integer, allocatable :: x > end type t > class(t), allocatable :: y > ... > deallocate (y) > > * * * > > Regarding your code: You assume that "al->expr" points to an allocated > variable, that's not the always the case - hence, select_type_4.f90 fails. > > * * * > > You always create a _free function; I wonder whether it makes sense to use > _vtab->free with NULL in case that no _free is needed. > > * * * > > Attached an updated version, which does that all. No guarantee that it works > correctly, but it should at least fix select_type_4.f90. > > Tobias