From 4c6b3ec7507e827156a1fdf8b904303b50eedf75 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 7 Apr 2007 20:23:40 +0000 Subject: [PATCH] re PR fortran/30872 (Bogus "size of variable is too large") 2007-04-07 Paul Thomas PR fortran/30872 * expr.c (find_array_element): Correct arithmetic for rank > 1. 2007-04-07 Paul Thomas PR fortran/30872 * gfortran.dg/parameter_array_element_1.f90: New test. From-SVN: r123644 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/expr.c | 12 ++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/parameter_array_element_1.f90 | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/parameter_array_element_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a9a8a07..6fba5b3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,10 @@ 2007-04-07 Paul Thomas + PR fortran/30872 + * expr.c (find_array_element): Correct arithmetic for rank > 1. + +2007-04-07 Paul Thomas + PR fortran/31222 * check.c (numeric_check): If an expresson has not got a type, see if it is a symbol for which a default type applies. diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index bf5b74d..d3f57172 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index df1d06a..fb1bbbe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2007-04-07 Paul Thomas + PR fortran/30872 + * gfortran.dg/parameter_array_element_1.f90: New test. + +2007-04-07 Paul Thomas + PR fortran/31222 * gfortran.dg/default_numeric_type_1.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/parameter_array_element_1.f90 b/gcc/testsuite/gfortran.dg/parameter_array_element_1.f90 new file mode 100644 index 0000000..8dfe544 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_array_element_1.f90 @@ -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 +! + 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" } } + -- 2.7.4