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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Incorrect execution result when using actual and dummy arguments with different lengths
        </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 : 22.0.0(9e5f9ff82f2f060aac73a965ab37fdbb6b53cfe0)/AArch64
```

The attached program (`test01.f90`) has incorrect results.
In this program, the character length of `actual argument (ptr) `is 4 and the character length of `dummy argument (ch)` is 2.

According to `Fortran standard 2023 15.5.2.5 Ordinary dummy variables`:
```
The dummy argument becomes associated with the leftmost len characters of the actual argument.
```
This results in the following operation.
- `dummy argument ch(1)` is associated with `first two characters ("pa")` of `actual argument (pass)`
- `dummy argument ch(2)` is also associated with `first two characters ("pa")` of `actual argument (pass)`

So the expected result value should be `"papa"`.

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

test01.f90:
```fortran
program main
 character(len=4),pointer,contiguous :: ptr(:)
  character(len=4),target :: ch(2) = "pass"
  integer, parameter :: n=2
  ptr=>ch
  write(6,*) "main : ptr = ", ptr
  call sub(ptr, n)
contains
  subroutine sub(ch, m)
 character(len=m),pointer  :: ch(:)
    write(6,*) "sub  : ch  = ", ch
 end subroutine sub
end program main
```

```
$ flang test01.f90; ./a.out
 main : ptr = passpass
 sub  : ch  = passpass
$
```

```
$ gfortran test01.f90; ./a.out
 main : ptr = passpass
 sub  : ch  = papa
$
```

```
$ ifx test01.f90; ./a.out
 main : ptr = passpass
 sub : ch  = papa
$
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vs1u4zYQfhr6MohAjyxZPvigTepiTz206H1EkRIXFCmQVLL79gUpeeM4m8UCbYEAMSXO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