PR fortran/99840 - ICE in gfc_simplify_matmul, at fortran/simplify.c:4777
authorHarald Anlauf <anlauf@gmx.de>
Thu, 1 Apr 2021 05:49:32 +0000 (07:49 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 1 Apr 2021 05:49:32 +0000 (07:49 +0200)
The simplification of the transposition of a constant array shall properly
initialize and set the shape of the result.

gcc/fortran/ChangeLog:

PR fortran/99840
* simplify.c (gfc_simplify_transpose): Properly initialize
resulting shape.

gcc/testsuite/ChangeLog:

PR fortran/99840
* gfortran.dg/transpose_5.f90: New test.

gcc/fortran/simplify.c
gcc/testsuite/gfortran.dg/transpose_5.f90 [new file with mode: 0644]

index 388aca7..c27b47a 100644 (file)
@@ -8123,8 +8123,8 @@ gfc_simplify_transpose (gfc_expr *matrix)
                               &matrix->where);
   result->rank = 2;
   result->shape = gfc_get_shape (result->rank);
-  mpz_set (result->shape[0], matrix->shape[1]);
-  mpz_set (result->shape[1], matrix->shape[0]);
+  mpz_init_set (result->shape[0], matrix->shape[1]);
+  mpz_init_set (result->shape[1], matrix->shape[0]);
 
   if (matrix->ts.type == BT_CHARACTER)
     result->ts.u.cl = matrix->ts.u.cl;
diff --git a/gcc/testsuite/gfortran.dg/transpose_5.f90 b/gcc/testsuite/gfortran.dg/transpose_5.f90
new file mode 100644 (file)
index 0000000..ed4b643
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! { dg-options "-O2" }
+! PR fortran/99840 - ICE in gfc_simplify_matmul, at fortran/simplify.c:4777
+program p
+  integer, parameter :: x(0,0) = 0
+  integer :: y(0,0)
+  y = matmul (x, transpose(x))
+end