<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138810>138810</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Incorrect execution result when reshape intrinsic function is specified as the argument of function
</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 : 21.0.0(842e5915778a820c63cf38b75bec932a6ea8c18b)/AArch64
```
When `reshape intrinsic function` is specified as the argument of `function (ch and s)`, the function result is incorrect.
The above program is Polymorphism_22.f90.
Once the result of `reshape intrinsic function` is assigned to a variable, and that variable is specified as an argument to `function (ch and s)`, the execution result is correct.
- Before modification
```
call s(ch(reshape([2,3,5,6],[2,2])))
```
- After modification
```
integer::res(2,2)
res=reshape([2,3,5,6],[2,2])
call s(ch(res))
```
The above program is Polymorphism_4.f90.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
Polymorphism_22.f90:
```fortran
program main
interface
subroutine s(unlim)
class(*) :: unlim(:,:)
end subroutine s
function ch(dum)
integer,pointer :: ch(:,:)
integer,target :: dum(:,:)
end function ch
end interface
call s(ch(reshape([2,3,5,6],[2,2])))
end program main
subroutine s(unlim)
interface
function fun(dmy)
integer :: fun
class(*):: dmy(2,2)
end function fun
end interface
class(*) :: unlim(:,:)
integer :: stat = 0
stat = fun(unlim)
if(stat/=1) then
print*,101
else
print*,'PASS'
endif
end subroutine s
function fun(dmy)
integer :: fun
class(*):: dmy(2,2)
if(sizeof(dmy) /= (4*4)) print*,'201'
fun=0
select type(dmy)
type is(complex)
print*,'202'
type is(integer)
! if(dmy(2,1)/=3) print*,203
print*, "dmy = ", dmy
fun=1
end select
end function fun
function ch(dum)
integer,pointer :: ch(:,:)
integer,target :: dum(:,:)
ch=>dum
end function ch
```
```
$ flang Polymorphism_22.f90; ./a.out
dmy = -1431332800 10 -418684532 -878184479
PASS
$
```
```
$ gfortran Polymorphism_22.f90; ./a.out
dmy = 2 3 5 6
PASS
$
```
```
$ ifx Polymorphism_22.f90; ./a.out
dmy = 2 3 5 6
PASS
$
```
Polymorphism_4.f90:
```fortran
program main
interface
subroutine s(unlim)
class(*) :: unlim(:,:)
end subroutine s
function ch(dum)
integer,pointer :: ch(:,:)
integer,target :: dum(:,:)
end function ch
end interface
integer::res(2,2)
res=reshape([2,3,5,6],[2,2])
call s(ch(res))
end program main
subroutine s(unlim)
interface
function fun(dmy)
integer :: fun
class(*):: dmy(2,2)
end function fun
end interface
class(*) :: unlim(:,:)
integer :: stat = 0
stat = fun(unlim)
if(stat/=1) then
print*,101
else
print*,'PASS'
endif
end subroutine s
function fun(dmy)
integer :: fun
class(*):: dmy(2,2)
if(sizeof(dmy) /= (4*4)) print*,'201'
fun=0
select type(dmy)
type is(complex)
print*,'202'
type is(integer)
! if(dmy(2,1)/=3) print*,203
print*, "dmy = ", dmy
fun=1
end select
end function fun
function ch(dum)
integer,pointer :: ch(:,:)
integer,target :: dum(:,:)
ch=>dum
end function ch
```
```
$ flang Polymorphism_4.f90; ./a.out
dmy = 2 3 5 6
PASS
$
```
```
$ gfortran Polymorphism_4.f90; ./a.out
dmy = 2 3 5 6
PASS
$
```
```
$ ifx Polymorphism_4.f90; ./a.out
dmy = 2 3 5 6
PASS
$
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWN1u4zYTfRr6ZmCDGkqyfOELxf78oVddYIv2sqBpyuJCEg2Sym769AUpyT9KnESLTbtADSPRDzlzzpkRj0xurTo2Uq5J8kCS7Yy3rtRmrctGz4svs70-PK1JSvsvzX-XxirdgC6gqHhzBMJywGhBF5RglsUok1WULJcZz5CKlImCZftlspdixZCnkmciyvYEVwR3eW5EmcaE5tcZCM3_KGUDJKVG2pKfJKjGGdVYJaBoG-GUbkhKQVmwJylUoeQBuAVXSuDm2NaycR4fSekwHAhmogTeHMD63CkluAkTziOMt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