We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all, some time ago I’ve faced an interesting difference in behaviour between different compilers.
Briefly, if there is a function, where in the specification part the ubounds/lbounds functions are used in the specification part, e.g.
ubounds
lbounds
function justcopy(arr_in) real, intent(in) :: arr_in(0:,:) real :: justcopy(0:ubound(arr_in,dim=1), 2:5) ....
the actual size of the declared array will be different, as if ubound is calculated before the declaration of the array.
ubound
See details here fortran-lang.discourse.group/.../3
My assumption is that such a behaviour is a bug.
Best regards, Andrii
P.S. As of now I've tested this code
program aocc_run_test implicit none real :: arr_in1(0:10, 2:5), arr1(0:10,2:5) integer i, j do i=0,10 do j=2,5 arr_in1(i,j) = 1000*i+j end do end do call evaluate(arr_in1,arr1) contains function justcopy(arr_in) implicit none real, intent(in) :: arr_in(0:,:) real :: justcopy(0:ubound(arr_in,dim=1), 2:5) !This works for "A" GNU,Intel/InteLLVM,lfortran,NAG,IBM. Does not work for "B" AOCC, NVidia, ARM. !real :: justcopy(0:size(arr_in,dim=1)-1, 2:5) !This works for all compilers write(*,*) "arr_in, dim 1 (lb,ub,sz):", lbound(arr_in,dim=1),ubound(arr_in,dim=1),size(arr_in,1) write(*,*) "arr_in, dim 2 (lb,ub,sz):", lbound(arr_in,dim=2),ubound(arr_in,dim=2),size(arr_in,2) write(*,*) "justcp, dim 1 (lb,ub,sz):", lbound(justcopy,dim=1),ubound(justcopy,dim=1),size(justcopy,1) write(*,*) "justcp, dim 2 (lb,ub,sz):", lbound(justcopy,dim=2),ubound(justcopy,dim=2),size(justcopy,2) justcopy=arr_in end function justcopy subroutine evaluate(arr_in1,arr_out1) implicit none real, intent(in) :: arr_in1(:,:) real, intent(out) :: arr_out1(:,:) real, allocatable :: X(:,:) !arr_out1 = justcopy(arr_in1) X = justcopy(arr_in1) write(*,*) "X , dim 1 (lb,ub,sz):", lbound(X,dim=1),ubound(X,dim=1),size(X,1) write(*,*) "X , dim 2 (lb,ub,sz):", lbound(X,dim=2),ubound(X,dim=2),size(X,2) if (size(X,1) /= size(arr_in1,1)) then print "(A,I2,A,I2)","Error: size of X(dim1)=",size(X,1),& " was not equal to size of arr_in1(dim1)=",size(arr_in1,1) error stop 1 end if arr_out1 = X end subroutine evaluate end program aocc_run_test
with 24.10.1 on Rocky9 (RHEL9).
Edit: actually the bug is present in 23.10, but seems to be absent in 24.10.1.
Thank you for this information. I have notified the appropriate teams internally.
Is using the 24.10 release a suitable solution?