llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.04k stars 11.58k forks source link

[Flang] Incorrect execution result of using the array defined in FORALL construct with scalar-mask-expr #62980

Closed ohno-fj closed 10 months ago

ohno-fj commented 1 year ago
Version of flang-new : 17.0.0(f6c4808d95221a5838e14474d95c6fe85bb1488a)

In Flang, the value of the array used in the scalar-mask-expr(a(i)>1) appears to reflect the value of the array definition in the FORALL construct.

The following are the test program, results of Flang-new, GFortran and ifort compilation and execution.

z033.f90:

program main
  integer,dimension(4)::a=(/11,-2,21,1/)
  write(6,*) "before a = ", a
  forall(i=1:3,a(i)>1)
     a(i+1) = 10
  end forall
  write(6,*) "after  a = ", a
end program main
$ flang-new -flang-experimental-exec z033.f90; ./a.out
 before a =  11 -2 21 1
 after  a =  11 10 10 10
$
$ gfortran z033.f90; ./a.out
 before a =           11          -2          21           1
 after  a =           11          10          21          10
$
$ ifort z033.f90; ./a.out
 before a =           11          -2          21           1
 after  a =           11          10          21          10
$
llvmbot commented 1 year ago

@llvm/issue-subscribers-flang-frontend

llvmbot commented 1 year ago

@llvm/issue-subscribers-bug

luporl commented 1 year ago

The issue doesn't happen when the test program is built with flang-new -flang-experimental-hlfir.

yus3710-fj commented 10 months ago

This issue isn't reproduced now because HLFIR is enabled by default.

$ flang-new -v z033.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 
 before a =  11 -2 21 1
 after  a =  11 10 21 10