From: Steven G. Kargl Date: Mon, 9 Nov 2015 05:50:24 +0000 (+0000) Subject: re PR fortran/68053 (lower bound of implied shape array restricted too much) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cdffe78809311f95847d43190626c10bd6f34a46;p=gcc.git re PR fortran/68053 (lower bound of implied shape array restricted too much) 2015-11-08 Steven g. Kargl PR fortran/68053 * decl.c (add_init_expr_to_sym): Try to reduce initialization expression before testing for a constant value. 2015-11-08 Steven g. Kargl PR fortran/68053 * gfortran.dg/pr68053.f90: New test. From-SVN: r229992 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 78644b876b1..cd4c94e6764 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-11-08 Steven g. Kargl + + PR fortran/68053 + * decl.c (add_init_expr_to_sym): Try to reduce initialization expression + before testing for a constant value. + 2015-11-08 Andre Vehreschild PR fortran/68218 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 7178aafe5e1..0c3377f7b08 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1529,26 +1529,34 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) for (dim = 0; dim < sym->as->rank; ++dim) { int k; - gfc_expr* lower; - gfc_expr* e; + gfc_expr *e, *lower; lower = sym->as->lower[dim]; - if (lower->expr_type != EXPR_CONSTANT) + + /* If the lower bound is an array element from another + parameterized array, then it is marked with EXPR_VARIABLE and + is an initialization expression. Try to reduce it. */ + if (lower->expr_type == EXPR_VARIABLE) + gfc_reduce_init_expr (lower); + + if (lower->expr_type == EXPR_CONSTANT) + { + /* All dimensions must be without upper bound. */ + gcc_assert (!sym->as->upper[dim]); + + k = lower->ts.kind; + e = gfc_get_constant_expr (BT_INTEGER, k, &sym->declared_at); + mpz_add (e->value.integer, lower->value.integer, + init->shape[dim]); + mpz_sub_ui (e->value.integer, e->value.integer, 1); + sym->as->upper[dim] = e; + } + else { gfc_error ("Non-constant lower bound in implied-shape" " declaration at %L", &lower->where); return false; } - - /* All dimensions must be without upper bound. */ - gcc_assert (!sym->as->upper[dim]); - - k = lower->ts.kind; - e = gfc_get_constant_expr (BT_INTEGER, k, &sym->declared_at); - mpz_add (e->value.integer, - lower->value.integer, init->shape[dim]); - mpz_sub_ui (e->value.integer, e->value.integer, 1); - sym->as->upper[dim] = e; } sym->as->type = AS_EXPLICIT; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 69c155bb1d9..f8c5d5ab7a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-08 Steven g. Kargl + + PR fortran/68053 + * gfortran.dg/pr68053.f90: New test. + 2015-11-06 Jan Hubicka * g++.dg/lto/pr68057_0.C: Fix testcase. diff --git a/gcc/testsuite/gfortran.dg/pr68053.f90 b/gcc/testsuite/gfortran.dg/pr68053.f90 new file mode 100644 index 00000000000..e59693c5f66 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr68053.f90 @@ -0,0 +1,10 @@ +! { dg-do run } +! PR fortran/68053 +! Original code contributed by Gerhard Steinmetz +! +program p + integer, parameter :: n(3) = [1,2,3] + integer, parameter :: x(1) = 7 + integer, parameter :: z(n(2):*) = x + if (lbound(z,1) /= 2) call abort +end