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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Execution error when an array that is allocated outside parallel construct is deallocated inside section construct with lastprivate clause in parallel construct
        </td>
    </tr>

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

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

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

<pre>
    ```
Version of flang-new : 19.0.0(dcebe297367f48a71a5ecea3bcdd54671195da1b)/AArch64
```

A run-time error occurs when an array that is allocated outside `parallel` construct is deallocated inside `section` construct with `lastprivate` clause in `parallel` construct.  
When `lastprivate` clause is removed, execution succeeds.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

FT_OMP_Intrinsic_01_.f90:
```fortran
subroutine s4
 complex, allocatable::v(:)
  allocate(v(2))
!$omp parallel
!$omp sections lastprivate(v)
!$omp section
  deallocate(v)
 allocate(v(3))
!$omp end sections
!$omp end parallel
end subroutine s4

program main
  call s4
  print *,'PASS'
end program main
```

```
$ flang-new -fopenmp FT_OMP_Intrinsic_01_.f90; ./a.out

fatal Fortran runtime error(/work/home/ohno/CT/test/fort/tp/reproducerJ/Metro/HCL_2019_636_647_01/FT_OMP_Intrinsic_01_.f90:2): Assign: mismatching element counts in array assignment (to 2, from 3)
Aborted (core dumped)
$
```

```
$ gfortran -fopenmp FT_OMP_Intrinsic_01_.f90; ./a.out
 PASS
$
```

```
$ ifort -qopenmp -diag-disable=10448 FT_OMP_Intrinsic_01_.f90; ./a.out
 PASS
$
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vd9v4zYM_muUFyKBTNtx_JAHXzPvB3a4Aldsj4EsM7FusuRJcnv33w9y3CRN29twwIDAsSSapMjv-yi8V0dDtGX5B5bvFmIMn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