re PR fortran/30872 (Bogus "size of variable is too large")

2007-04-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30872
	* expr.c (find_array_element): Correct arithmetic for rank > 1.

2007-04-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30872
	* gfortran.dg/parameter_array_element_1.f90: New test.

From-SVN: r123644
This commit is contained in:
Paul Thomas 2007-04-07 20:23:40 +00:00
parent 909a3e38aa
commit 4c6b3ec750
4 changed files with 41 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2007-04-07 Paul Thomas <pault@gcc.gnu.org>
PR fortran/30872
* expr.c (find_array_element): Correct arithmetic for rank > 1.
2007-04-07 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31222

View File

@ -899,6 +899,8 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
int i;
mpz_t delta;
mpz_t offset;
mpz_t span;
mpz_t tmp;
gfc_expr *e;
try t;
@ -907,6 +909,8 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
mpz_init_set_ui (offset, 0);
mpz_init (delta);
mpz_init (tmp);
mpz_init_set_ui (span, 1);
for (i = 0; i < ar->dimen; i++)
{
e = gfc_copy_expr (ar->start[i]);
@ -930,7 +934,13 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
}
mpz_sub (delta, e->value.integer, ar->as->lower[i]->value.integer);
mpz_mul (delta, delta, span);
mpz_add (offset, offset, delta);
mpz_set_ui (tmp, 1);
mpz_add (tmp, tmp, ar->as->upper[i]->value.integer);
mpz_sub (tmp, tmp, ar->as->lower[i]->value.integer);
mpz_mul (span, span, tmp);
}
if (cons)
@ -949,6 +959,8 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
depart:
mpz_clear (delta);
mpz_clear (offset);
mpz_clear (span);
mpz_clear (tmp);
if (e)
gfc_free_expr (e);
*rval = cons;

View File

@ -1,3 +1,8 @@
2007-04-07 Paul Thomas <pault@gcc.gnu.org>
PR fortran/30872
* gfortran.dg/parameter_array_element_1.f90: New test.
2007-04-07 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31222

View File

@ -0,0 +1,19 @@
! { dg-do compile}
! { dg-options "-fdump-tree-original" }
! Tests the fix for PR 30872, in which the array element references bo(1,1) etc.
! would be wrong for rank > 1.
!
! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
!
INTEGER, PARAMETER, DIMENSION(2,3) :: bo= &
RESHAPE((/-1,1,-2,2,-3,3/),(/2,3/))
REAL(kind=8), DIMENSION( &
bo(1,1):bo(2,1), &
bo(1,2):bo(2,2), &
bo(1,3):bo(2,3)) :: out_val
out_val=0.0
END
! Scan for the 105 in the declaration real8 out_val[105];
! { dg-final { scan-tree-dump-times "105" 1 "original" } }
! { dg-final { cleanup-tree-dump "original" } }