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

    <tr>
        <th>Summary</th>
        <td>
            Pointer and allocatable assignment problem
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          PeixinQiao
      </td>
    </tr>
</table>

<pre>
    ```
  integer, parameter :: n = 5
  integer :: x(n), y(n) = [1,2,3,4,5]
  integer, pointer :: w(:)
  integer, allocatable :: z(:)
  allocate(w(n))
  allocate(z(n))
  call test(x, y, w, z, n)
contains
  subroutine test(x, y, w, z, n)
    integer :: x(n), y(n)
    integer, pointer :: w(:)
    integer, allocatable :: z(:)
    x = y(1:4)
    w = y(1:4)
    z = y(1:4)
    print *, size(x), x
    print *, size(w), w
    print *, size(z), z
  end
end
```
```
$ cat run.sh 
#!/bin/bash

echo "---------- gfortran ----------"
gfortran $1 $2 && ./a.out

echo && echo "---------- ifort ----------"
ifort $1 $2 && ./a.out

echo && echo "---------- flang-new ----------"
flang-new -flang-experimental-exec $1 $2 && ./a.out
```
```
$ bash run.sh test.f90 
---------- gfortran ----------
           5           1           2           3           4           0
           5           1           2           3           4           0
           4           1           2           3           4

---------- ifort ----------
           5           1           2           3           4           0
           5           1           2           3           4           0
           4           1           2           3           4

---------- flang-new ----------
 5 1 2 3 4 5
 5 1 2 3 4 5
 4 1 2 3 4
```

This code will have one execution error when runtime check is enabled.
```
$ gfortran test.f90 -fcheck=bounds && ./a.out
At line 13 of file test.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'x' (5/4)
```
If the array is large, which is common in real HPC applications. For example, assign one array of 50,000 elements to an array of 100,000 elements. LLVM Flang would not be efficient as gfortran and ifort.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVluPqzYQ_jXwMloEBufywEP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