This PR came about because index expressions of the form k+k in
implied DO loops in I/O statements were considered for replacement
by array slices.
Fixed by only doing the transformation if the expression is of the
type expr OP contastant.
gcc/fortran/ChangeLog:
PR fortran/100227
* frontend-passes.c (traverse_io_block): Adjust test for
when a variable is eligible for the transformation to
array slice.
gcc/testsuite/ChangeLog:
PR fortran/100227
* gfortran.dg/implied_do_io_7.f90: New test.
std::swap (start->value.op.op1, start->value.op.op2);
gcc_fallthrough ();
case INTRINSIC_MINUS:
- if ((start->value.op.op1->expr_type!= EXPR_VARIABLE
- && start->value.op.op2->expr_type != EXPR_CONSTANT)
+ if (start->value.op.op1->expr_type!= EXPR_VARIABLE
+ || start->value.op.op2->expr_type != EXPR_CONSTANT
|| start->value.op.op1->ref)
return false;
if (!stack_top || !stack_top->iter
--- /dev/null
+! { dg-do run }
+! PR 100227 - this was falsely optimized, leading to nonsense results.
+! Original test case by "Mathieu".
+
+program p
+ implicit none
+ integer, parameter :: nbmode = 3
+ integer :: k
+ real :: mass(nbmode*2)
+ character (len=80) :: line
+ do k = 1, nbmode*2
+ mass(k) = k
+ end do
+ write (unit=line,fmt='(*(F6.2))') (mass(k+k), k=1,nbmode)
+ if (line /= ' 2.00 4.00 6.00') stop 1
+end program