Hello,
Revision 180898:
http://gcc.gnu.org/viewcvs?view=revision&revision=180898
introduced at the end of gfc_add_loop_ss_code some self recursive calls
to handle reductions' loops (like in sum for example).
However, as gfc_add_loop_ss_code already calls itself to handle scalar
and vector subscripts, the new calls had to be disabled if there was
such a subscript, as in that case the reduction(s) would have been
handled from within the subscript call.
Back then, I didn't pay attention, however, to the fact that the
subscript flag was set to true in all the subscript calls, so the
reductions are then handled with subscript set to true, which introduces
an unwanted conversion to gfc_array_index_type and the failure leading
to the PR.
The patch below (which is the one posted on bugzilla) disables reduction
handling if subscript is true, so that the reductions are handled from
the outer call instead of from the subscript call.
I have finally convinced myself that it is always right, as if there is
a reduction in a subscript, gfc_add_loop_ss_code will call
gfc_conv_expr_descriptor which will create a temporary, and the
reduction will be handled separatedly in a new loop initializing the
temporary.
Regression tested on x86_64-unknown-freebsd9.0.
OK for trunk/4.7?
Mikael
2012-07-15 Mikael Morin <mik...@gcc.gnu.org>
PR fortran/53732
* trans-array.c (gfc_add_loop_ss_code): Disable self recursive calls
handling nested loop(s) if the subscript flag is true.
diff --git a/trans-array.c b/trans-array.c
index f135af1..d289ac3 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -2398,7 +2398,6 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
gfc_ss_info *ss_info;
gfc_array_info *info;
gfc_expr *expr;
- bool skip_nested = false;
int n;
/* Don't evaluate the arguments for realloc_lhs_loop_for_fcn_call; otherwise,
@@ -2487,12 +2486,7 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
/* Add the expressions for scalar and vector subscripts. */
for (n = 0; n < GFC_MAX_DIMENSIONS; n++)
if (info->subscript[n])
- {
- gfc_add_loop_ss_code (loop, info->subscript[n], true, where);
- /* The recursive call will have taken care of the nested loops.
- No need to do it twice. */
- skip_nested = true;
- }
+ gfc_add_loop_ss_code (loop, info->subscript[n], true, where);
set_vector_loop_bounds (ss);
break;
@@ -2548,7 +2542,7 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript,
}
}
- if (!skip_nested)
+ if (!subscript)
for (nested_loop = loop->nested; nested_loop;
nested_loop = nested_loop->next)
gfc_add_loop_ss_code (nested_loop, nested_loop->ss, subscript, where);
2012-07-03 Mikael Morin <mik...@gcc.gnu.org>
PR fortran/53732
* gfortran.dg/inline_sum_4.f90: New test.
! { dg-do compile }
!
! PR fortran/53732
! this was leading to an internal "mismatching comparison operand types" error
!
! Contributed by minzastro <minzas...@googlemail.com>
program test
implicit none
real*8 arr(4, 4, 4, 4)
arr(:,:,:,:) = 1d0
arr(1, :, :, = sum(arr, dim=1, mask=(arr(:,:,:,:) > 0d0))
end program test