With option -Wsurprising or -Wall, down to at least 4.8 : $ cat z1.f90 subroutine a c = transfer(a, b) end $ cat z2.f90 subroutine a c = transfer(a, a) end $ cat z3.f90 subroutine a c = transfer(b, a) end $ cat z4.f90 recursive subroutine a c = transfer(a, b) end $ gfortran-9-20180513 -c z4.f90 $ $ gfortran-9-20180513 -c z1.f90 z1.f90:2:16: c = transfer(a, b) 1 Warning: Non-RECURSIVE procedure 'a' at (1) is possibly calling itself recursively. Declare it RECURSIVE or use '-frecursive' $ gfortran-9-20180513 -c z4.f90 -Wsurprising f951: internal compiler error: Invalid expression in gfc_element_size. 0x6a7d3f gfc_internal_error(char const*, ...) ../../gcc/fortran/error.c:1358 0x73cdbb gfc_element_size(gfc_expr*) ../../gcc/fortran/target-memory.c:126 0x73ce01 gfc_target_expr_size(gfc_expr*) ../../gcc/fortran/target-memory.c:152 0x684a23 gfc_calculate_transfer_sizes(gfc_expr*, gfc_expr*, gfc_expr*, unsigned long*, unsigned long*, unsigned long*) ../../gcc/fortran/check.c:5408 0x684b88 gfc_check_transfer(gfc_expr*, gfc_expr*, gfc_expr*) ../../gcc/fortran/check.c:5472 0x6baf24 check_specific ../../gcc/fortran/intrinsic.c:4545 0x6c4ee4 gfc_intrinsic_func_interface(gfc_expr*, int) ../../gcc/fortran/intrinsic.c:4781 0x70ee65 resolve_unknown_f ../../gcc/fortran/resolve.c:2870 0x70ee65 resolve_function ../../gcc/fortran/resolve.c:3179 0x70ef8a gfc_resolve_expr(gfc_expr*) ../../gcc/fortran/resolve.c:6719 0x715810 gfc_resolve_code(gfc_code*, gfc_namespace*) ../../gcc/fortran/resolve.c:11100 0x7182aa resolve_codes ../../gcc/fortran/resolve.c:16537 0x7183ae gfc_resolve(gfc_namespace*) ../../gcc/fortran/resolve.c:16572 0x701b6a resolve_all_program_units ../../gcc/fortran/parse.c:6060 0x701b6a gfc_parse_file() ../../gcc/fortran/parse.c:6310 0x748adf gfc_be_parse_file ../../gcc/fortran/f95-lang.c:204
Confirmed.
The following patch generates errors for the testcases when one of the TRANSFER arguments is a procedure (but not a pointer): Index: gcc/fortran/check.c =================================================================== --- gcc/fortran/check.c (revision 269717) +++ gcc/fortran/check.c (working copy) @@ -5551,6 +5551,24 @@ return false; } + if (source->ts.type == BT_PROCEDURE + && !source->symtree->n.sym->attr.pointer) + { + gfc_error ("%<SOURCE%> argument of %<TRANSFER%> intrinsic at %L " + "must not be a %s", &source->where, + gfc_basic_typename (source->ts.type)); + return false; + } + + if (mold->ts.type == BT_PROCEDURE + && !mold->symtree->n.sym->attr.pointer) + { + gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L " + "must not be a %s", &mold->where, + gfc_basic_typename (mold->ts.type)); + return false; + } + if (size != NULL) { if (!type_check (size, 2, BT_INTEGER)) Needs regtesting.
Patch submitted: https://gcc.gnu.org/ml/fortran/2019-03/msg00099.html
Revised patch that also addresses PR83515: https://gcc.gnu.org/ml/fortran/2019-03/msg00109.html
> Revised patch that also addresses PR83515: The patch fixes the ICE. Compiling the tests z2.f90 or z3.f90 gives the error 2 | c = transfer(a, a) | 1 Error: Cannot convert PROCEDURE to REAL(4) at (1) or 2 | c = transfer(b, a) | 1 Error: Cannot convert PROCEDURE to REAL(4) at (1)
Author: anlauf Date: Sun Mar 31 18:33:51 2019 New Revision: 270045 URL: https://gcc.gnu.org/viewcvs?rev=270045&root=gcc&view=rev Log: 2019-03-31 Harald Anlauf <anlauf@gmx.de> PR fortran/83515 PR fortran/85797 * trans-types.c (gfc_typenode_for_spec): Handle conversion for procedure pointers. * target-memory.c (gfc_element_size): Handle size determination for procedure pointers. PR fortran/83515 PR fortran/85797 * gfortran.dg/pr85797.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/pr85797.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/target-memory.c trunk/gcc/fortran/trans-types.c trunk/gcc/testsuite/ChangeLog
Author: anlauf Date: Sun Mar 31 19:08:23 2019 New Revision: 270046 URL: https://gcc.gnu.org/viewcvs?rev=270046&root=gcc&view=rev Log: 2019-03-31 Harald Anlauf <anlauf@gmx.de> PR fortran/83515 PR fortran/85797 * trans-types.c (gfc_typenode_for_spec): Handle conversion for procedure pointers. * target-memory.c (gfc_element_size): Handle size determination for procedure pointers. PR fortran/83515 PR fortran/85797 * gfortran.dg/pr85797.f90: New test. Added: branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr85797.f90 Modified: branches/gcc-8-branch/gcc/fortran/ChangeLog branches/gcc-8-branch/gcc/fortran/target-memory.c branches/gcc-8-branch/gcc/fortran/trans-types.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
Author: anlauf Date: Sun Mar 31 19:21:37 2019 New Revision: 270047 URL: https://gcc.gnu.org/viewcvs?rev=270047&root=gcc&view=rev Log: 2019-03-31 Harald Anlauf <anlauf@gmx.de> Backport from trunk PR fortran/83515 PR fortran/85797 * trans-types.c (gfc_typenode_for_spec): Handle conversion for procedure pointers. * target-memory.c (gfc_element_size): Handle size determination for procedure pointers. PR fortran/83515 PR fortran/85797 * gfortran.dg/pr85797.f90: New test. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr85797.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/target-memory.c branches/gcc-7-branch/gcc/fortran/trans-types.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fixed on trunk and open branches (7/8). Thanks for the report!