[flang] Execution result error of assignment statement using vector subscript for mask-expr in WHERE construct
Version of flang-new : 17.0.0(633146093c4ea78dc8f56a27006fe4eed84be370)
If a vector subscript is used in mask-expr of WHERE construct, the execution result of the assignment statement is incorrect.
The following are the test program, results of Flang-new, GFortran and ifort compilation and execution.
snf95_082_3.f90:
program main
interface assignment(=)
elemental subroutine aaa(ifun,iii)
intent(inout) :: ifun
intent(in) :: iii
character iii
end subroutine aaa
end interface assignment(=)
integer arr1(10)
integer arr2(10)
arr1=(/1,12,3,14,5,16,7,18,9,20/)
arr2=1
do:where (arr1.eq.(/1,2,3,4,5,6,7,8,9,10/))
arr2=char(arr1)
else where do
arr2=ifunng(arr1)
end where do
write(6,*) "arr2 = ", arr2
do i=1,10
if (arr2(i).ne.i) write(6,*) "NG arr2(", i, ") = ", arr2(i)
end do
contains
elemental function ifunng(iii)
intent(in) :: iii
ifunng=iii-10
end function ifunng
end program main
elemental subroutine aaa(ifun,iii)
intent(inout) :: ifun
intent(in) :: iii
character iii
ifun=ichar(iii)
end subroutine aaa
$ flang-new -flang-experimental-exec snf95_082_3.f90; ./a.out
arr2 = -9 2 3 1 5 6 7 8 9 10
NG arr2( 1 ) = -9
NG arr2( 4 ) = 1
$
$ gfortran snf95_082_3.f90; ./a.out
arr2 = 1 2 3 4 5 6 7 8 9 10
$
$ ifort snf95_082_3.f90; ./a.out
arr2 = 1 2 3 4 5 6
7 8 9 10
$
@llvm/issue-subscribers-bug
Test program doesn't build with flang-new -flang-experimental-hlfir:
llvm-project/flang/lib/Optimizer/Builder/HLFIRTools.cpp:616: not yet implemented: inquire type parameters of hlfir.expr
The test program now works when built with flang-new -flang-experimental-hlfir:
$ flang-new -flang-experimental-hlfir test.f90 && ./a.out
arr2 = 1 2 3 4 5 6 7 8 9 10
$
The missing HLFIR feature must have been implemented recently.
Thank you for your comment.
I can now get correct results by using the latest version of flang-new and adding the option (-flang-experimental-hlfir).
$ flang-new snf95_082_3.f90 -flang-experimental-hlfir; ./a.out
arr2 = 1 2 3 4 5 6 7 8 9 10
$
I close this issue.
I'm sorry.
If the option (-flang-experimental-hlfir) is specified for flang-new, I get the correct result, but if the option is not specified, I get the wrong result, so let the issue be Open.
If I get the correct result without any options, let issue be close.
This issue isn't reproduced now because HLFIR is enabled by default.
$ flang-new -v snf95_082_3.f90
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git ba89749cd24950c9c51f4cc64277ce0421d86d20)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
:
$ ./a.out
arr2 = 1 2 3 4 5 6 7 8 9 10