Started between 20221218 and 20230108 : $ cat z1.f90 program p real, parameter :: n = 2 real :: a(1,(n),2) call s(a(:,:,1)) end subroutine s(x) real :: x(2) end $ gfortran-13-20230122 -c z1.f90 z1.f90:3:15: 3 | real :: a(1,(n),2) | 1 Error: Expression at (1) must be of INTEGER type, found REAL z1.f90:3:21: 3 | real :: a(1,(n),2) | 1 Error: The module or main program array 'a' at (1) must have constant shape f951: internal compiler error: Segmentation fault 0xf8a79f crash_signal ../../gcc/toplev.cc:314 0x848fd9 get_expr_storage_size ../../gcc/fortran/interface.cc:2941 0x848fd9 gfc_compare_actual_formal(gfc_actual_arglist**, gfc_formal_arglist*, int, int, bool, locus*) ../../gcc/fortran/interface.cc:3327 0x9b3136 check_externals_procedure ../../gcc/fortran/frontend-passes.cc:5742 0x9b7e29 gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) ../../gcc/fortran/frontend-passes.cc:5352 0x9b968b gfc_check_externals0 ../../gcc/fortran/frontend-passes.cc:5861 0x9ba614 gfc_check_externals(gfc_namespace*) ../../gcc/fortran/frontend-passes.cc:5883 0x89f2c0 gfc_parse_file() ../../gcc/fortran/parse.cc:6942 0x8edd9f gfc_be_parse_file ../../gcc/fortran/f95-lang.cc:229
First, I think the code is actually valid, adjusting keywords. Furthermore, there are two issues here, an underlying one, namely that we reject the following: program p real, parameter :: n = 2 real :: a(1,(n),2) end pr108501.f90:3:14: 3 | real :: a(1,(n),2) | 1 Error: Expression at (1) must be of INTEGER type, found REAL pr108501.f90:3:20: 3 | real :: a(1,(n),2) | 1 Error: The module or main program array 'a' at (1) must have constant shape This is already present in gcc-7, so although it is a nasty bug, it's not a regression. The other issue is likely exposed by this misbehavior, leading to an ICE when checking the argument of the call in get_expr_storage_size. This issue is also present in all versions down to at least gcc-7, so arguably not really a regression. I have a patch for the latter.
Created attachment 54330 [details] Patch for the ICE in get_expr_storage_size
(In reply to anlauf from comment #1) > First, I think the code is actually valid, adjusting keywords. Oops, I cannot read, and Intel accepted the code when forgetting to enfore standard conformance checking. Putting a brown bag over my head. Fixing keywords again...
Submitted: https://gcc.gnu.org/pipermail/fortran/2023-January/058818.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:771d793df1622a476e1cf8d05f0a6aee350fa56b commit r13-5312-g771d793df1622a476e1cf8d05f0a6aee350fa56b Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Jan 23 21:19:03 2023 +0100 Fortran: avoid ICE on invalid array subscript triplets [PR108501] gcc/fortran/ChangeLog: PR fortran/108501 * interface.cc (get_expr_storage_size): Check array subscript triplets that we actually have integer values before trying to extract with mpz_get_si. gcc/testsuite/ChangeLog: PR fortran/108501 * gfortran.dg/pr108501.f90: New test.
Fixed I assume.
The releases/gcc-12 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:daa4c49a4773f274b7a784cedd7b0e0b3c59523b commit r12-9076-gdaa4c49a4773f274b7a784cedd7b0e0b3c59523b Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Jan 23 21:19:03 2023 +0100 Fortran: avoid ICE on invalid array subscript triplets [PR108501] gcc/fortran/ChangeLog: PR fortran/108501 * interface.cc (get_expr_storage_size): Check array subscript triplets that we actually have integer values before trying to extract with mpz_get_si. gcc/testsuite/ChangeLog: PR fortran/108501 * gfortran.dg/pr108501.f90: New test. (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:76a6f8470c8c786b271cb0d897de891fe0d4043f commit r11-10504-g76a6f8470c8c786b271cb0d897de891fe0d4043f Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Jan 23 21:19:03 2023 +0100 Fortran: avoid ICE on invalid array subscript triplets [PR108501] gcc/fortran/ChangeLog: PR fortran/108501 * interface.c (get_expr_storage_size): Check array subscript triplets that we actually have integer values before trying to extract with mpz_get_si. gcc/testsuite/ChangeLog: PR fortran/108501 * gfortran.dg/pr108501.f90: New test. (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:d4bb7751af090736fb4a3bd7278d7094f35e02e4 commit r10-11196-gd4bb7751af090736fb4a3bd7278d7094f35e02e4 Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Jan 23 21:19:03 2023 +0100 Fortran: avoid ICE on invalid array subscript triplets [PR108501] gcc/fortran/ChangeLog: PR fortran/108501 * interface.c (get_expr_storage_size): Check array subscript triplets that we actually have integer values before trying to extract with mpz_get_si. gcc/testsuite/ChangeLog: PR fortran/108501 * gfortran.dg/pr108501.f90: New test. (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)