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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation error of `atomic update` with `MAX` for variables of different types
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            openmp,
            flang
      </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 in `atomic update` with `MAX` for variables of different types.

Gfortran emits error messages even if OpenMP is disabled.

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

```fortran
! test.f90
program main
  call isub1()
end program main

subroutine isub1()
  integer*1  i1x, i1y
  integer*2  i2x, i2y
  integer*4  i4x, i4y, calc(6),res/4/
  integer*8  i8x, i8y
  real*4  r4x, r4y
  real*8  r8x, r8y

  data i1x,i2x,i4x,i8x,r4x,r8x/6*-2/
  data i1y,i2y,i4y,i8y,r4y,r8y/6*4/

  !$omp atomic update
  i4x   =  max(i4x  ,  i1y)
  !$omp end atomic
  calc(1) = i4x
  i4x = -2
  !$omp atomic update
  i4x   =  max(i4x  ,  i2y)
  !$omp end atomic
  calc(2) = i4x
  i4x = -2
  !$omp atomic update
  i4x   =  max(i4x  ,  i4y)
  !$omp end atomic
  calc(3) = i4x
  i4x = -2
  !$omp atomic update
  i4x   =  max(i4x  ,  i8y)
  !$omp end atomic
  calc(4) = i4x
  i4x = -2
  !$omp atomic update
  i4x   =  max(i4x  ,  r4y)
  !$omp end atomic
  calc(5) = i4x
  i4x = -2
  !$omp atomic update
  i4x   =  max(i4x  ,  r8y)
  !$omp end atomic
  calc(6) = i4x
end subroutine
```
```console
$ flang-new -v test.f90 -fopenmp
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 61ff9f8db8d18002767ea27f83a4bfb8ed47f255)
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-3ff5d4.o -x f95-cpp-input test.f90
error: loc("/path/to/test.f90":30:3): no atomic update operation with region argument as operand found inside atomic.update region
error: loc("/path/to/test.f90":30:3): LLVM Translation failed for operation: omp.atomic.update
error: failed to create the LLVM module
```
```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) 
 :
test.f90:33:15:

   i4x   =  max(i4x  ,  i8y)
               1
Error: !$OMP ATOMIC intrinsic arguments except one must not reference ‘i4x’ at (1)
test.f90:38:23:

   i4x   =  max(i4x  ,  r4y)
                       1
Error: ‘a2’ argument of ‘max’ intrinsic at (1) must be INTEGER(4)
test.f90:38:11:

   i4x   =  max(i4x  ,  r4y)
           1
Error: !$OMP ATOMIC assignment must have an operator or intrinsic on right hand side at (1)
test.f90:43:23:

   i4x   =  max(i4x  ,  r8y)
                       1
Error: ‘a2’ argument of ‘max’ intrinsic at (1) must be INTEGER(4)
test.f90:43:11:

   i4x   =  max(i4x  ,  r8y)
           1
Error: !$OMP ATOMIC assignment must have an operator or intrinsic on right hand side at (1)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWFuTmzoS_jWaly65QGAbP8yDY4-zpyrZpLKzl7eUgAYrERIriRn7_PotSeDLXHJ29pyc2qkpDOqLvq8luhtxa0WrEG_J_B2Zb2_44Pba3B4Hmy3ThDbfbkpdH2_v98KCsMAVCGsHhMboDnbDN-HsAA6ts4NwOCPJliTreN1Jrlqq8BEcmk4o7tACL5U2HZfyCI97VFDprhdSqBaEArJIuNOdqGDoa-6QLBJ4FG7vBR_X__KPjTbwwI3gpUQLuoFaNA0aVA7csUd7heB9o40zXAF2wllAY7SBDq3lLVrAB1QgGvjUo_r42bOrhfV-6ysn93uERkupHz1KbhDcHgNl6I1uDe-AqzoMRjLcCa3AoB2kCxDPgfCK7QjqahKySOL_KBxHWRommjWrJI5MM3ZcjDoAFZcShB3KlLCCsFUcR1XDc-14tUNp9OCEwud2AEI5bNEQtk4BRHogbAMiPT4XMwDBopi9IM4BRB7F-dH_VFxWhBULPxfbGLSE7XLCds9NCwBRRNPi5Nkgl9GtiW5N_lRWAJhoZya7SaPmjo9sIuiILU4THQbT3YKwNWUXsEbLY7AM10DHI_OW4ervg-WZz2ROWEpYrrservf2RDo_AADJtgAdPxBWhAFPIc65eu7HL230dbEFfGRTwlbBled24d8PUfYHAGJvBMR-NqD8jYCynw2oeCOg_CcDMm-N0PxnA3prhBbPAHnVcwp7kkCfPFZaWS0nJZZDc0rG9OGUXIE2ukfV9VHvrPOAxvpsnq5mySxph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