llvm / llvm-project

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

[Flang][OpenMP] Incorrect execution result when a variable declared by both common and namelist statement is used in do reduction construct and namelist-group-name is output #101907

Open ohno-fj opened 1 month ago

ohno-fj commented 1 month ago
Version of flang-new : 19.0.0(41211919db5feb279d2954eb590a3cf2a1742152)/AArch64

When a variable declared by both common and namelist statement is used in do reduction construct and namelist-group-name is output, the output is incorrect.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snggq855_222.f90:

program main
  call sub1
end program main

subroutine sub1()
  common // im1
  namelist /nam/im1
  im1=10
!$omp parallel
!$omp do reduction (+:im1)
  do j=1,4
     im1 = im1 + 1
     write(1,nam)
  enddo
!$omp enddo
!$omp end parallel
end subroutine sub1
$ flang-new -fopenmp snggq855_222.f90; ./a.out; cat fort.1
 &NAM IM1= 10/
 &NAM IM1= 10/
 &NAM IM1= 10/
 &NAM IM1= 10/
$
$ gfortran -fopenmp snggq855_22.f90; ./a.out; cat fort.1
&NAM
 IM1=1          ,
 /
&NAM
 IM1=2          ,
 /
&NAM
 IM1=1          ,
 /
&NAM
 IM1=2          ,
 /
$
$ ifort -qopenmp -diag-disable=10448 snggq855_22.f90; ./a.out; cat fort.1
 &NAM
 IM1     =           1
 /
 &NAM
 IM1     =           1
 /
 &NAM
 IM1     =           2
 /
 &NAM
 IM1     =           2
 /
$
llvmbot commented 1 month ago

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 19.0.0(41211919db5feb279d2954eb590a3cf2a1742152)/AArch64 ``` When a variable declared by both `common` and `namelist` statement is used in `do reduction` construct and `namelist-group-name` is output, the output is incorrect. The following are the test program, Flang-new, Gfortran and ifort compilation/execution result. snggq855_222.f90: ```fortran program main call sub1 end program main subroutine sub1() common // im1 namelist /nam/im1 im1=10 !$omp parallel !$omp do reduction (+:im1) do j=1,4 im1 = im1 + 1 write(1,nam) enddo !$omp enddo !$omp end parallel end subroutine sub1 ``` ``` $ flang-new -fopenmp snggq855_222.f90; ./a.out; cat fort.1 &NAM IM1= 10/ &NAM IM1= 10/ &NAM IM1= 10/ &NAM IM1= 10/ $ ``` ``` $ gfortran -fopenmp snggq855_22.f90; ./a.out; cat fort.1 &NAM IM1=1 , / &NAM IM1=2 , / &NAM IM1=1 , / &NAM IM1=2 , / $ ``` ``` $ ifort -qopenmp -diag-disable=10448 snggq855_22.f90; ./a.out; cat fort.1 &NAM IM1 = 1 / &NAM IM1 = 1 / &NAM IM1 = 2 / &NAM IM1 = 2 / $ ```