<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68856>68856</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang][OpenMP] Execution error of a WRITE statement with an unopened unit in a parallel region
</td>
</tr>
<tr>
<th>Labels</th>
<td>
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.
The execution of a program compiled by flang-new terminates with a fatal error.
In the program, there is a `WRITE` statement in a parallel region and the unit specified in that is not opened explicitly.
The execution terminates normally when OpenMP is disabled.
The following are the test program, Flang-new and gfortran execution result.
```fortran
! test.f90
!$omp parallel
write(1,*) 'OK'
!$omp end parallel
end
```
```console
$ flang-new -v test.f90 -fopenmp
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git dae91f5dbc5bee579eac7f4cbb71e86f2934817f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0
Selected GCC installation: /path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0
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 +neon -target-feature +v8a -o /tmp/test-f33630.o -x f95-cpp-input test.f90
"/usr/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 /path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0/crtbeginS.o -L/path/to/install/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0 -L/path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-f33630.o -L/path/to/install/lib -lFortran_main -lFortranRuntime -lFortranDecimal -lm -lomp -L/path/to/install/lib -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /path/to/gcc/11.2.0/lib/gcc/aarch64-unknown-linux-gnu/11.2.0/crtendS.o /lib/../lib64/crtn.o
$ ./a.out
$ OMP_NUM_THREADS=4 ./a.out
fatal Fortran runtime error(/path/to/test.f90:2): Attempted output to read-only file
Aborted (core dumped)
$ flang-new test.f90
$ ./a.out
$ cat fort.1
OK
```
```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
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.4.1 20200928 (Red Hat 8.4.1-1) (GCC)
:
$ OMP_NUM_THREADS=4 ./a.out
$ cat fort.1
OK
OK
OK
OK
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V19z4ygS_zTkpQuVhPz3wQ-OHe9u7exla5Kte0whaMlkEOgAJc5--iuQbCeeJHdTN3VVKUc0TdP9o2l-zb1XjUFckek1mW6veB_21q1eel_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