This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] Simplification of SIZE
- From: Paul Brook <paul at nowt dot org>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>,fortran at gcc dot gnu dot org
- Cc: Joost VandeVondele <jv244 at hermes dot cam dot ac dot uk>
- Date: Sat, 18 Oct 2003 00:29:42 +0100
- Subject: [gfortran] Simplification of SIZE
Patch below fixes a bug in the simplification of the SIZE intrinsic.
Applied to tree-ssa branch.
Paul
2003-10-17 Paul Brook <paul@nowt.org>
* simplify.c (gfc_simplify_shape): Use gfc_array_dimen_size.
testsuite
* gfortran.fortran-torture/execute/intrinsic_size.f90: Add
additional case.
diff -urpxCVS clean/tree-ssa/gcc/fortran/simplify.c gcc/gcc/fortran/
simplify.c
--- clean/tree-ssa/gcc/fortran/simplify.c
+++ gcc/gcc/fortran/simplify.c
@@ -3328,38 +3328,29 @@ gfc_simplify_shape (gfc_expr * source)
gfc_expr *
gfc_simplify_size (gfc_expr * array, gfc_expr * dim)
{
- mpz_t shape[GFC_MAX_DIMENSIONS];
- gfc_array_ref *ar;
+ mpz_t size;
gfc_expr *result;
- int n, d;
+ int d;
if (dim == NULL)
{
- if (gfc_array_size (array, &shape[0]) == FAILURE)
+ if (gfc_array_size (array, &size) == FAILURE)
return NULL;
- n = 1;
- d = 1;
}
else
{
- if (dim->expr_type != EXPR_CONSTANT
- || array->expr_type != EXPR_VARIABLE)
+ if (dim->expr_type != EXPR_CONSTANT)
return NULL;
- d = mpz_get_ui (dim->value.integer);
- ar = gfc_find_array_ref (array);
- if (gfc_array_ref_shape (ar, shape) == FAILURE)
+ d = mpz_get_ui (dim->value.integer) - 1;
+ if (gfc_array_dimen_size (array, d, &size) == FAILURE)
return NULL;
- n = (ar->type == AR_FULL) ? ar->as->rank : ar->dimen;
}
result = gfc_constant_result (BT_INTEGER, gfc_default_integer_kind (),
&array->where);
- mpz_set (result->value.integer, shape[d - 1]);
-
- for (d = 0; d < n; d++)
- mpz_clear (shape[d]);
+ mpz_set (result->value.integer, size);
return result;
}
diff -urpxCVS clean/tree-ssa/gcc/testsuite/gfortran.fortran-torture/execute/
intrinsic_size.f90 gcc/gcc/testsuite/gfortran.fortran-torture/execute/
intrinsic_size.f90
--- clean/tree-ssa/gcc/testsuite/gfortran.fortran-torture/execute/
intrinsic_size.f90
+++ gcc/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_size.f90
@@ -3,8 +3,11 @@ program testsize
implicit none
real, dimension(:, :), allocatable :: a
integer, dimension(5) :: j
+ integer, dimension(2, 3) :: b
integer i
+ if (size (b(2, :), 1) .ne. 3) call abort
+
allocate (a(3:8, 5:7))
! With one parameter