<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104464>104464</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Lowering fails with -O3 inside where clause
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lukasm91
</td>
</tr>
</table>
<pre>
Consider this code (simplified from a large code):
```
module m1
implicit none
type a
integer :: b
real, dimension(0:234) :: c
end type
type(a), allocatable, dimension(:) :: h
end module
module m2
use m1
implicit none
contains
subroutine m(d,e,f,g)
implicit none
real, intent(in) :: d(:)
real, intent(inout), dimension(:,:) :: e
real, intent(inout), dimension(:) :: f
real, intent(inout), dimension(:) :: g
where ( f(:) <= 1.)
g(:) = h(1)%c(0) + matmul(e(:,:),h(1)%c(1:h(1)%b))
endwhere
end subroutine
end module
```
Compiling with -O0 works perfectly fine, with -O3 I get
error: loc("/app/example.f90":27:7): null operand found
error: Lowering to LLVM IR failed
error: loc("/app/example.f90":1:1): LLVM Translation failed for operation: fir.global
error: failed to create the LLVM module
See https://fortran.godbolt.org/z/8Wfxn1dsa
Workaround is to split the assignment into two lines, i.e.
g(:) = h(1)%c(0)
g(:) = g(:) + matmul(e(:,:),h(1)%c(1:h(1)%b))
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU1v4zYQ_TX0ZRBDGlqJdNDBa0PAAikKtEX3TIkjiQ1FCiS12fTXF6Tl9UfaYNE2iCVwPPPezPMjKbxXgyGqWfGJFceNWMJoXa2XF-GnKt-0Vr7VB2u8kuQgjMpDZyUBw9KradaqVyShd3YCAVq4gdL3DCvG9yw7suz8fMzW_7ScrFw0wZSflpCwOhXAWEPXdQDhbSYQ5xWAMoEGcnDzF9n4HtpLmiOhGR5AqomMV9YwLDPG98h3DKtzQXcuICMT03tuhqWI8-ABhNa2E0G0mu6hIx5WN82M11gR_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