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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compile error when derived-type array is defined using derived type and reshape intrinsic function in where construct
        </td>
    </tr>

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

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

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

<pre>
    ```
Version of flang : 21.0.0(8c7c791284877e36f73c41ffa56b52c13e613993)/AArch64
```

As in the attached program, when `derived-type array (str)` is defined using `derived type (ty1)` and `reshape intrinsic function` in `where construct`, a compilation error occurs.  
When the compilation option (-flang-deprecated-no-hlfir) is specified, the following message is outputted:  
  `not yet implemented: allocatable components in derived type assignment`  
The above program is `snfmm509_21.f90`.

When `reshape intrinsic function` is not used, the compilation succeeds.  
The above program is `snfmm509_22.f90`.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

snfmm509_21.f90:
```fortran
program main
  call test06()
 print *,'pass'
end program main

subroutine test06()
  type ty1
 integer ,allocatable :: a(:,:,:)
  end type ty1
  type(ty1) :: str(1)
 integer ,allocatable :: b(:,:,:)
  allocate(str(1)%a(1,1,1),b(1,1,1))
 b=1
  write(6,*) "b                                 = ", b
  write(6,*) "reshape((/(b,jj=1,1)/),(/1,1,1/)) = ", reshape((/(b,jj=1,1)/),(/1,1,1/))
! where ((/.true./)) str=(/(ty1(b ),ii=1,1)/)  ! compilation normal termination
  where ((/.true./)) str=(/(ty1(reshape((/(b,jj=1,1)/),(/1,1,1/))),ii=1,1)/)  ! compilation error
end subroutine test06
```

```
$ flang snfmm509_21.f90 -flang-deprecated-no-hlfir
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/Metro/fe2_05/snfmm509_21.f90":17:3): /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Lower/ConvertExpr.cpp:1012: not yet implemented: allocatable components in derived type assignment
LLVM ERROR: aborting
```

```
$ flang snfmm509_21.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/Metro/fe2_05/snfmm509_21.f90":17:3): failed to legalize operation 'hlfir.exactly_once'
error: failure in HLFIR bufferization pass
error: Lowering to LLVM IR failed
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/Metro/fe2_05/snfmm509_21.f90":1:1): cannot be converted to LLVM IR: missing `LLVMTranslationDialectInterface` registration for dialect for op: func.func
error: failed to create the LLVM module
$
```

```
$ gfortran snfmm509_21.f90; ./a.out
 b =            1
 reshape((/(b,jj=1,1)/),(/1,1,1/)) = 1
 pass
$
```

```
$ ifx snfmm509_21.f90; ./a.out
 b =            1
 reshape((/(b,jj=1,1)/),(/1,1,1/)) = 1
 pass
$
```

snfmm509_22.f90:
```fortran
program main
  call test06()
  print *,'pass'
end program main

subroutine test06()
  type ty1
     integer ,allocatable :: a(:,:,:)
  end type ty1
  type(ty1) :: str(1)
  integer ,allocatable :: b(:,:,:)
 allocate(str(1)%a(1,1,1),b(1,1,1))
  b=1
  write(6,*) "b = ", b
  write(6,*) "reshape((/(b,jj=1,1)/),(/1,1,1/)) = ", reshape((/(b,jj=1,1)/),(/1,1,1/))
  where ((/.true./)) str=(/(ty1(b ),ii=1,1)/)  ! compilation normal termination
! where ((/.true./)) str=(/(ty1(reshape((/(b,jj=1,1)/),(/1,1,1/))),ii=1,1)/)  ! compilation error
end subroutine test06
```

```
$ flang snfmm509_22.f90; ./a.out
 b                                 =  1
 reshape((/(b,jj=1,1)/),(/1,1,1/)) =  1
 pass
$
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWN9v2zYQ_mvoFyKCdLIs-cEPqlNtHVIMCIL2saCok81MIgWSyo_-9cNRcuIkaxOk2dYasWPZp7uP3x3vPlM4p3YaccOydyw7XYjR743dmL02J-3lojbN7Yat4vkvLj-hdcpoblredkLvOEtLDkkURzGDopC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