Possible NVFORTRAN optimization bug

Greetings,

I was testing a piece of fortran code yesterday, and came up with a very strange behaviour. The code is as follows:

program test_pgi

implicit none

type :: test
class(), pointer :: v1(:)
end type test
type(test), pointer :: my_test
class(
), pointer :: v2(:)
integer(4), target :: aa(2)

aa = (/ 1_4,2_4 /)
allocate(my_test) ; nullify(my_test % v1)
my_test % v1 => aa

select type ( v => my_test % v1 )
type is ( integer )
print*,'v1 is integer= ',v
class default
print*,‘v1 is nothing’
end select

v2 => aa
select type ( v => v2 )
type is ( integer )
print*,'v2 is integer= ',v
class default
print*,‘v2 is nothing’
end select

end program test_pgi

The issue is that, with O1 and O2 flags i get different results, O1 being the correct one. We’ve tried a couple of variations on that, including a longer version using modules, but the problem persisted. The code should return that both v1 and v2 are integers, with values 1 and 2, but O2 returns v1 is nothing. This code runs well with both gfortran (any version beyond 8.1 as far as we tested), xlf AND ifort/2017 and beyond. The issue seems to be old, as older versions of the pgf90 return the same exact issue. Using nvfortran, I’ve compiled this with “nvfortran -O2 -o test.x test.f90” under a POWER9 machine that has both CUDA drivers and the package installed (driver version 440.33.01), and the code is running on host anyways. Am I missing some flag, or is this an optimization bug? If necessary, I can provide the .s files from main versions of the compilers I’ve just cited.

In any case, thank you for your attention,

Best

Thanks Lucas. I was able to reproduce the issue here but will need one of our compiler engineers to look into it to determine what’s going wrong. I’ve filed TPR #29364 to track.

-Mat

1 Like

This bug has been fixed in our latest release, NVIDIA HPC SDK version 21.3. Thanks for the bug report and simple reproducer.