<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71368>71368</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Incorrect execution result of subarray operation passed to subroutine
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang-new : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4)
```
The result of subarray operation passed to `subroutine` is incorrect.
When I specify `-flang-experimental-hlfir` at the compilation, I can avoid the execution error.
The following are the test program, Flang-new, Gfortran and ifort compilation result.
target_tp01_3.f90:
```fortran
module m
contains
subroutine sub(a_arg,b_arg,c_arg)
integer, dimension(:),target:: a_arg
integer, dimension(:),target:: b_arg,c_arg
a_arg = b_arg + c_arg
end subroutine sub
end module m
program main
use m
integer,dimension(50)::x
integer,pointer :: a_pointer(:)
allocate (a_pointer(4))
a_pointer = (/100000,2,300000,40/)
call sub (a_pointer(2:3),a_pointer(1:2),a_pointer(3:4))
write(6,*) "a_pointer(3) = ", a_pointer(3)
x(a_pointer(3))=1
print *,'pass'
end program main
```
```
$ flang-new target_tp01_3.f90; ./a.out
a_pointer(3) = 400040
Segmentation fault (core dumped)
$
```
```
$ flang-new target_tp01_3.f90 -flang-experimental-hlfir; ./a.out
a_pointer(3) = 42
pass
$
```
```
$ gfortran target_tp01_3.f90; ./a.out
a_pointer(3) = 42
pass
$
```
```
$ ifort target_tp01_3.f90; ./a.out
a_pointer(3) = 42
pass
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk2P4ygQ_TXkUoqFyx-xDzmkE2XV513tHlvYLjuMCFiAp7v__QrsfM6sNJodjdUypqh69erRFBHOyUETbVnxworDSkz-ZOzWnLRZ919Wjek-t6zkyx8_ML77m6yTRoPpoVdCD2tN78C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