Variable aliasing by pgf90?

Hello

When I use a declared integer variable as loop variable for an implied-do and then use the same variable in an internal subroutine, it seems to become aliased to another variable.

In the example, the loop in the subroutine executes the required number of iterations, but the value of the outer loop variable i is always equal to the inner loop variable j. This example works fine with other compilers.

Example:
!-----
PROGRAM pgitest
IMPLICIT NONE
INTEGER, PARAMETER :: imax=2, &
jmax=3
INTEGER :: i, j, array(10)=(/(i, i=1,10)/)

CALL sub1

CONTAINS

SUBROUTINE sub1()

print*, “imax,jmax”, imax,jmax

do i=1,imax
do j=1,jmax
print*, “i,j”,i,j
end do
end do

END SUBROUTINE sub1
!-----

This example code should print

~> a.out
imax,jmax 2 3
i,j 1 1
i,j 1 2
i,j 1 3
i,j 2 1
i,j 2 2
i,j 2 3

but when compiled with pgfortran, I get instead:

~> pgfortran -V

pgfortran 13.10-0 64-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
~> pgfortran pgitest.f90
~> ./a.out
imax,jmax 2 3
i,j 1 1
i,j 2 2
i,j 3 3
i,j 1 1
i,j 2 2
i,j 3 3


Regards
Pirmin

Thanks Primin,

This one is interesting. If you change “i” to be some other variable (like k) in the array’s data initialization or move the initialization into the body, then the example works fine. Somehow it’s use in the data initialization is causing the error. I added problem report TPR#19739 and sent to engineering for further investigation.

Best Regards,
Mat