Re: [Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
Dear Dominique, Committed to trunk as revision 254936. Thanks for picking up the problem and for redoing the testing. Regards Paul
Re: [Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
Looks good to me (as in "pass all my tests"). Thanks, Dominique > Le 18 nov. 2017 à 14:02, Paul Richard Thomas> a écrit : > > Dear Dominique, > > Please find attached a revised patch that I believe fixes the problem > that you found. The changes are the additions in trans-decl.c. > > OK for trunk and 7-branch? > > Paul >
Re: [Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
Dear Dominique, Please find attached a revised patch that I believe fixes the problem that you found. The changes are the additions in trans-decl.c. OK for trunk and 7-branch? Paul 2017-11-18 Paul ThomasPR fortran/78990 * expr.c (gfc_is_class_array_function): Renamed from 'gfc_is_alloc_class_array_function' and modified to return true for pointers as well as allocatable results. * gfortran.h : Change of name for prototype of above function. * trans-array.c (gfc_add_loop_ss_code): Force finalization of class array results. (build_class_array_ref): Change assertion into a condition. (build_class_array_ref): Set the se class_vptr for class array function results. (gfc_walk_function_expr): Reference gfc_is_class_array_function as above. * trans-decl.c (get_proc_result): Move it up before gfc_trans_deferred_vars. (gfc_trans_deferred_vars): Nullify explicit return class arrays on entry. * trans-expr.c (gfc_conv_class_to_class): Allow conversion of class array functions that have an se class_vptr and use it for the result vptr. (gfc_conv_subref_array_arg): Rename reference to the above function. (gfc_conv_procedure_call): Ditto. Add the se pre block to the loop pre block before the function is evaluated. Do not finalize class pointer results. (arrayfunc_assign_needs_temporary, gfc_trans_assignment_1) More renamed references. * trans-intrinsic.c (gfc_conv_intrinsic_size): Ditto. 2017-11-18 Paul Thomas PR fortran/78990 * gfortran.dg/class_67.f90: New test. On 15 November 2017 at 11:40, Dominique d'Humières wrote: > Hi Paul, > > Your patch fixes the ICE and pass the tests. However I see > > At line 22 of file pr78990.f90 > Fortran runtime error: Attempting to allocate already allocated variable > ‘return_t1' > > for the original tests (with mold or source). This runtime error depends on > the options: > > % gfc pr78990.f90 > % a.out > At line 22 of file pr78990.f90 > Fortran runtime error: Attempting to allocate already allocated variable > 'return_t1' > > Error termination. Backtrace: > … > % gfc pr78990.f90 -fno-backtrace > % a.out >0 0 0 > % gfc pr78990.f90 -m32 > % a.out >0 0 0 > % gfc pr78990.f90 -O > % a.out >0 0 0 > > The problem seems related to the line > > print*,v2%i > > Cheers, > > Dominique > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein Index: gcc/fortran/expr.c === *** gcc/fortran/expr.c (revision 254626) --- gcc/fortran/expr.c (working copy) *** gfc_is_alloc_class_scalar_function (gfc_ *** 4822,4835 /* Determine if an expression is a function with an allocatable class array result. */ bool ! gfc_is_alloc_class_array_function (gfc_expr *expr) { if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym && expr->value.function.esym->result && expr->value.function.esym->result->ts.type == BT_CLASS && CLASS_DATA (expr->value.function.esym->result)->attr.dimension ! && CLASS_DATA (expr->value.function.esym->result)->attr.allocatable) return true; return false; --- 4822,4836 /* Determine if an expression is a function with an allocatable class array result. */ bool ! gfc_is_class_array_function (gfc_expr *expr) { if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym && expr->value.function.esym->result && expr->value.function.esym->result->ts.type == BT_CLASS && CLASS_DATA (expr->value.function.esym->result)->attr.dimension ! && (CLASS_DATA (expr->value.function.esym->result)->attr.allocatable ! || CLASS_DATA (expr->value.function.esym->result)->attr.pointer)) return true; return false; Index: gcc/fortran/gfortran.h === *** gcc/fortran/gfortran.h (revision 254626) --- gcc/fortran/gfortran.h (working copy) *** gfc_param_spec_type gfc_spec_list_type ( *** 3194,3200 gfc_component * gfc_get_proc_ptr_comp (gfc_expr *); bool gfc_is_proc_ptr_comp (gfc_expr *); bool gfc_is_alloc_class_scalar_function (gfc_expr *); ! bool gfc_is_alloc_class_array_function (gfc_expr *); bool gfc_ref_this_image (gfc_ref *ref); bool gfc_is_coindexed (gfc_expr *); --- 3194,3200 gfc_component * gfc_get_proc_ptr_comp (gfc_expr *); bool gfc_is_proc_ptr_comp (gfc_expr *); bool gfc_is_alloc_class_scalar_function (gfc_expr *); ! bool gfc_is_class_array_function (gfc_expr *); bool gfc_ref_this_image (gfc_ref *ref); bool gfc_is_coindexed (gfc_expr *); Index: gcc/fortran/resolve.c
Re: [Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
Hi Dominique, Quite suddenly, I am seeing fault too. I don't know what has changed. I'm on to it. Thanks Paul On 15 November 2017 at 11:40, Dominique d'Humièreswrote: > Hi Paul, > > Your patch fixes the ICE and pass the tests. However I see > > At line 22 of file pr78990.f90 > Fortran runtime error: Attempting to allocate already allocated variable > ‘return_t1' > > for the original tests (with mold or source). This runtime error depends on > the options: > > % gfc pr78990.f90 > % a.out > At line 22 of file pr78990.f90 > Fortran runtime error: Attempting to allocate already allocated variable > 'return_t1' > > Error termination. Backtrace: > … > % gfc pr78990.f90 -fno-backtrace > % a.out >0 0 0 > % gfc pr78990.f90 -m32 > % a.out >0 0 0 > % gfc pr78990.f90 -O > % a.out >0 0 0 > > The problem seems related to the line > > print*,v2%i > > Cheers, > > Dominique > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein
Re: [Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
Hi Paul, Your patch fixes the ICE and pass the tests. However I see At line 22 of file pr78990.f90 Fortran runtime error: Attempting to allocate already allocated variable ‘return_t1' for the original tests (with mold or source). This runtime error depends on the options: % gfc pr78990.f90 % a.out At line 22 of file pr78990.f90 Fortran runtime error: Attempting to allocate already allocated variable 'return_t1' Error termination. Backtrace: … % gfc pr78990.f90 -fno-backtrace % a.out 0 0 0 % gfc pr78990.f90 -m32 % a.out 0 0 0 % gfc pr78990.f90 -O % a.out 0 0 0 The problem seems related to the line print*,v2%i Cheers, Dominique
[Patch, fortran] PR78990 [5/6/7 Regression] ICE when assigning polymorphic array function result
This turned out to be quite a challenging debugging job as often seems to be the case where the scalarizer is involved. Ultimately, I found that the testcase compiled when return_t1 was made a pointer and the resulting code revealed where the problems lay. This modified testcase now works as well but, of course, it leaks memory. The submitted testcase tests both allocatable and pointer versions of the function but in a manner that does not leak memory. The scalarization of the assignment in the main program failed for two reasons: (i) The conversion of 'v1' into a class actual was being done after the call to 'return_t1', giving rise to the ICE reported in comment #1of the PR. This was fixed by adding the se pre to the loop pre block before the function evaluation in trans-expr.c(gfc_conv_procedure_call); and (ii) The 'info' descriptor, required for scalarization was not set, which gave rise to the ICE noted by the reporter. This was fixed by forcing the evaluation of the function and the setting of the info fields by setting the expression must_finalize flag in trans-array.c(gfc_add_loop_ss_code). The name change of expr.c(gfc_is_alloc_class_array_function) to gfc_is_class_array_function was done to allow pointer results through the hoop. The test for the allocatable or pointer attributes is in principle redundant but I have retained it just in case... Bootstrapped and regtested on FC23/x86_64 - OK for trunk and, ultimately after a waiting period, 6- and 7-branches? It should be noted that part (i) of the problem is not a regression since the symptoms of it being present previously are reported in comment #1 of the PR. Thus, I would not mind if it were decided that this patch is too intrusive to backport. That said, the patch is rather safe since it is well cloaked by conditions that handle class array function results. Cheers Paul 2017-11-13 Paul ThomasPR fortran/78990 * expr.c (gfc_is_class_array_function): Renamed from 'gfc_is_alloc_class_array_function' and modified to return true for pointers as well as allocatable results. * gfortran.h : Change of name for prototype of above function. * trans-array.c (gfc_add_loop_ss_code): Force finalization of class array results. (build_class_array_ref): Change assertion into a condition. (build_class_array_ref): Set the se class_vptr for class array function results. (gfc_walk_function_expr): Reference gfc_is_class_array_function as above. * trans-expr.c (gfc_conv_class_to_class): Allow conversion of class array functions that have an se class_vptr and use it for the result vptr. (gfc_conv_subref_array_arg): Rename reference to the above function. (gfc_conv_procedure_call): Ditto. Add the se pre block to the loop pre block before the function is evaluated. Do not finalize class pointer results. (arrayfunc_assign_needs_temporary, gfc_trans_assignment_1) More renamed references. * trans-intrinsic.c (gfc_conv_intrinsic_size): Ditto. 2017-11-13 Paul Thomas PR fortran/78990 * gfortran.dg/class_67.f90: New test. Index: gcc/fortran/expr.c === *** gcc/fortran/expr.c (revision 254626) --- gcc/fortran/expr.c (working copy) *** gfc_is_alloc_class_scalar_function (gfc_ *** 4822,4835 /* Determine if an expression is a function with an allocatable class array result. */ bool ! gfc_is_alloc_class_array_function (gfc_expr *expr) { if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym && expr->value.function.esym->result && expr->value.function.esym->result->ts.type == BT_CLASS && CLASS_DATA (expr->value.function.esym->result)->attr.dimension ! && CLASS_DATA (expr->value.function.esym->result)->attr.allocatable) return true; return false; --- 4822,4836 /* Determine if an expression is a function with an allocatable class array result. */ bool ! gfc_is_class_array_function (gfc_expr *expr) { if (expr->expr_type == EXPR_FUNCTION && expr->value.function.esym && expr->value.function.esym->result && expr->value.function.esym->result->ts.type == BT_CLASS && CLASS_DATA (expr->value.function.esym->result)->attr.dimension ! && (CLASS_DATA (expr->value.function.esym->result)->attr.allocatable ! || CLASS_DATA (expr->value.function.esym->result)->attr.pointer)) return true; return false; Index: gcc/fortran/gfortran.h === *** gcc/fortran/gfortran.h (revision 254626) --- gcc/fortran/gfortran.h (working copy) *** gfc_param_spec_type gfc_spec_list_type ( *** 3194,3200 gfc_component * gfc_get_proc_ptr_comp (gfc_expr *); bool gfc_is_proc_ptr_comp (gfc_expr *); bool gfc_is_alloc_class_scalar_function