<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/80399>80399</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation error of `atomic read` for different elements of the common symbol
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:openmp
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yus3710-fj
      </td>
    </tr>
</table>

<pre>
    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) 
 :
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWFtz2zoO_jX0C4YeifL1wQ-JXZ-zM91pp83OPmYoCpKZUqSWpBz7_PodUpZvJ5cm7bbbcR0TBEB8EAgB4M7JSiMuyPiWjFcD3vqNsYt967JpmtDyYZCbYr-420gH0gHXIJ1rEUprali3D9K7Fjw671rpcUiSFUluuu-14rqiGh_Bo62l5h4d8FwbW3Ol9vC4QQ3C1I1UUldAJgn3ppYCLPKCTBIojYVCliVa1B5QYY3aOzAl-A0GydpocPs6NwpcKzbAHXBr-T7YWUCBVm6xAL9v0F1YdrdBKI1S5jEczC1GhQEFNNZUltdRweGURirupdFg0bWqM-CELTBWpbHecn1xCJkk3eeweaCyNB40LOdJR5HaY4UWSHZDshvYEbaE7ZawGSNsHha7Xb-I_AEO-LRbAFyJbwlb7sP__YUQ6s4PR8GwIGzm08ASRT1hS-8vpHYkWx34d2e_t9vTb0_YeH-1PF8HhfGMS7Zz8jW9wz3ePk1-hvtcy9HThI1M3cB5WB28Fh0cDACSrc7c_bpkQLiNUh30N0vse-jfIXnmpoOGC3--W8PRxa9qeMWEt4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