[fortran] PR 54208 compilation error for ubound construct in PARAMETER statements

Message ID 504A04B2.1000407@sfr.fr
State New
Headers show

Commit Message

Mikael Morin Sept. 7, 2012, 2:29 p.m.

here comes a low hanging regression(4.6/4.7/4.8) fix.
In the test provided:

  integer, parameter :: n=2
  integer, dimension(1-min(n,2)/2:n) :: arr
  integer, parameter :: i=ubound(arr,1)

gfc_match_init_expr checks right away (at parse time) that the
definition for `i' is a constant (so called init-) expression.  However,
`arr' is resolved too late for the ubound call to be simplified, so that
the expression is seen as non-constant.

The solution is to add the missing call to gfc_resolve_array_spec.
Janus had a patch that added it in resolve_variable, but it regressed.
This patch adds the call in simplify_bound_dim instead.

Regression tested on x86_64-unknown-linux-gnu. OK for 4.8/4.7/4.6?



Tobias Burnus Sept. 7, 2012, 4:41 p.m. | #1
On 09/07/2012 04:29 PM, Mikael Morin wrote:
> Regression tested on x86_64-unknown-linux-gnu. OK for 4.8/4.7/4.6?

Looks fine. Thanks!



2012-09-07  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/54208
	* simplify.c (simplify_bound_dim): Resolve array spec before
	proceeding with simplification.

2012-09-07  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/54208
	* gfortran.dg/bound_simplification_3.f90: New test.

Index: simplify.c
--- simplify.c	(révision 190976)
+++ simplify.c	(copie de travail)
@@ -3255,6 +3255,9 @@  simplify_bound_dim (gfc_expr *array, gfc_expr *kin
   gcc_assert (array->expr_type == EXPR_VARIABLE);
   gcc_assert (as);
+  if (gfc_resolve_array_spec (as, 0) == FAILURE)
+    return NULL;
   /* The last dimension of an assumed-size array is special.  */
   if ((!coarray && d == as->rank && as->type == AS_ASSUMED_SIZE && !upper)
       || (coarray && d == as->rank + as->corank