Issue 154043
Summary [Flang] Incorrect execution result when using actual and dummy arguments with different lengths
Labels flang
Assignees
Reporter ohno-fj
    ```
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
$
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to