Bug 99839 - [9/10/11/12 Regression] ICE in inline_matmul_assign, at fortran/frontend-passes.c:4234
Summary: [9/10/11/12 Regression] ICE in inline_matmul_assign, at fortran/frontend-pass...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 9.5
Assignee: anlauf
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2021-03-30 19:12 UTC by G. Steinmetz
Modified: 2021-06-04 18:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-03-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2021-03-30 19:12:50 UTC
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
Comment 1 anlauf 2021-03-30 20:07:46 UTC
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.
Comment 2 Martin Liška 2021-03-31 12:53:42 UTC
Btw. started with r6-523-gf1abbf6901a64919.
Comment 3 Jakub Jelinek 2021-05-14 09:54:37 UTC
GCC 8 branch is being closed.
Comment 5 Richard Biener 2021-06-01 08:20:04 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 6 GCC Commits 2021-06-04 17:24:16 UTC
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.
Comment 7 GCC Commits 2021-06-04 17:42:16 UTC
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)
Comment 8 GCC Commits 2021-06-04 17:54:44 UTC
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)
Comment 9 GCC Commits 2021-06-04 18:19:27 UTC
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)
Comment 10 anlauf 2021-06-04 18:22:05 UTC
Fixed on mainline for gcc-12, and committed on 11-, 10- and 9-branch.  Closing.

Thanks for the report!