Temporary arrays in array assignment in presence of pointers

Fortran array assignment rules permit assignments with overlapping subsections and the requirement is that this should not affect the evaluation. Fortran compilers typically insert a temporary array copy when there is an array section assignment to ensure that there is no effect on the result of the assignment. This temporary array can be optimized away in some cases like when there is no array overlap (or full overlap) between the array sections in the lhs and rhs of the array assignment.

For the Fortran code given below gfortran does not have a temporary array copy but classic flang (github.com/flang-compiler/flang) shows a temporary copy. Is the temporary array not required here because val2 on both lhs and rhs of the assignment have the same indices/section? Or is it required because val1 can potentially be a pointer to the same location that val2 is and removing the temporary will cause incorrect results?

  subroutine cdata(n,dim1,val2,val1)
    implicit none

    integer :: n,dim1
    real(4), pointer :: val2(:,:)
    real(4), pointer :: val1(:)
    integer :: i

    do i=1,n
      val2(1:dim1,i) = val2(1:dim1,i)*val1(i)
    end do

  end subroutine cdata

Thanks @pmk for replying. I could not write an example that causes the results of flang and gfortran (without temporary arrays) to differ.

I am thinking that gfortran is probably right here since even if val1 aliases with val2, it does not matter. The evaluation of the array assignment expression here depends only on a single value in val1, i.e. val1(i). As long as this value is read and stored in a register/temporary location, even if val1(i) is written into during the evaluation of the array assignment it is fine and the results do not change. For val2 the lhs and rhs refer to the same section and indices, so each element can be multiplied by val1(i) and updated in place without a temporary array I guess.