llvm / llvm-project

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

[Flang][OpenMP] Compilation error of `atomic read` for different elements of the common symbol #80399

Open yus3710-fj opened 7 months ago

yus3710-fj commented 7 months ago

This is an issue from Fujitsu testsuite.

Flang-new terminates abnormally when compiling atomic read for different elements of the common symbol such as arrays and derived types.

The following are the test program and the compilation results of Flang-new and gfortran.

! test.f90
integer :: x, vv(2), xx(2)
type t1
  integer :: v,y,yy(2)
end type t1
type(t1)::t,tt(2)
x=1
xx=1
vv=1
t%y=1
t%yy=1
tt(1)%y=1
tt(1)%yy=1
tt(2)%v=1
tt(2)%y=1
tt(2)%yy=1

!$omp atomic read
  vv(1) = vv(2)
!$omp atomic read
  t%v = t%y
!$omp atomic read
  t%v = t%yy(1)
!$omp atomic read
  tt(1)%v = tt(1)%y
!$omp atomic read
  tt(1)%v = tt(2)%v
!$omp atomic read
  tt(1)%v = tt(1)%yy(1)
!$omp atomic read
  t%yy(2) = t%y
!$omp atomic read
  t%yy(2) = t%yy(1)
!$omp atomic read
  tt(1)%yy(2) = tt(1)%y
!$omp atomic read
  tt(1)%yy(2) = tt(1)%yy(1)
!$omp atomic read
  tt(1)%yy(2) = tt(2)%yy(2)

print *,'pass'
end
$ flang-new -v test.f90 -fopenmp
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 7c3ee7cbe6419ea5e37ce2723cc1a1688380581f)
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
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/test-f79d60.o -x f95-cpp-input test.f90
error: Semantic errors in test.f90
./test.f90:19:11: error: RHS expression on atomic assignment statement cannot access 'vv(1)'
    vv(1) = vv(2)
            ^^^^^
./test.f90:21:9: error: RHS expression on atomic assignment statement cannot access 't%v'
    t%v = t%y
          ^^^
./test.f90:23:9: error: RHS expression on atomic assignment statement cannot access 't%v'
    t%v = t%yy(1)
          ^^^^^^^
./test.f90:25:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v'
    tt(1)%v = tt(1)%y
              ^^^^^^^
./test.f90:27:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v'
    tt(1)%v = tt(2)%v
              ^^^^^^^
./test.f90:29:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v'
    tt(1)%v = tt(1)%yy(1)
              ^^^^^^^^^^^
./test.f90:31:13: error: RHS expression on atomic assignment statement cannot access 't%yy(2)'
    t%yy(2) = t%y
              ^^^
./test.f90:33:13: error: RHS expression on atomic assignment statement cannot access 't%yy(2)'
    t%yy(2) = t%yy(1)
              ^^^^^^^
./test.f90:35:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)'
    tt(1)%yy(2) = tt(1)%y
                  ^^^^^^^
./test.f90:37:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)'
    tt(1)%yy(2) = tt(1)%yy(1)
                  ^^^^^^^^^^^
./test.f90:39:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)'
    tt(1)%yy(2) = tt(2)%yy(2)
                  ^^^^^^^^^^^
$ gfortran -v test.f90 -fopenmp
Driving: gfortran -v test.f90 -fopenmp -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC) 
 :
$
llvmbot commented 7 months ago

@llvm/issue-subscribers-flang-frontend

Author: Yusuke MINATO (yus3710-fj)

This is an issue from Fujitsu testsuite. Flang-new terminates abnormally when compiling `atomic read` for different elements of the common symbol such as arrays and derived types. The following are the test program and the compilation results of Flang-new and gfortran. ```fortran ! test.f90 integer :: x, vv(2), xx(2) type t1 integer :: v,y,yy(2) end type t1 type(t1)::t,tt(2) x=1 xx=1 vv=1 t%y=1 t%yy=1 tt(1)%y=1 tt(1)%yy=1 tt(2)%v=1 tt(2)%y=1 tt(2)%yy=1 !$omp atomic read vv(1) = vv(2) !$omp atomic read t%v = t%y !$omp atomic read t%v = t%yy(1) !$omp atomic read tt(1)%v = tt(1)%y !$omp atomic read tt(1)%v = tt(2)%v !$omp atomic read tt(1)%v = tt(1)%yy(1) !$omp atomic read t%yy(2) = t%y !$omp atomic read t%yy(2) = t%yy(1) !$omp atomic read tt(1)%yy(2) = tt(1)%y !$omp atomic read tt(1)%yy(2) = tt(1)%yy(1) !$omp atomic read tt(1)%yy(2) = tt(2)%yy(2) print *,'pass' end ``` ```console $ flang-new -v test.f90 -fopenmp flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 7c3ee7cbe6419ea5e37ce2723cc1a1688380581f) 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 Candidate multilib: .;@m64 Selected multilib: .;@m64 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/test-f79d60.o -x f95-cpp-input test.f90 error: Semantic errors in test.f90 ./test.f90:19:11: error: RHS expression on atomic assignment statement cannot access 'vv(1)' vv(1) = vv(2) ^^^^^ ./test.f90:21:9: error: RHS expression on atomic assignment statement cannot access 't%v' t%v = t%y ^^^ ./test.f90:23:9: error: RHS expression on atomic assignment statement cannot access 't%v' t%v = t%yy(1) ^^^^^^^ ./test.f90:25:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v' tt(1)%v = tt(1)%y ^^^^^^^ ./test.f90:27:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v' tt(1)%v = tt(2)%v ^^^^^^^ ./test.f90:29:13: error: RHS expression on atomic assignment statement cannot access 'tt(1)%v' tt(1)%v = tt(1)%yy(1) ^^^^^^^^^^^ ./test.f90:31:13: error: RHS expression on atomic assignment statement cannot access 't%yy(2)' t%yy(2) = t%y ^^^ ./test.f90:33:13: error: RHS expression on atomic assignment statement cannot access 't%yy(2)' t%yy(2) = t%yy(1) ^^^^^^^ ./test.f90:35:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)' tt(1)%yy(2) = tt(1)%y ^^^^^^^ ./test.f90:37:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)' tt(1)%yy(2) = tt(1)%yy(1) ^^^^^^^^^^^ ./test.f90:39:17: error: RHS expression on atomic assignment statement cannot access 'tt(1)%yy(2)' tt(1)%yy(2) = tt(2)%yy(2) ^^^^^^^^^^^ ``` ```console $ gfortran -v test.f90 -fopenmp Driving: gfortran -v test.f90 -fopenmp -l gfortran -l m -shared-libgcc Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper Target: aarch64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC) : $ ```
Thirumalai-Shaktivel commented 2 months ago

@chandankds has a fix, will submit a PR soon.