------- Comment #3 from rguenth at gcc dot gnu dot org 2010-04-21 14:26 ------- subroutine test0(esss,Ix, e_x) real(kind=kind(1.0d0)), dimension(:), intent(out) :: esss real(kind=kind(1.0d0)), dimension(:) :: Ix integer(kind=kind(1)), dimension(:) :: e_x esss = Ix(e_x) end subroutine
where we create the temporary during gfc_conv_loop_setup -> gfc_add_loop_ss_code when handling the GFC_SS_SECTION subscript e_x and want to get its array descriptor. To be able to specialize this we'd need to know whether at the end we're going to need a descriptor for the GFC_SS_SECTION (because we are passing it to a function or so) or whether we are going to access single elements only. It looks like this is all because of the convert intrinsic called by __convert_i4_i8[[((test0:e_x(FULL)))]] which is emitted regardless of the type of e_x (even if it is integer(kind=kind(8))). Testcase is fixed by Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 158590) +++ gcc/fortran/resolve.c (working copy) @@ -4007,8 +4007,7 @@ gfc_resolve_index (gfc_expr *index, int &index->where) == FAILURE) return FAILURE; - if (index->ts.kind != gfc_index_integer_kind - || index->ts.type != BT_INTEGER) + if (index->ts.type != BT_INTEGER) { gfc_clear_ts (&ts); ts.type = BT_INTEGER; Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (revision 158590) +++ gcc/fortran/trans-array.c (working copy) @@ -2434,6 +2434,7 @@ gfc_conv_array_index_offset (gfc_se * se gfc_conv_array_data (desc)); index = gfc_build_array_ref (data, index, NULL); index = gfc_evaluate_now (index, &se->pre); + index = fold_convert (gfc_array_index_type, index); /* Do any bounds checking on the final info->descriptor index. */ index = gfc_trans_array_bound_check (se, info->descriptor, -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43829