Hello,

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?

Mikael



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

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

2012-09-07  Mikael Morin  <mik...@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

! { dg-do compile }
! { dg-options "-fdump-tree-original" }
!
! PR fortran/54208
! The I and J definitions used to raise an error because ARR's array spec
! was resolved to late for the LBOUND and UBOUND calls to be simplified to
! a constant.
!
! Contributed by Carlos A. Cruz <carlos.a.c...@nasa.gov>

program testit
  integer, parameter :: n=2
  integer, dimension(1-min(n,2)/2:n) :: arr
  integer, parameter :: i=lbound(arr,1)
  integer, parameter :: j=ubound(arr,1)
  ! write(6,*) i, j
  if (i /= 0) call abort
  if (j /= 2) call abort
end program testit

! { dg-final { scan-tree-dump-times "bound" 0 "original" } }
! { dg-final { scan-tree-dump-times "abort" 0 "original" } }
! { dg-final { cleanup-tree-dump "original" } }

Reply via email to