(The code mentioned below is available 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 the Classic flang 7.1.0, flang in Bisheng Compiler 1.3.3.b023, flang in AOCC 3.2, and NVIDIA nvfortran 21.11 & 22.1 encounter errors, which will be detailed in the sequel.
! test.f90
module test_implied_do_mod
implicit none
private
public :: test_implied_do
contains
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'
else
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
The flang-based compilers encounter the following errors.
1. Classic flang on Ubuntu 20.04
When invoked without any option:
$ flang test.f90 && /a.out
Test: Implied do.
Segmentation error
When invoked with -Mbounds
:
$ flang -Mbounds test.f90 && ./a.out
Test: Implied do.
0: Subscript out of range for array ffilt (test.f90: 25)
subscript=19, lower bound=1, upper bound=2, dimension=1
2. Bisheng flang on Kunpeng platform with Ubuntu 18.04
When invoked without any option:
$flang test.f90 && ./a.out
Test: Implied do.
Segmentation fault (core dumped)
When invoked with -Mbounds
$flang -Mbounds test.f90 && ./a.out
Test: Implied do.
0: Subscript out of range for array ffilt (test.f90: 26)
subscript=-1556092340, lower bound=1, upper bound=2, dimension=1
3. AOCC flang on Ubuntu 20.04
When invoked without any option:
$ flang test.f90 && ./a.out
Test: Implied do.
0.000000 0.000000 1.000000 4.000000
0.000000 0.000000 1.000000 4.000000
Wrong
1
When invoked with -Mbounds
$ flang -Mbounds test.f90 && ./a.out
Test: Implied do.
0: Subscript out of range for array ffilt (test.f90: 25)
subscript=0, lower bound=1, upper bound=2, dimension=1
4. NVIDIA nvfortran on Ubuntu 20.04
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
Wrong
1
When invoked with -Mbounds
:
$ nvfortran -Mbounds test.f90 && ./a.out
Test: Implied do.
0: Subscript out of range for array ffilt (test.f90: 25)
subscript=0, lower bound=1, upper bound=2, dimension=1
Is there anything wrong with the code of test.f90
? Is it standard-conforming? Thank you