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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Execution error (Segmentation fault) when an array with allocatable attribute of derived types is specified in lastprivate clause in sections 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(dd7386d85f11cf6ad911b9827c7018fb08c6c205)/AArch64
```

When an array with `allocatable` attribute of `derived types` is specified in `lastprivate` clause in `sections` construct, the execution terminates abnormally (Segmentation fault).

Execution ends normally in the following cases:
- Remove `lastprivate` clause, or
- Do not specify the compilation option (`-fopenmp`)

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

omp3_alc_022_.f90:
```fortran
program main
  type test
     integer::x,y
  end type test
 type(test),dimension(:),allocatable::a
  type(test),dimension(5)::b
 integer,dimension(5)::c,d
  integer::n=5
  allocate(a(n))
 a=test(5,10)
  b=test(5,10)
!$omp parallel
!$omp sections lastprivate(a,b)
!$omp section
  do i=1,n
     a(i)=test(i,n)
 b(i)=test(i,n)
     if (a(i)%x.eq.b(i)%x.and.a(i)%y.eq.b(i)%y) then
 c(i)=0
     else
        c(i)=1
     end if
  end do
!$omp section
  do i=1,n
     a(i)=test(15,20)
 b(i)=test(15,20)
     if (a(i)%x.eq.b(i)%x.and.a(i)%y.eq.b(i)%y) then
 d(i)=0
     else
        d(i)=1
     end if
  end do
!$omp end sections
!$omp end parallel
  err=0
  do i=1,n
 if (c(i).eq.1.or.d(i).eq.1) err = err +1
  end do
  if (err .eq. 0) then
     print *,"OK"
  else
     print *,"NG"
 endif
end program main
```

```
$ flang-new -fopenmp omp3_alc_022_.f90; ./a.out
Segmentation fault (core dumped)
$
```

```
$ gfortran -fopenmp omp3_alc_022_.f90; ./a.out
 OK
$
```

```
$ ifort -qopenmp -diag-disable=10448 omp3_alc_022_.f90; ./a.out
 OK
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VsGO2zYQ_Rr6MrBAUbIsHXzYtescgjZFW7THgBJHNgOKVEhqd_33BWnJK6-9aRukQbACh48zbx7HnOHOyYNG3JDVI1ntFnzwR2M35qjNsv2yqI04bUhBx_90R-jDn2idNBpMC63i-rDU-Awke4C0SmhCCSuFWGdlIcpVm6ZNW3BRpWldlWzdrGlatjUtm6JhdEVYRdj-4cE2xyI_O38T6_z3ryNq4Bq4tfwEz9IfgRSUK2Ua7nmtkBQUuPdW1oPHQIwUVKCVTyjAn3p0ASAduB4b2UoUIHXAKO58b-UT99FFo_jgcNxz2HhpdDzaGO28HRpP2Bb8EQFfsBnCNni0ndTcowNea2M7rtQJCCt_x0OH2vOIavmgPGFVMk_rp4sT1MLB5bDUMUZrlDLPUh-g4Q4dycZjS_gNO_OE7yYQSBo7gXcGtPFj6qfouTFdL9WZmenjh7CSFHTZmh511wf9WTXn-scVIW4xOvLoPPTWHCzvQtT9VA9h8aE11ttwbVqADIt5YML2ryJadIPyV-KYrs8-c9V8pox9TtqKXvK_lMjo_2wdWUDH5WiBePWR42QAAKk9HtAGb9nDC2Hb07SJWtycCGvCymgJxboVskPtIv8y-IjGeSVGv3zO4N3zsf4jvh7xE7n3cE3YmXxfZaJJtltNOyOfEJkTVuoYerxO4CTbnfkEx9v09aYB6nf3CEsJy03XQ88tVwrVW_v0e4F5TUYC2_qOmxE-RRYGJMl2KWFbPbutQF_G9CdeMiIulOt_AsQ7b2GUIkLZ6iXBr0k9X3Mtkhng9AZwIqwKFT9xa17D0lkgVA5nS4A5MJ0D409iXnnC_CiF0nB1jH5LoxvI_6OS-Lcqie9XKVgvT_WdvetyBUBr53TuqHrWYbq4kGKaGJuIuSEkitYCyXbnL3tM7_GcVA2YcBDoG4n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