aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2008-01-08 15:14:33 +0000
committerPaul Thomas <pault@gcc.gnu.org>2008-01-08 15:14:33 +0000
commit0c6ce8b02716646c4ecf998a96c40621a5cba15e (patch)
tree428f9813996262ab2e07f6030752e8726adc9784 /gcc
parent3672065a1dc197ed785e6b1ffae1449621c5e3d2 (diff)
downloadgcc-0c6ce8b02716646c4ecf998a96c40621a5cba15e.zip
gcc-0c6ce8b02716646c4ecf998a96c40621a5cba15e.tar.gz
gcc-0c6ce8b02716646c4ecf998a96c40621a5cba15e.tar.bz2
re PR fortran/34476 (Parameters: Bogus out of bounds error in array constructor)
2008-01-08 Paul Thomas <pault@gcc.gnu.org> PR fortran/34476 * expr.c (find_array_element): Check that the array bounds are constant before using them. Use lower, as well as upper bound. (check_restricted): Allow implied index variable. 2008-01-08 Paul Thomas <pault@gcc.gnu.org> PR fortran/34476 * gfortran.dg/parameter_array_init_3.f90: New test. From-SVN: r131396
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/expr.c18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/parameter_array_init_3.f9016
4 files changed, 39 insertions, 7 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index dd2492d..40c98af 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,12 @@
2008-01-08 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/34476
+ * expr.c (find_array_element): Check that the array bounds are
+ constant before using them. Use lower, as well as upper bound.
+ (check_restricted): Allow implied index variable.
+
+2008-01-08 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/34681
* trans_array.c (gfc_trans_deferred_array): Do not null the
data pointer on entering scope, nor deallocate it on leaving
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 8ae8464..e8b6548 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1024,14 +1024,17 @@ find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
cons = NULL;
goto depart;
}
-
- /* Check the bounds. */
- if (ar->as->upper[i]
- && (mpz_cmp (e->value.integer, ar->as->upper[i]->value.integer) > 0
- || mpz_cmp (e->value.integer,
- ar->as->lower[i]->value.integer) < 0))
+ /* Check the bounds. */
+ if ((ar->as->upper[i]
+ && ar->as->upper[i]->expr_type == EXPR_CONSTANT
+ && mpz_cmp (e->value.integer,
+ ar->as->upper[i]->value.integer) > 0)
+ ||
+ (ar->as->lower[i]->expr_type == EXPR_CONSTANT
+ && mpz_cmp (e->value.integer,
+ ar->as->lower[i]->value.integer) < 0))
{
- gfc_error ("index in dimension %d is out of bounds "
+ gfc_error ("Index in dimension %d is out of bounds "
"at %L", i + 1, &ar->c_where[i]);
cons = NULL;
t = FAILURE;
@@ -2496,6 +2499,7 @@ check_restricted (gfc_expr *e)
if (sym->attr.in_common
|| sym->attr.use_assoc
|| sym->attr.dummy
+ || sym->attr.implied_index
|| sym->ns != gfc_current_ns
|| (sym->ns->proc_name != NULL
&& sym->ns->proc_name->attr.flavor == FL_MODULE)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5b95e29..01389c9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2008-01-08 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/34476
+ * gfortran.dg/parameter_array_init_3.f90: New test.
+
+2008-01-08 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/34681
PR fortran/34704
* gfortran.dg/alloc_comp_default_init_1.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/parameter_array_init_3.f90 b/gcc/testsuite/gfortran.dg/parameter_array_init_3.f90
new file mode 100644
index 0000000..e39da8e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parameter_array_init_3.f90
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! Test the fix for PR34476 in which an 'out of bounds' error would be
+! generated for the array initializations AND the implicit index 'i'
+! would be rejected.
+!
+! Reported by Tobias Burnus <burnus@gcc.gnu.org> following a thread
+! on comp.lang.fortran (see PR)
+!
+module abuse_mod
+ implicit none
+ integer i
+ character(8), parameter :: HEX1 = '40490FDB'
+ integer(1), parameter :: MSKa1(len(HEX1)) = [(1,i=1,len(HEX1))]
+ integer(1), parameter :: ARR1(len(HEX1)) = [( MSKa1(i), i=1,len(HEX1) )]
+end module abuse_mod
+! { dg-final { cleanup-modules "abuse_mod" } }