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