https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99840

--- Comment #4 from anlauf at gcc dot gnu.org ---
For reasons I do not understand,

Breakpoint 1, gfc_simplify_matmul (matrix_a=0x292bbf0, matrix_b=0x292c550)
    at ../../gcc-trunk/gcc/fortran/simplify.c:4777
4777          result_columns = mpz_get_si (matrix_b->shape[1]);
(gdb) p matrix_b->shape[1]                         
$64 = {{_mp_alloc = 0, _mp_size = 0, _mp_d = 0x0}}
(gdb) p matrix_b->shape[0]
$65 = {{_mp_alloc = 0, _mp_size = 0, _mp_d = 0x0}}

This is a result from the mpz_set in gfc_simplify_transpose.
Isn't this a representation of zero?

Alternative patch, which passes the relevant regtesting:

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 388aca7c38c..b884a81fce0 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -8123,16 +8123,16 @@ 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]);
+  matrix_rows = mpz_get_si (matrix->shape[0]);
+  matrix_cols = mpz_get_si (matrix->shape[1]);
+  mpz_init_set_si (result->shape[0], matrix_cols);
+  mpz_init_set_si (result->shape[1], matrix_rows);

   if (matrix->ts.type == BT_CHARACTER)
     result->ts.u.cl = matrix->ts.u.cl;
   else if (matrix->ts.type == BT_DERIVED)
     result->ts.u.derived = matrix->ts.u.derived;

-  matrix_rows = mpz_get_si (matrix->shape[0]);
-  matrix_cols = mpz_get_si (matrix->shape[1]);
   for (row = 0; row < matrix_rows; ++row)
     for (col = 0; col < matrix_cols; ++col)
       {

Reply via email to