Created attachment 49494 [details] Fortran source code The attached code crashs with an ICE. It requires that the argument has type class(*) and is optional. classstar_rank.f90:14:0: 14 | s = '0' | internal compiler error: Segmentation fault 0xbe205f crash_signal ../../gcc-repo/gcc/toplev.c:328 0x793007 trans_associate_var ../../gcc-repo/gcc/fortran/trans-stmt.c:1765 0x798fe1 gfc_trans_block_construct(gfc_code*) ../../gcc-repo/gcc/fortran/trans-stmt.c:2283 0x724950 trans_code ../../gcc-repo/gcc/fortran/trans.c:1960 0x79a89f gfc_trans_select_rank_cases ../../gcc-repo/gcc/fortran/trans-stmt.c:3703 0x79a89f gfc_trans_select_rank(gfc_code*) ../../gcc-repo/gcc/fortran/trans-stmt.c:3758 0x724aa3 trans_code ../../gcc-repo/gcc/fortran/trans.c:1984 0x798f70 gfc_trans_block_construct(gfc_code*) ../../gcc-repo/gcc/fortran/trans-stmt.c:2276 0x724950 trans_code ../../gcc-repo/gcc/fortran/trans.c:1960 0x791065 gfc_trans_if_1 ../../gcc-repo/gcc/fortran/trans-stmt.c:1448 0x798a8b gfc_trans_if(gfc_code*) ../../gcc-repo/gcc/fortran/trans-stmt.c:1480 0x724b23 trans_code ../../gcc-repo/gcc/fortran/trans.c:1952 0x74dd44 gfc_generate_function_code(gfc_namespace*) ../../gcc-repo/gcc/fortran/trans-decl.c:6835 0x728571 gfc_generate_module_code(gfc_namespace*) ../../gcc-repo/gcc/fortran/trans.c:2264 0x6ca905 translate_all_program_units ../../gcc-repo/gcc/fortran/parse.c:6293 0x6ca905 gfc_parse_file() ../../gcc-repo/gcc/fortran/parse.c:6545 0x721c4f gfc_be_parse_file ../../gcc-repo/gcc/fortran/f95-lang.c:210
There are two resolved bug reports which are very similar, bug 61881 and bug 91926. At least bug 91926 is working fine. The other is pretty old and lacks the optional attribute.
Started to ICE with r10-3563-g73a28634098cb1ab.
Created attachment 49743 [details] Fix for this PR and PR97723 This regtests and fixes both PRs Paul select_rank_5.f90: ! { dg-do run } ! ! Test the fixes for PR97723 and PR97694. ! ! Contributed by Martin <mscfd@gmx.net> ! module mod implicit none private public cssel contains function cssel(x) result(s) character(len=:), allocatable :: s class(*), dimension(..), optional, intent(in) :: x if (present(x)) then select rank (x) rank (0) s = '0' ! PR97723: ‘assign’ at (1) is not a function ! PR97694: ICE in trans-stmt.c(trans_associate_var) rank (1) s = '1' ! PR97723: ‘assign’ at (1) is not a function rank default s = '?' ! PR97723: ‘assign’ at (1) is not a function end select else s = '-' end if end function cssel end module mod program classstar_rank use mod implicit none integer :: x real, dimension(1:3) :: y logical, dimension(1:2,1:2) :: z if (any ([cssel(x),cssel(y),cssel(z),cssel()] .ne. ['0','1','?','-'])) stop 1 end program classstar_rank
I guess that it's mine :-) Paul
Thanks a lot. The patch seems to work great. Tried it with the more complex code from which the two failed tests were boiled down.
There is still a somewhat related problem if a variable of a derived type with allocatable component is provided to cssel. See bug 98342 with a simplified example code (without class(*)).
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>: https://gcc.gnu.org/g:c4a678981572c12d158709ace0d3f23dd04cf217 commit r11-6346-gc4a678981572c12d158709ace0d3f23dd04cf217 Author: Paul Thomas <pault@gcc.gnu.org> Date: Sun Dec 27 14:59:38 2020 +0000 Fortran: Fix some select rank issues [PR97694 and 97723]. 2020-12-27 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/97694 PR fortran/97723 * check.c (allocatable_check): Select rank temporaries are permitted even though they are treated as associate variables. * resolve.c (gfc_resolve_code): Break on select rank as well as select type so that the block os resolved. * trans-stmt.c (trans_associate_var): Class associate variables that are optional dummies must use the backend_decl. gcc/testsuite/ PR fortran/97694 PR fortran/97723 * gfortran.dg/select_rank_5.f90: New test.
Paul – what's the state of this PR? I see a mainline/GCC 11 commit from end of December. Is there more to do?
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:25d45b5dd41a9ab005a5ae8ee8e54be17f2467a2 commit r10-10109-g25d45b5dd41a9ab005a5ae8ee8e54be17f2467a2 Author: Paul Thomas <pault@gcc.gnu.org> Date: Sun Dec 27 14:59:38 2020 +0000 Fortran: Fix some select rank issues [PR97694 and 97723]. 2020-12-27 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/97694 PR fortran/97723 * check.c (allocatable_check): Select rank temporaries are permitted even though they are treated as associate variables. * resolve.c (gfc_resolve_code): Break on select rank as well as select type so that the block os resolved. * trans-stmt.c (trans_associate_var): Class associate variables that are optional dummies must use the backend_decl. gcc/testsuite/ PR fortran/97694 PR fortran/97723 * gfortran.dg/select_rank_5.f90: New test. (cherry picked from commit c4a678981572c12d158709ace0d3f23dd04cf217)
Backported Paul's fix to 10-branch after verifying that it does the job. The backport to 9-branch would require more work, thus not done. Closing.