When compiling following program: program t_unlimited_2 implicit none class(*), dimension(:), pointer :: u u => sub() contains function sub() result(r) class(*), dimension(:), pointer :: r integer, dimension(3), target :: x = [1,2,3] r => x end function end program I get the output: ---------------------------------------------------------- $gfortran -Wall -Wextra t_unlimited_2.f90 t_unlimited_2.f90:4.4: u => sub() 1 Error: Different ranks in pointer assignment at (1) --------------------------------------------------------- u and sub are both of rank 1. When compiling the following (u is scalar here): program t_unlimited_3 implicit none class(*), pointer :: u u => sub() contains function sub() result(r) class(*), dimension(:), pointer :: r integer, dimension(3), target :: x = [1,2,3] r => x end function end program I get an ICE: ------------------------------------------------------------ $gfortran -Wall -Wextra t_unlimited_3.f90 t_unlimited_3.f90: In function ‘t_unlimited_3’: t_unlimited_3.f90:4:0: internal compiler error: in fold_convert_loc, at fold-const.c:1862 u => sub() ^ t_unlimited_3.f90:4:0: internal compiler error: Abort trap gfortran: internal compiler error: Abort trap (program f951) Abort trap ------------------------------------------------------------- Version: $gfortran -v Using built-in specs. COLLECT_GCC=/xsw/gf48/bin/gfortran COLLECT_LTO_WRAPPER=/xsw/gcc-4.8-20130321/install/libexec/gcc/x86_64-apple-darwin10.8.0/4.8.0/lto-wrapper Target: x86_64-apple-darwin10.8.0 Configured with: ../src/configure --prefix=/xsw/gcc-4.8-20130321/install --enable-languages=c,fortran --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-libiconv-prefix=/opt/local Thread model: posix gcc version 4.8.0 20130321 (prerelease) (GCC) Running on Mac OS X 10.6.8
Confirmed with current trunk.
Regarding the rank error (and "expr->rank = "), it seems as if one has to review the following functions in result.c: resolve_generic_f0, expression_rank, check_host_association, resolve_unknown_f, resolve_specific_f0, resolve_compcall,resolve_expr_ppc, resolve_assoc_var, add_comp_ref, resolve_structure_cons.
With this patch ... Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 196862) +++ gcc/fortran/resolve.c (working copy) @@ -2538,7 +2538,9 @@ found: expr->ts = sym->ts; expr->value.function.name = sym->name; expr->value.function.esym = sym; - if (sym->as != NULL) + if (sym->result->ts.type == BT_CLASS && CLASS_DATA (sym->result)->as) + expr->rank = CLASS_DATA (sym->result)->as->rank; + else if (sym->as != NULL) expr->rank = sym->as->rank; return MATCH_YES; ... the behavior of the two test cases is swapped: The second one is (correctly) rejected, while the first one ends up with the ICE.
Btw, this bug does not require unlimited polymorphism, but also shows up with normal ('limited'?) CLASS definitions: program t_limited implicit none type :: t integer :: i = 0 end type class(t), dimension(:), pointer :: u u => sub() contains function sub() result(r) class(t), dimension(:), pointer :: r type(t), dimension(3), target :: x = t(1) r => x end function end program
Note: The patch in comment 3 regtests cleanly.
On my environment, all tests compile now without an ICE. (also tested with several other compile options) $ gfortran-6 --version GNU Fortran (SUSE Linux) 6.1.1 20160502 [gcc-6-branch revision 235698] $ gfortran-6 -Wall -Wextra pr56765_comment0_t2.f90 $ a.out $ gfortran-6 -Wall -Wextra pr56765_comment0_t3.f90 pr56765_comment0_t3.f90:4:4: u => sub() 1 Error: Different ranks in pointer assignment at (1) $ gfortran-6 -Wall -Wextra pr56765_comment4.f90 $ a.out
> On my environment, all tests compile now without an ICE. Confirmed.