A bug of `nvfortran` 21.11

(The code reflecting the issue is available at GitHub. See also discussions at Fortran Discourse and Flang issue #1200 at GitHub)

Below is a piece of code involving implied do and array constructor. Gfortran, Intel ifort and ifx, NAG nagfor, Absoft af95, and Oracle sunf95 can all handle it, but nvfortran 21.11 encounters errors, which will be detailed in the sequel.

! test.f90 (available at https://github.com/zaikunzhang/test_compiler)
module test_implied_do_mod
implicit none
public :: test_implied_do


subroutine test_implied_do()
implicit none
integer :: i
integer :: nfilt
integer, parameter :: maxfilt = 2
logical :: better(maxfilt)
real :: cfilt(maxfilt)
real :: cstrv
real :: f
real :: ffilt(maxfilt)

ffilt = [2.0, 3.0]
cfilt = [3.0, 2.0]
f = 1.0
cstrv = 4.0

nfilt = maxfilt
better(1:nfilt) = [(isbetter([ffilt(i), cfilt(i)], [f, cstrv]), i=1, nfilt)]
if (.not. any(better(1:nfilt))) then
    print *, 'Right'
    print *, 'Wrong'
    stop 1
end if
end subroutine test_implied_do

function isbetter(fc1, fc2) result(is_better)
implicit none
real, intent(in) :: fc1(:)
real, intent(in) :: fc2(:)
logical :: is_better

write (*, *) fc1, fc2
is_better = all(fc1 < fc2)
end function isbetter

end module test_implied_do_mod

program test
use, non_intrinsic :: test_implied_do_mod, only : test_implied_do
implicit none

print *, 'Test: Implied do.'
call test_implied_do()
print *, 'Succeed: Implied do.'

end program test

nvfortran 21.11 encounters the following errors.

When invoked without any options

$ nvfortran test.f90 
 $ ./a.out 
 Test: Implied do.
    0.000000        3.000000        1.000000        4.000000    
    0.000000        3.000000        1.000000        4.000000    

When invoked with -Mbounds:

$ nvfortran -Mbounds test.f90
$ ./a.out
 Test: Implied do.
0: Subscript out of range for array ffilt (testsuite/test_implied_do.f90: 25)
    subscript=0, lower bound=1, upper bound=2, dimension=1


Sorry that we only work on jetson platform issues. Other moderators may reply your issue for nvfortran.

1 Like

Hello @jmudd, @MatColgrove ! Sorry for bothering you with this, but I do believe it is a considerable bug in nvfortran 21.11. Thank you very much for having a look at it.

Thanks Zaikunzhang, I’ve filed a problem report, TPR #31090, and sent it to engineering for further investigation.


1 Like

Thank you @MatColgrove ! I look forward to seeing the bug fixed. It concerns an essential part of my project. While gfortran, ifort, nagfor, and af95 can all handle the code correctly, I do hope my project works with nvfortran and flang as well.

The same issue exists in the classic flang 7.1.0 and the flang in AOCC 3.2. See the following bug reports and discussions for details.

Thank NVIDIA engineers and developers for fixing it as soon as possible.

The bug still exists in the NVIDIA HPC SDK Version 22.1 released in January 2022.

Engineering’s initial assessment is that this will be a difficult issue to fix so may not any time soon.

1 Like

Thanks for the update.

For your information, the same problem ( Implied do and array constructor: a bug of flang and related compilers #1200) has been fixed in the classic Flang:

Fix implied do and array constructor (fixes #1200)

Hope this might be helpful. Thanks.