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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Execution error of WRITE statements with a format that uses a repeat specification
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:ir
      </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.

The execution of a program compiled by flang-new terminates with a fatal error.

In the program, there is a `PRINT` statement with Implied DO. The format of it has a repeat specification. If parentheses are used with the repeat specification, the error occurs. The error doesn't occur without parentheses.

The following are the test program, Flang-new and gfortran execution result.

```fortran
! test.f90
REAL ANSTBL(50,3)
PRINT '((I2,3(D25.16)))', ( J,ANSTBL(J,1),ANSTBL(J,2),ANSTBL(J,3), J=1, 50 )
!PRINT '((I2,3D25.16))', ( J,ANSTBL(J,1),ANSTBL(J,2),ANSTBL(J,3), J=1, 50 )
END
```
```console
$ flang-new -v test.f90 
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git 4ac304242b65413f4eae21af300dd14cb14ed066)
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 -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-322b1c.o -x f95-cpp-input test.f90
 "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../bin/ld" -pie -EL --hash-style=gnu --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /lib/../lib64/Scrt1.o /lib/../lib64/crti.o /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtbeginS.o -L/path/to/install/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-322b1c.o -L/path/to/install/lib -lFortran_main -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtendS.o /lib/../lib64/crtn.o
$ ./a.out 

fatal Fortran runtime error(/path/to/test.f90:2): Data edit descriptor 'D' may not be used with an INTEGER data item
 1   0.0000000000000000D+00   0.0000000000000000D+00 0.0000000000000000D+00
 2   0.0000000000000000D+00 0.0000000000000000D+00   0.0000000000000000D+00
Aborted (core dumped)
```
```console
$ gfortran -v test.f90 
Driving: gfortran -v test.f90 -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=https://bugs.rockylinux.org/ --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)
 :
$ ./a.out 
 1 0.0000000000000000D+00  -0.1438849039914203D-10   0.0000000000000000D+00
 2   0.0000000000000000D+00   0.9183409485952689D-40 0.0000000000000000D+00
 3   0.0000000000000000D+00 0.5508640000000000D+06   0.0000000000000000D+00
 :
48 0.0000000000000000D+00   0.0000000000000000D+00 0.0000000000000000D+00
49   0.0000000000000000D+00 0.0000000000000000D+00   0.5508640000000000D+06
50 0.0000000000000000D+00   0.0000000000000000D+00 -0.2251764322355860D-34
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WF1v2zrS_jXMzYCCREm2fJELx4rPm4Ogp0jz4lwGFDWS2VKklqTysb9-QcmfaeyeLdotDDWaGQ5nHo6GD8mdk61GvCb5DcnLKz74jbHXb4NL50lMm69Xlanfrh830oF0wDVI5waExpoO1sNX6d0AHp13g_QYkbgk8XJ6Pm4Q8BXF4KXRYBrg0FvTWt6BMF0vFdZQvUGjuG6pxhfwaDupuUcHL9JvgEPDPVeA1hp74vpOg9_gzh1hq_BqcYwQyCz-_HD36ZHMYnCee-xQ-8njXdcriTWUf0UQwmuM7bgPsUkPGx5GW-yRe3A9CtlIwUPwEdw10HOL2m_QoQNuEQaH9eQ1hPLRsG1cU_xghBism-adJLVBpwmb-0k3OjODP57pO0Abo5R5kbodYwjeA_jHSKz3eHJdQ9sY6y3XRyth0Q3Kn3gms3j6ba23UpaM3qNmEU-Sh9vlPSw_fXm8uSesyGPCVilhi0k5gg6EzQkrCCvu2KQtSpZHySyYbX_zECZhBfxJ2GrvLbwko_5Uxj6QpZMM_iRpmYQ_8hj2cRCWfBjKaRy_OYjbT-U7aN-9CqOdUbgLOTv6DujzHnaY9AfdM1oXFjEpojgK8xUb73tH0iVha8LWrfSboYqE6QhbK_W8-4_21nxF4aNWesi4SOOMZaya5VmSNhlyZAlv0jiu6yQTVZJhHc9m-2weuW3Rk3QJnFuxmWV00N-0edFUST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