]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran - ICE in inline_matmul_assign
authorHarald Anlauf <anlauf@gmx.de>
Fri, 4 Jun 2021 17:23:48 +0000 (19:23 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 4 Jun 2021 17:32:42 +0000 (19:32 +0200)
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)

gcc/fortran/frontend-passes.c
gcc/testsuite/gfortran.dg/inline_matmul_25.f90 [new file with mode: 0644]

index 7d3eae676321e21ee9c4dce63df13f792aa08257..213530e46e1810e2a23facc204b71b89281ce831 100644 (file)
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/inline_matmul_25.f90 b/gcc/testsuite/gfortran.dg/inline_matmul_25.f90
new file mode 100644 (file)
index 0000000..df8ad06
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-ffrontend-optimize" }
+! PR fortran/99839 - ICE in inline_matmul_assign
+
+program p
+  real :: x(3, 3) = 1.0
+  class(*), allocatable :: z(:, :)
+  z = matmul(x, x)
+end