RFA: PR fortran/12840: Scalarisation of general array constructors

Paul Brook paul@codesourcery.com
Thu Sep 8 15:21:00 GMT 2005


> + /* Return the number of iterations in a loop that starts at START,
> +    ends at END, and has step STEP.  */
> +
> + static tree
> + gfc_get_iteration_count (tree start, tree end, tree step)
> + {
> +   tree tmp;
> +
> +   tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, end, start);
> +   tmp = fold_build2 (FLOOR_DIV_EXPR, gfc_array_index_type, tmp, step);
> +   tmp = fold_build2 (PLUS_EXPR, gfc_array_index_type, tmp, 
gfc_index_one_node); 
> tmp = fold_build2 (MAX_EXPR, gfc_array_index_type, 
> tmp, gfc_index_zero_node); +   return tmp;
> + }

You've got a type mismatch here. When called from 
gfc_trans_array_constructor_value the three arguments have the user-specified 
type, not gfc_array_index_type. 

You probably want to perform the calculation in the specified type, then cast 
to gfc_array_index_type. I don't remember if the frontend converts all three 
arguments to same type, you may also need to do that.

With your patch the following testcase fails on 32-bit targets:

program array_constructor_x
  integer(8) i, k, n
  ! Maybe pick a large power of two so truncating to a narrower type
  ! will give zero
  integer(8), parameter :: big = 10000000000_8
  k = big * 4
  n = big
  ! Check that loop iteration calculations are done in the user specified
  ! type kind, not size_t
  call foo ((/(4.0, i=big,k, n)/))
contains
subroutine foo(a)
  real, dimension(:) :: a
  print *, a
end subroutine
end program

Paul



More information about the Fortran mailing list