Affects versions down to r7, at -O1+ : $ cat z1.f90 program p real :: x(3, 3) = 1.0 class(*), allocatable :: z(:, :) z = matmul(x, x) end $ gfortran-11-20210328 -c z1.f90 -O0 $ $ gfortran-11-20210328 -c z1.f90 -O2 f951: internal compiler error: in inline_matmul_assign, at fortran/frontend-passes.c:4234 0x7bf248 inline_matmul_assign ../../gcc/fortran/frontend-passes.c:4234 0x7bfd69 gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) ../../gcc/fortran/frontend-passes.c:5320 0x7c1172 optimize_namespace ../../gcc/fortran/frontend-passes.c:1500 0x7c154f gfc_run_passes(gfc_namespace*) ../../gcc/fortran/frontend-passes.c:169 0x6fd1a7 gfc_resolve(gfc_namespace*) ../../gcc/fortran/resolve.c:17436 0x6e56e4 resolve_all_program_units ../../gcc/fortran/parse.c:6290 0x6e56e4 gfc_parse_file() ../../gcc/fortran/parse.c:6542 0x7320ef gfc_be_parse_file ../../gcc/fortran/f95-lang.c:212
This one is funny. Simply punting on non-numeric and non-logical results works around the ICE. diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 7d3eae67632..213530e46e1 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -4193,6 +4193,19 @@ inline_matmul_assign (gfc_code **c, int *walk_subtrees, if (m_case == none) return 0; + /* We only handle assignment to numeric or logical variables. */ + switch(expr1->ts.type) + { + case BT_INTEGER: + case BT_LOGICAL: + case BT_REAL: + case BT_COMPLEX: + break; + + default: + return 0; + } + ns = insert_block (); /* Assign the type of the zero expression for initializing the resulting Adding Thomas, who knows the code better.
Btw. started with r6-523-gf1abbf6901a64919.
GCC 8 branch is being closed.
Patch: https://gcc.gnu.org/pipermail/fortran/2021-May/056095.html
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:bee8619ad0ac3bd27b7c8dc5819b83a5e8e147a0 commit r12-1222-gbee8619ad0ac3bd27b7c8dc5819b83a5e8e147a0 Author: Harald Anlauf <anlauf@gmx.de> Date: Fri Jun 4 19:23:48 2021 +0200 Fortran - ICE in inline_matmul_assign Restrict inlining of matmul to those cases where assignment to the result array does not need special treatment. gcc/fortran/ChangeLog: PR fortran/99839 * frontend-passes.c (inline_matmul_assign): Do not inline matmul if the assignment to the resulting array if it is not of canonical type (real/integer/complex/logical). gcc/testsuite/ChangeLog: PR fortran/99839 * gfortran.dg/inline_matmul_25.f90: New test.
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:2fdca7cfda7d49f3b252e79acc5933d764e7b77d commit r11-8511-g2fdca7cfda7d49f3b252e79acc5933d764e7b77d Author: Harald Anlauf <anlauf@gmx.de> Date: Fri Jun 4 19:23:48 2021 +0200 Fortran - ICE in inline_matmul_assign Restrict inlining of matmul to those cases where assignment to the result array does not need special treatment. gcc/fortran/ChangeLog: PR fortran/99839 * frontend-passes.c (inline_matmul_assign): Do not inline matmul if the assignment to the resulting array if it is not of canonical type (real/integer/complex/logical). gcc/testsuite/ChangeLog: PR fortran/99839 * gfortran.dg/inline_matmul_25.f90: New test. (cherry picked from commit bee8619ad0ac3bd27b7c8dc5819b83a5e8e147a0)
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:df45c5b83447a06e6b15c729807a17409c39ddff commit r10-9890-gdf45c5b83447a06e6b15c729807a17409c39ddff Author: Harald Anlauf <anlauf@gmx.de> Date: Fri Jun 4 19:23:48 2021 +0200 Fortran - ICE in inline_matmul_assign Restrict inlining of matmul to those cases where assignment to the result array does not need special treatment. gcc/fortran/ChangeLog: PR fortran/99839 * frontend-passes.c (inline_matmul_assign): Do not inline matmul if the assignment to the resulting array if it is not of canonical type (real/integer/complex/logical). gcc/testsuite/ChangeLog: PR fortran/99839 * gfortran.dg/inline_matmul_25.f90: New test. (cherry picked from commit bee8619ad0ac3bd27b7c8dc5819b83a5e8e147a0)
The releases/gcc-9 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:e912880888f9529eb44e3456c4753fc556c63812 commit r9-9568-ge912880888f9529eb44e3456c4753fc556c63812 Author: Harald Anlauf <anlauf@gmx.de> Date: Fri Jun 4 19:23:48 2021 +0200 Fortran - ICE in inline_matmul_assign Restrict inlining of matmul to those cases where assignment to the result array does not need special treatment. gcc/fortran/ChangeLog: PR fortran/99839 * frontend-passes.c (inline_matmul_assign): Do not inline matmul if the assignment to the resulting array if it is not of canonical type (real/integer/complex/logical). gcc/testsuite/ChangeLog: PR fortran/99839 * gfortran.dg/inline_matmul_25.f90: New test. (cherry picked from commit bee8619ad0ac3bd27b7c8dc5819b83a5e8e147a0)
Fixed on mainline for gcc-12, and committed on 11-, 10- and 9-branch. Closing. Thanks for the report!